Ignore Issue on Files feature is not working

We’re on Enterprise Edition of SonarQube 8.3 and I’m trying to allow developers to selectively ignore issue on files by placing the following string at the top of a file: “// SQIgnore”

I’ve configured the “Ignore Issue on Files” to ignore files that contain that string but analysis is still being triggered and they aren’t passing the quality gate like I would expect them to if the file was actually being ignored. Is there something more I need to do?

Hi Brian,

Can you confirm how you attempted to configure this? In the UI, with what value in what configuration entry? The setting should be a valid regular expression.

Here’s my admin screen:

I think you’re missing escaping on your comment slashes. Give this a shot:

\/\/ SQIgnore

Yep, I was. Thanks for the heads up. However, I updated the regex to contain the escape characters and it’s still analyzing files that have // SQIgnore at the top of the file. Maybe I need a more forgiving Regex?
Here’s my updated screen shot.

It worked for me when I tested it; a file with // SQIgnore at the top that contained a bug and a code smell reported no issues afterwards.

To be clear, this ignores issues on the file. Without other settings in place, the file will still factor into coverage & duplication results potentially. I’m not sure what your’e seeing specifically when you say “it’s still analyzing” the files.

Sorry, what I mean by analyzing that it still reports errors/code smells in the file even though we include the // SQIgnore on the file. I guess I’m a bit confused by what you mean about other settings and how the file will still factor into coverage metrics, that’s the exact metric I’m trying to ignore on those files. Is there a better way of removing certain specific files from coverage/duplication results?

Well first you said you wanted to ignore issues, but now you’re saying you want to ignore coverage and duplication as well, or instead of issues? There are ways to ignore coverage or duplication, but only based on file name matching, not based on comments/contents within the file.

If you want to avoid analyzing the file entirely, that’s not possible to do based on anything in the file contents, unless you get really clever and do something like a recursive grep before the analysis starts to build a list of the files to ignore and then manually pass it to the scanner as an analysis parameter. This would be rather challenging to do correctly depending on your shell & scripting abilities.

Apologies for the confusion. So, we’ve got a series of code behind files that primarily just control UI elements. We don’t want to have those sorts of files considered for Code Coverage metrics by SonarQube. Initially I thought the best way to hide the file was just place a “// SGInore”, but I didn’t realize that wouldn’t except it from Code Coverage. I’m relatively new to administrating this stuff so any advice you can provide is much appreciated.

If those files all live together in the same location(s), the easiest by far would be to simply exclude them by pattern-matching the location(s)/name(s) in which they can be found. The property by which to express this is sonar.exclusions, labeled as Source File Exclusions in the UI.

If, for example, your UI files all live in src/ui, you would set this value to src/ui/**/* which would then exclude all the files at that level and within any child directories. You can also match partial file names if the file names can be used as a hint for what should be excluded.