- What language is this for? C#
- Which rule? S125
- Why do you believe it’s a false-positive/false-negative?
I acknowledge there’s an older topic about this false positive and I’ve also seen one GitHub issue about it, but I wanted to ask if we could reconsider or if the team could at least try to improve this rule. In the short few months I’ve been using Sonar, I’ve already encountered a few irritating instances of it (and, ironically although not surprisingly, not even a single true positive).
One big offender for me is putting ‘ends with a semicolon’ in the list of rules of your heuristic – that just seems too broad for me. There is at least one common way where phrases can terminate with a semicolon, and that’s lists:
- This one;
- Then this one;
- Then that one; and
- Finally, this one here.
The first two lines above are flagged by Sonar as commented code.
But then, considering source files need line breaks in between long expressions or long sentences in comments, then you also need to be careful where you break your lines so that you don’t break in the wrong place;
Otherwise Sonar will force you to rewrite your sentences!
And then there’s of course the issue of not being able to legitimately include code in comments (eg. giving examples or explaining how/why something was done).
And many many other false positives generated by this rule that you can find people complaining about on the internet.
In both of the issues I saw about this particular false positive, a Sonar team member responded saying that this is by design.
So is my understanding correct that the following truly is the Sonar’s team recommendation for developers who frequently hit this?
1) globally disable the rule in your projects; or
2) litter your code with #pragmas; or
3) change your writing style.
When a rule frequently forces you to write code – or, in this case, natural language text!! – differently only so that you don’t hit the rule (as opposed to writing better code), what is the point?
Does you data really suggest that this rule triggers more true positives than false ones? I truly do find that hard to believe.
Would it at least be possible to allow customization of the heuristic?
- Are you using
- SonarQube Cloud? No
- SonarQube Server / Community Build - which version? No
- SonarQube for IDE - which IDE/version? SonarQube for Visual Studio version 8.30.0.15605
- in connected mode with SonarQube Server / Community Build or SonarQube Cloud? No
- How can we reproduce the problem? Give us a self-contained snippet of code (formatted text, no screenshots) A few examples above;