Can we configure the custom rules in Sonarlint?

  • Operating system: Windows 10 E
  • SonarLint plugin version: 6.9.0.54300
  • Programming language you’re coding in: C#
  • Is connected mode used: No

And a thorough description of the problem / question:
I wanted to set the rules like S107, Cognitive Complexity in SonarLint. Can I do that? I don’t want to use the connected mode to SonarQube as I don’t have the the UserName/Password/Token of that. I am new with the Sonar environment.

Hi @Rahul_K - welcome to the community!

Yes, you can configure the Sonar C# and Visual Basic rules as follows:

  1. Create a file called SonarLint.xml in the appropriate format (example here)

  2. Add a reference to that file to your MSBuild project as follows:

<ItemGroup>
  <AdditionalFiles Include="[... absolute or relative path...]\SonarLint.xml" />
</ItemGroup>

For a C# project, Visual Studio will show the file properties as follows:
image

1 Like

the reference to an example gives a 404

@MrAntix Here’s a copy from a previous version of the repo: sonar-dotnet/analyzers/.sonarlint/sonaranalyzer-dotnet/CSharp/SonarLint.xml at 8.56.0.67649 · SonarSource/sonar-dotnet · GitHub

1 Like