SonarLint should use the severity specified in the Quality Profile

I’m using SonarLint for VS2019 and despite innumerous tries, the severity of the custom rules is still being set to Warning regardless of their severity in the Quality Profile on SonarQube.
of my troubleshooting, I reinstalled the SonarLint plugin, tried fetching the custom rules for different projects but none worked. It’s critical for our projects to have a fix for this as soon as possible.
Can you please advise here?

SonarLint version : 4.31

1 Like

Hello, thank you for your feedback.

As stated on the project’s wiki, this is by design - there is no 1:1 mapping of SonarQube/Cloud rule severity to IDE problem levels.

Given that SonarQube/Cloud rules define 5 levels vs the IDE’s 3 levels, and given that the IDE’s “Error” level is blocking by default, what do you believe would be an appropriate mapping for your use case? What are you trying to achieve?

@JBL_SonarSource as per below issue link which has mentioned that we can have custom severity in IDE based on the sonarQube Quality profile.

Cant we change settings like below.

Info → Info
Minor → Info
Major → Warning
Critical → Error
Blocker → Error

@sachin-agarwal-by if you read the Implementation Notes section of that ticket you’ll see that it states that the expected mapping is on the one given by @JBL_SonarSource (prior to the ticket being implemented, the VS severity was always Warning irrespective of what was in the Quality Profile)

If you want to increase the severity of rules locally you have two options:

  • Blocker issues can be treated as Errors in VS by setting the SONAR_INTERNAL_TREAT_BLOCKER_AS_ERROR environment variable as described in the ticket, or
  • the default binding process creates a local ruleset that imports the generated ruleset. Any settings in the local ruleset override the generated ruleset, so you could change the severity in the local ruleset (note that SLVS will complain if you try to weaken the Quality Profile in the local ruleset, but it won’t complain if you strengthen what is in the Quality Profile e.g. by enabling more rules or increasing severities).
1 Like

@duncanp may I know where should I use SONAR_INTERNAL_TREAT_BLOCKER_AS_ERROR as true in project so that I can checkin the code and it will work for other team memebers as well.
Can I mark critical also as error by using some other settings as well?

@sachin-agarwal-by It’s an environment variable, not a project variable so it would need to be set per-machine. There isn’t a corresponding variable for Critical issues.

@duncanp I tried setting System and User both env variable one by one but still its not working.
any thing I am missing ?

@sachin-agarwal-by

Did you do what it says in the ticket you referred to?

Note:

  • this experimental feature could be removed without notice at any time.
  • to use it, set the SONAR_INTERNAL_TREAT_BLOCKER_AS_ERROR to “true”; then restart VS, and update the binding configuration to force the ruleset to be regenerated.

@duncanp restart VS and binding works now .

1 Like

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