Sonar exclusion behavior

Hi guys,

Today I’m facing an unexpected behavior on sonar.coverage.exclusions settings. When I save any exclusions, Sonar groups them in just one input, separated by comma, but does not exclude them in the analysis process.

Anyone having this problem too?

That’s weird but not technically an issue (I’ll flag it internally).

You set sonar.coverage.exclusions rather than sonar.exclusions (scroll down). These do different things (the former excluding from code coverage only, the latter excluding from analysis overall). Which are you trying to acheive?

Thanks for your explanation Colin. My intention is really to remove only the code coverage, so I believe I made the configuration in the right place.

An important point is that this problem started when I went to add a new exclusion configuration. Before everything was working and visually the exclusions were one below the other. When I added the new one and clicked on save it started to have the mentioned behavior.

Thanks for the update.

So far I can’t reproduce the issue (the collapsing of multi-line configuraiton into a comma seperate value, yes, but it still works).

Do you see the coverage exclusion indicated in the analysis logs? For example:

[INFO] Indexing files...
[INFO] Project configuration:
[INFO]   Excluded sources: **/build-wrapper-dump.json
[INFO]   Excluded sources for coverage: **/*.java,**/*

New grouping row in UI is incorrect.
Because it doesn’t add spaces after commas.
And if you have several excludes it will not work after grouping.
As quick fix you may add spaces in row after UI grouping.

2 Likes

Facing the same issue “,” separated values not working in coverage exclusions in sonarCloud, Andrii_Yefimov your quick fix is also not working of adding spaces

Can you help us with a specific example of the inputs on the SonarCloud side that result in a malformed/non-working exclusion? I’m having trouble reproducing it (I’m sure the issue is on my side and about my understanding if there are now multiple reports!)

Eg, our coverage exclusion is -

tests/**/*, tests/*, commands/*, config/test.php, codingstandard/**/*

When I added it one by one in UI they grouped as
tests/**/*,tests/*,commands/*,config/test.php,codingstandard/**/*
Then after new scan I see:

PS may be it important - we use sonarsource/sonarcloud-scan:2.0.0 for scan

Do you see the coverage exclusion indicated in the analysis logs?

Yes, the log showed the use of exclusions, but still, sonarcloud failed to test the “excluded” files.

The approach used here to work around this issue was to use .properties with the Sonar settings including these exclusions. Then it worked.

I think it’s a string length issue. Exclude works with 2-3 expression, but doesn’t work with many exclusions

I am getting the same issue on :

  • source file inclusions (sonar.inclusions)
  • Javascript global variables (sonar.javascript.globals)

Issue is not about the UX point about all of the same line, but well about the fact that result are incorrect. For example, before I update sonar inclusions I have in my reports :

INFO:   Included sources: scripts/**/*, modules/**/*, vendors/**/*
INFO:   Excluded sources: **/build-wrapper-dump.json, test/**/*
INFO:   Included tests: test/**/*
INFO: 1261 files indexed
INFO: 141 files ignored because of inclusion/exclusion patterns
INFO: 0 files ignored because of scm ignore settings

After just a save, and add spaces after coma as suggested, logs seems to be the same, but results are differents :

INFO:   Included sources: scripts/**/*, modules/**/*, vendors/**/*
INFO:   Excluded sources: **/build-wrapper-dump.json, test/**/*
INFO:   Included tests: test/**/*
INFO: 0 files indexed
INFO: 1254 files ignored because of inclusion/exclusion patterns
INFO: 0 files ignored because of scm ignore settings

Same for globals that I have added, they seems to be ignored and continue to be reported as issues…

I have a few code coverage exclusions setup and before adding a new exclusion, it used to work fine.
Today I added a new exclusion and noticed that on the web interface, the items are now being added as a comma delimited string (which sucks!)
It used to an exclusion per line.
Anyhow, after adding a new exclusion item, and running a sonar scan, none of the exclusions work anymore.

Thanks everyone for the reports. I’ve flagged this thread for attention.

I have same issue and wasted a day for trouble shooting.



Do inspection and you guys can understand of error. After “collapsing of multi-line configuration into a comma seperate value”. The configuration value was changed from an array of strings to a single string.

Any updates on the resolution of the issue? as there is no way to revert to the original form and this comma-separated string is also not working, this is affecting the quality gates and deployments as well.

After this morning’s update, it all should work as expected.

5 Likes

Now it’s working guys. Thanks a lot!

Hi @neeldip_barot and @thientd87,

Are you still seeing issues?

Regards,
Ismail

1 Like


Ismail.cherri same issue with Duplication Exclusions (#sonar.cpd.exclusions)
Could you check other section in the Analysis Scope page