Setting notification level based on SonarCloud category

  • Operating system: Windows 10 21H2 (Build 19044.4529)
  • Visual Studio version: Version 17.10.2
  • SonarLint plugin version:
  • Programming language you’re coding in: C#
  • Is connected mode used: Yes
    • Connected to SonarCloud (and which version): Unsure how to check this version.

Intent: Visualize the level of severity in the IDE for developers before making a PR.

  • Set all active SonarCloud Code Smell rules to a minimum of warning level.
  • Set all active SonarCloud Software Quality rules to error level.

Today, we haver all rules defined in our .editorconfig file, grouped by category and flagged with the information level we want to use.
This works well, until we update the quality profiles and there is a mismatch between the cloud profile and the solution editorconfig.
The editorconfig will override the cloud settings locally and highlight rules we have disabled in the cloud.
We would prefer to only set the notification level in the quality profile, and remove the overrides in the editorconfig.

How can we best achieve the intent? Preferably with as few manual changes as possible.

Hi @OddMathisenNOV

Thanks for reaching out!
To have more context, you are modifying the .editorconfig file manually? Could you send an extract of it?
Why do you want to visualize the level of severity in the IDE before PRs?



This is an excerpt from our .editorconfig. We modify it manually in the sense that we built a tool that scrape the currently existing rspec rules from the sonar-dotnet repo, then set them to warning or error depending on the type.

#### SonarLint configuration ####
# Maintaining this list:
#   Use the SonarEditorConfigBuilder project to build a new list for SonarLint updates.


# S1147: Blocker :: Exit methods should not be called
dotnet_diagnostic.S1147.severity = warning

# S1451: Blocker :: Track lack of copyright and license headers
# dotnet_diagnostic.S1451.severity = warning

# S2178: Blocker :: Short-circuit logic should be used in boolean contexts
dotnet_diagnostic.S2178.severity = warning

# S2187: Blocker :: Test classes should contain at least one test case
dotnet_diagnostic.S2187.severity = warning

# S2306: Blocker :: "async" and "await" should not be used as identifiers
dotnet_diagnostic.S2306.severity = warning

# S2368: Blocker :: Public methods should not have multidimensional array parameters
dotnet_diagnostic.S2368.severity = warning

# S2387: Blocker :: Child class fields should not shadow parent class fields
dotnet_diagnostic.S2387.severity = warning

As for why: We set warnings and errors as high visibility in the IDEs. We wish to see the sonar notifications more clearly in the editor, so they are easier to see visually before making a PR.
This reduced the amount of noise and “back-and-forth” each developer had when trying to get a new PR ready for review.

If you know of a better way to achieve this we are open for suggestions.

Thanks for sharing. I see what you are trying to achieve.

For now you have to do it manually I’m afraid.
Something that will come later this year will be the Focus on New Code functionality in Visual Studio, meaning that you will be able to apply the Clean as You Code methodology directly in the IDE. We really promote this methodology to reach the Clean Code state on your projects. If you want to apply it, it means the developers would solve every issue on New Code and having severity classification would make less sense.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.