sbaudoin / sonar-ansible

SonarQube plugin to analyze Ansible playbooks
Apache License 2.0
71 stars 17 forks source link

Multiple 'false-positive' reports for issue #44

Closed tannerli closed 3 years ago

tannerli commented 3 years ago

We are running sonar-ansible 2.5.0 and ansible-lint 5.2.0 using ansible 2.10.15.

There seems to be an issue with the reporting of certain issues, I've added an excerpt from a logfile of ours:

13:01:57.114 DEBUG: Analyzing file: main.yml
13:01:57.115 DEBUG: 'defaults/main.yml' generated metadata with charset 'UTF-8'
13:01:57.116 DEBUG: File file:///var/atlassian/bamboo02-agent-2-home/xml-data/build-dir/CLAAA-BRC1-JOB1/defaults/main.yml has syntax error? false
13:01:57.116 DEBUG: Count lines in main.yml
13:01:57.120 DEBUG: Checking rule: yaml:EmptyValuesCheck
13:01:57.133 DEBUG: Problems found: [69:1:too many blank lines (1 > 0) (empty-lines)]
13:01:57.133 DEBUG: Creating violation for 69:1:too many blank lines (1 > 0) (empty-lines)
13:01:57.133 DEBUG: Checking rule: yaml:IndentationCheck
13:01:57.142 DEBUG: Problems found: [69:1:too many blank lines (1 > 0) (empty-lines)]
13:01:57.142 DEBUG: Creating violation for 69:1:too many blank lines (1 > 0) (empty-lines)
13:01:57.142 DEBUG: Checking rule: yaml:CommasCheck
13:01:57.150 DEBUG: Problems found: [69:1:too many blank lines (1 > 0) (empty-lines)]
13:01:57.150 DEBUG: Creating violation for 69:1:too many blank lines (1 > 0) (empty-lines)
13:01:57.150 DEBUG: Checking rule: yaml:LineLengthCheck
13:01:57.159 DEBUG: Problems found: [69:1:too many blank lines (1 > 0) (empty-lines)]
13:01:57.159 DEBUG: Creating violation for 69:1:too many blank lines (1 > 0) (empty-lines)
13:01:57.159 DEBUG: Checking rule: yaml:KeyDuplicatesCheck
13:01:57.167 DEBUG: Problems found: [69:1:too many blank lines (1 > 0) (empty-lines)]
13:01:57.167 DEBUG: Creating violation for 69:1:too many blank lines (1 > 0) (empty-lines)
13:01:57.167 DEBUG: Checking rule: yaml:EmptyLinesCheck
13:01:57.176 DEBUG: Problems found: [69:1:too many blank lines (1 > 0) (empty-lines)]
13:01:57.176 DEBUG: Creating violation for 69:1:too many blank lines (1 > 0) (empty-lines)
13:01:57.176 DEBUG: Checking rule: yaml:TrailingSpacesCheck
13:01:57.184 DEBUG: Problems found: [69:1:too many blank lines (1 > 0) (empty-lines)]
13:01:57.184 DEBUG: Creating violation for 69:1:too many blank lines (1 > 0) (empty-lines)
13:01:57.184 DEBUG: Checking rule: yaml:ParsingErrorCheck
13:01:57.184 DEBUG: Checking rule: yaml:CommentsCheck
13:01:57.193 DEBUG: Problems found: [69:1:too many blank lines (1 > 0) (empty-lines)]
13:01:57.193 DEBUG: Creating violation for 69:1:too many blank lines (1 > 0) (empty-lines)
13:01:57.193 DEBUG: Checking rule: yaml:BracesCheck
13:01:57.201 DEBUG: Problems found: [69:1:too many blank lines (1 > 0) (empty-lines)]
13:01:57.201 DEBUG: Creating violation for 69:1:too many blank lines (1 > 0) (empty-lines)
13:01:57.201 DEBUG: Checking rule: yaml:HyphensCheck
13:01:57.210 DEBUG: Problems found: [69:1:too many blank lines (1 > 0) (empty-lines)]
13:01:57.210 DEBUG: Creating violation for 69:1:too many blank lines (1 > 0) (empty-lines)
13:01:57.210 DEBUG: Checking rule: yaml:DocumentStartCheck
13:01:57.218 DEBUG: Problems found: [69:1:too many blank lines (1 > 0) (empty-lines)]
13:01:57.218 DEBUG: Creating violation for 69:1:too many blank lines (1 > 0) (empty-lines)
13:01:57.219 DEBUG: Checking rule: yaml:NewLineAtEndOfFileCheck
13:01:57.227 DEBUG: Problems found: [69:1:too many blank lines (1 > 0) (empty-lines)]
13:01:57.227 DEBUG: Creating violation for 69:1:too many blank lines (1 > 0) (empty-lines)
13:01:57.227 DEBUG: Checking rule: yaml:OctalValuesCheck
13:01:57.235 DEBUG: Problems found: [69:1:too many blank lines (1 > 0) (empty-lines)]
13:01:57.235 DEBUG: Creating violation for 69:1:too many blank lines (1 > 0) (empty-lines)
13:01:57.235 DEBUG: Checking rule: yaml:ColonsCheck
13:01:57.244 DEBUG: Problems found: [69:1:too many blank lines (1 > 0) (empty-lines)]
13:01:57.244 DEBUG: Creating violation for 69:1:too many blank lines (1 > 0) (empty-lines)
13:01:57.244 DEBUG: Checking rule: yaml:TruthyCheck
13:01:57.244 DEBUG: Got RuleProperty null
13:01:57.244 DEBUG: Got RuleProperty @org.sonar.check.RuleProperty(description="Comma-separated list of truthy values which will be ignored during linting", type="", defaultValue="true, false", key="allowed-values")
13:01:57.244 DEBUG: Got RuleProperty @org.sonar.check.RuleProperty(description="Disable verification for keys in mappings. By default, truthy rule applies to both keys and values. Set this option to false to prevent this.", type="", defaultValue="true", key="check-keys")
13:01:57.244 DEBUG: YAMLLint config for rule yaml:TruthyCheck/truthy: '---
rules:
  truthy:
    allowed-values: ['true', 'false', 'yes', 'no']
    check-keys: true
'
13:01:57.247 DEBUG: Problems found: []
13:01:57.247 DEBUG: Checking rule: yaml:CommentsIndentationCheck
13:01:57.255 DEBUG: Problems found: [69:1:too many blank lines (1 > 0) (empty-lines)]
13:01:57.255 DEBUG: Creating violation for 69:1:too many blank lines (1 > 0) (empty-lines)
13:01:57.255 DEBUG: Checking rule: yaml:BracketsCheck
13:01:57.263 DEBUG: Problems found: [69:1:too many blank lines (1 > 0) (empty-lines)]
13:01:57.263 DEBUG: Creating violation for 69:1:too many blank lines (1 > 0) (empty-lines)
13:01:57.264 DEBUG: Checking rule: yaml:NewLinesCheck
13:01:57.272 DEBUG: Problems found: [69:1:too many blank lines (1 > 0) (empty-lines)]
13:01:57.272 DEBUG: Creating violation for 69:1:too many blank lines (1 > 0) (empty-lines)
13:01:57.272 DEBUG: Saving issue: too many blank lines (1 > 0) (empty-lines)
13:01:57.273 DEBUG: Saving issue: too many blank lines (1 > 0) (empty-lines)
13:01:57.273 DEBUG: Saving issue: too many blank lines (1 > 0) (empty-lines)
13:01:57.274 DEBUG: Saving issue: too many blank lines (1 > 0) (empty-lines)
13:01:57.274 DEBUG: Saving issue: too many blank lines (1 > 0) (empty-lines)
13:01:57.274 DEBUG: Saving issue: too many blank lines (1 > 0) (empty-lines)
13:01:57.274 DEBUG: Saving issue: too many blank lines (1 > 0) (empty-lines)
13:01:57.274 DEBUG: Saving issue: too many blank lines (1 > 0) (empty-lines)
13:01:57.274 DEBUG: Saving issue: too many blank lines (1 > 0) (empty-lines)
13:01:57.275 DEBUG: Saving issue: too many blank lines (1 > 0) (empty-lines)
13:01:57.275 DEBUG: Saving issue: too many blank lines (1 > 0) (empty-lines)
13:01:57.275 DEBUG: Saving issue: too many blank lines (1 > 0) (empty-lines)
13:01:57.275 DEBUG: Saving issue: too many blank lines (1 > 0) (empty-lines)
13:01:57.275 DEBUG: Saving issue: too many blank lines (1 > 0) (empty-lines)
13:01:57.275 DEBUG: Saving issue: too many blank lines (1 > 0) (empty-lines)
13:01:57.275 DEBUG: Saving issue: too many blank lines (1 > 0) (empty-lines)
13:01:57.276 DEBUG: Saving issue: too many blank lines (1 > 0) (empty-lines)

The result is, that the single line 69 is reported a whopping 17 times inside sonarqube. Each code smell is generated by one of the rules like HyphenCheck, BracktesCheck etc.

At first it looked like it might have to do something with #32, but the log looks to me like this is one single pass-through of main.yml

Any advice on how to fix this? If you could point me to the relevant place inside the code, I could maybe fix it myself and make a PR for you.

sbaudoin commented 3 years ago

Hello,

On first sight, no it does not relate to #32. I think I have found what's wrong but as such I'm surprised such an issue has not been raised so far. I'll try to figure this out.

sbaudoin commented 3 years ago

The issue seems different from the one I though of: I just cannot reproduce your problem. I first expected an issue coming from static caching or so, but this is not the case. It seems that the underlying YAML linter gets a configuration larger than the simple, dynamically-calculated one containing only the rule to be checked. I expect this case to happen only if there is a local YAML lint configuration fie. So can you tell me if this is the case? Do you have a .yamllint configuration file in your project?

sbaudoin commented 3 years ago

So yes, that's it. I'm going to release a fix. BTW, this is an issue of the YAML plugin so you will have to install the new YAML plugin, not the Ansible plugin.

sbaudoin commented 3 years ago

Version 1.6.1 released: can you test it, please?

tannerli commented 3 years ago

Sorry for getting back late to you on this, i was on vacation last week. I'm extremely glad you took an interest in this. I will install the updated version and give feedback

tannerli commented 3 years ago

Yes, the issue has been resolved with your fix. Thank you very much for the patch :+1: