I’m using SonarCloud with Azure DevOps on a predominantly C# codebase with supporting web files. I’m trying to exclude all XML files via the UI (Administration > General Settings > Analysis Scope > Source File Exclusions) using **/*.xml but in the Overview I’m seeing this:
I can see that there was an issue with exclusions set in the UI not being taken into account back in 2020 but that got fixed. Grateful for any pointers as to what I might be doing wrong. Thanks!
There’s a hierarchy to settings, with those set via the UI at the bottom.
Can you check your Administration → Background Tasks → [row dots menu] → Show SonarScanner Context to see what exclusions were actually in force for the analysis?
Thanks for checking that. Could you provide your full analysis log, please?
The analysis / scanner log is what’s output from the analysis command. Hopefully, the log you provide - redacted as necessary - will include that command as well.
Many thanks Ann! I have the debug log but it’s 63k lines long and thus difficult to redact and I’d rather not post it publicly. Would it be possible to send it to you privately please? I am of course happy for salient extracts to be posted here to help anyone in the future.
No problem! At a very broad level there are 20k of CSS files being reported in the overview which I’m not expecting to see based on the exclusion filter. The more granular exclusions do seem to be working.
This is fascinating. Does “working granular exclusions” include **/*publish.xml? Also, what about the **/*.sql exclusion? At this point I’m guessing it’s failing?
And finally, I’m well beyond my expertise at this point, so I’m going to flag this for more expert eyes.
Could it be that the not-excluded XML files are classified as part of a test project? In this case, the way to exclude them would be to set the test-specific property: sonar.test.exclusions.
Thanks for that thought @Julien_HENRY. We do have test projects but the files are predominantly C#.
I’ve been looking again at the SonarCloudAnalyze output generated by Azure DevOps (with sonar.verbose=true). I can see that the C# files I have looked at get 7 ‘mentions’ whilst the XML files I have checked only get 2 ‘mentions’. I can see that the C# files are getting indexed but the XML files are not. Is that the indication that the exclusions are working and the issue is with the final Lines of Code calculation?
Apologies @ganncamp - just realised that I hadn’t answered your questions. As far as I can tell, in the SonarCloudAnalyze output generated by Azure DevOps everything we want to exclude in terms of full filenames appears only twice (including **/*publish.xml and **/*.sql) whilst what we do want to include appears seven times. So that bit seems to be working.
The problem seems to be in the generation of the final Lines of Code calculation which appears to be calculating 30k too high due to CSS and XML. This brings us to a total of 494k lines of code which is perilously close to our 500k billing allowance hence my desire to get loc down. Cheers!
I don’t think there is a way today to drilldown from the UI to find files by language.
I just realized something: what SonarCloud will consider as XML file is controlled by the file suffixes property, and by default it is .xml,.xsd,.xsl,.config.
So if you really want to exclude all “XML” files, you should configure exclusions like:
Great thought @Julien_HENRY - I’ve just tested and those extra exclusions have WORKED!
In a similar vein I wondered if SonarCloud has a more liberal interpretation of CSS and it DOES!
Excluding **/*.scss and **/*.sass has almost eliminated the CSS element. Weirdly, there are still 919 lines of CSS which I can live with of course, but would be interested to know where they are coming from. If CSS is embedded in HTML files will it pick those up?
Many thanks for all the responses to this - hopefully will be of use for others.