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?
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?
@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).
@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.
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.