9

I installed SonarLint in VS 2015 and it looks like a great extension with lots of potential.

At the moment the extension is also analysing my test projects and giving warnings about this. How can I disable inspection of specific (test) projects?

Update Its not about disabling specific Sonar rules or projects in SonarQube, but its about the Visual Studio extension SonarLint.

Niek Jannink
  • 1,056
  • 2
  • 12
  • 24
  • possible duplicate of [How to disable Sonar rules for specific files?](http://stackoverflow.com/questions/21103175/how-to-disable-sonar-rules-for-specific-files) – Artem Kulikov Aug 17 '15 at 07:32
  • 2
    Not a duplicate, this is not about disabling the rule on the SonarQube server, but inside Visual Studio. – jessehouwing Aug 17 '15 at 07:41
  • Our goal is to have a default ruleset applicable for both test and non-tests projects. Could you mention which rules in particular are bothering you on test projects and why? – Dinesh Bolkensteyn Aug 17 '15 at 09:13
  • @Dinesh, I will have a look tonight which rules. Im not interested in. Probably its mainly about naming and spelling, localization and unused locals – Niek Jannink Aug 17 '15 at 11:14
  • I let you check - C# naming convention rules should not be available in SonarQube because they cannot be customized (whereas they can in the C# SonarQube plugin). I don't think we have localization rules. Finally, I don't see why you would allow unused locals in tests? In any case, FxCop & other tools rulesets can be changed as described in the answer below. – Dinesh Bolkensteyn Aug 17 '15 at 16:44
  • 1
    @Dinesh-SonarSourceTeam in the case you have a class with a constructor that throws Exception on invalid arguments then you do something like `var testObj = new MyObject()` and then decorate the method with `[ExpectedException(typeof(XxxException))]`. In that case you get that unused local variable warning that I don't care about – Niek Jannink Aug 18 '15 at 05:52
  • `_ = testObj;` is the simplest way I found for these – mBardos Jul 06 '21 at 12:43

1 Answers1

8

In Visual Studio, open the project and then dig into the Reference section. There choose to edit the active rule set:

Open Active Ruleset

In the screen that opens select/deselect the rules you want for the specific project. Then hit save. This will most likely create a new .ruleset file in your project and instruct Roslyn to use that instead of the standard set.

The result is that the project file is updated with the <CodeAnalysisRuleSet> tag like this:

<CodeAnalysisRuleSet>UnitTests.Core.ruleset</CodeAnalysisRuleSet>

You can also use the add new file wizard and pick the "Code Analysis Rule set" option:

enter image description here

Then from the Analyze menu select "Configure Code Analysis for Solution", your newly added rule set can be selected from there and assigned to the project you want:

enter image description here

jessehouwing
  • 106,458
  • 22
  • 256
  • 341