Operating system: Windows 10 Education: 10.0.19044 Build 19044
SonarLint plugin version: SonarLint for Visual Studio 2017 5.5.0.43817
Connected to: SonarQube Version 9.4 Build 54424
My solution has two projects. Both projects have rule sets that simply include the rule set in the .sonarlint folder of my solution. Both projects appear to be working with almost all of the rules in that rule set.
For example: Rules S108, S1125, and S1481 work in both of my projects.
Rule S1542 works only in one of my projects. By “works” I mean the error is underlined and shown in the error list window. In the other project, it seems that this rule is simply ignored for some reason.
As far as I can tell, there are not multiple sonar rule sets in my solution.
If there’s any more information I can collect to assist with resolving this issue, I would be very glad to do that.
Below is an improperly named method per rule S1542:
Private Sub TESTMETHOD()
'
End Sub
I have pasted this method into both of my projects, but only one of the projects recognizes and reports this in the error list.
However, if I remove the apostrophe, both projects will report a violation of rule S1186.
I’ve also just noticed that my project that isn’t working with rule S1542 also doesn’t work with rules S2364, S2366, or S101. I suspect the project also doesn’t work with the other various naming related rules.
Another update: I’ve been able to upgrade to Visual Studio 2022 and all of the issues described above are still present with the updated IDE and updated SonarLint extension.
regarding rule S1186: the rule works as expected since the comment is handled as an exception and will make the method compliant. In the documentation it’s the first case from the Compliant solution.
Compliant Solution
Sub DoSomething()
' Not implemented because of reason
End Sub
Regarding the other rules, could you provide some code examples where the behavior is not as expected?
Just to clarify my comment about rule S1186: I wasn’t implying that that rule was broken. I was using it as an example of a successful rule application in both projects. I meant to show that because that rule worked in both projects, both projects are at least capable of applying some of the rules, but not all (S1542).
My original code example is an example of rule S1542 failing to apply.
All following examples have been pasted into both of my projects and are failing to apply in only one:
S2364:
Private TEST As Integer
S2366:
Public Property TEST As Integer
Upon further examination of rule S101 I’ve found that it does work for both projects. I was fooled into believing that rule didn’t work because I was looking at an improperly named module, not an improperly named class.
Sorry I forgot to mention, I was thinking to reproduce this issue using the SonarScanner for .NET and not SonarLint. The verbose parameter can be passed only to the scanner.
By the way, is the issue reproducible only with SonarLint or with the SonarScanner for .NET too?
Does the project with missing issues reference any test framework assemblies or other test related dependencies: mocking or assertion frameworks? Currently SonarQubeTestProject property is not read by the SonarLint.
The issue is only present with SonarLint. SonarScanner for .NET is working exactly as expected so we can still see any issues introduced, but we have to wait until someone pushes new code and wait for a build to complete until we see the complete set of issues.
I just searched through the project references and found that it was referencing a unit testing framework called NUnit. After removing those references, it seems that all the expected rules are working just as intended! Thank you!
Do you know why these references would be causing only some rules to fail?
I just searched through the project references and found that it was referencing a unit testing framework called NUnit. After removing those references, it seems that all the expected rules are working just as intended! Thank you!
Great. Happy that it solved the problem for you.
Do you know why these references would be causing only some rules to fail?
Yes. We have some rules that are designed to work only for not test projects and some rules that are designed to work only for test projects. We also have an automatic detection heuristic on our rules that detects the project type and enable/disable the rules depending on it. Since the SonarQubeTestProject property is not read by the SonarLint (currently it’s read only by the scanner), we used the heuristic instead.