Search code examples
.netvisual-studio-2015sonarqubesonarlintsonarlint-vs

SonarQube/SonarLint/Visual Studio: Use one ruleset fo all projects in solution


We are currently in the process of evaluating the use of SonarQube/SonarLint for our .NET applications. We are pretty happy with what we've seen so far (and, btw, kudos for bringing SonarQube this far - I've used it a couple of years ago for my PhD project, and it has improved greatly since then!).

However, one thing was a bit surprising: When I connected my SonarLint instance to our SonarQube server (which worked just fine) and started syncing the bound project, SonarLint started to download nuget packages (which was kind of expected) and then created one or even two .ruleset files for each project of our solution (in addition to a file SonarQube/<solution name>CSharp.ruleset which I assume is the solution-wide ruleset).

What I expected and would prefer is only the single ruleset valid for the complete solution (and possibly the option to override that ruleset for projects where this makes sense (e.g., test projects)).

Is this behavior possible at all, i.e., did I miss anything? Documentation is the only area I've identified so far where SonarLint is lacking.


Solution

  • There is a reason why these additional ruleset files are created. Well actually there are multiple:

    • That is to allow you to set a baseline to which all projects must adhere, but the enable additional rules for projects with specific types of code. You may have a couple MSOCAF rules enabled that are specific to Sharepoint projects, which don't make sense for your Unittest or Windows Service projects

    • Say, when you are fixing technical debt in your projects, you can set a baseline for the whole solution and that slowly tighten the rulesets of the individual projects so that you can focus your cleanup effort on a specific project. Instead of having to clear up a specific rule or set of rules across all projects in the solution at the same time.

    One of the project ruleset files will be overwritten each time you sync with SonarQube. The other one will remain as you've left it. Allowing you to save your customizations and still allowing you to safely sync changes to the SonarQube baseline.

    If I'm remembering this correctly, the Solution ruleset is included in the project ruleset as is the ruleset in which you store your customizations. Currently I don't have a SonarQube server at hand to verify which ruleset file server which purpose, but this is the reasoning behind it.