How can I enable a small amount of rules and disable the rest by default?

Hello Sonar Specialists,

Visual Studio 2022 Version 17.9.3
SonarLint Version 8.6.0.10679

There are 600+ rules and I’m being hit with all of them at once. I’m working in an old legacy codebase so it’ll be a challenge just to enable one rule. I need to start off with a small set of rules enabled with the rest disabled and then enable them one by one over time. I tried adding a few rules into my settings.json file, but I am still getting flagged with all 600+ rules.

Do I need to turn off each one manually? like so?

  "cpp:S1066": {
    "level": "Off"
  }

Also, I can’t seem to tune the complexity value, it just ignores my value of 50 here.

"cpp:S3776": { // Cognitive Complexity Rule
  "level": "error",
  "parameters": {
    "max": 50 // Set an initial high threshold for cognitive complexity
  },

I’ve ensured that my settings.json doesn’t have any errors and I’ve made sure to re-save so that it re-scans the file.

Does adding to my
{
“sonarlint.rules”: {

block update from the defaults or will sonarlint only use what is in that block?

take care,
David

I am in offline sonar lint mode. Are the extra things like parameters only available in sonar cloud?

Are there other tunables available to the offline sonar lint mode besides turning a rule off? I can’t find these in the Sonar Lint Documentation anywhere.

Hi,

I think your best bet here is to connect to wherever your project is regularly analyzed, whether that’s SonarQube or SonarCloud. That will limit the rule set to just what’s being applied during normal analysis.

The other thing is to Clean as You Code, which means focusing only on the issues raised in new code. Don’t pay attention to every issue raised in the file you’re working on; narrow your focus to just what’s going on in the code you’re working on.

 
HTH,
Ann

Hi Ann,

We can’t use SonarQube or SonarCloud just yet. Yes, cleaning as we go is always an option. I tried generating a settings.json file that had every single rule turned off. At the time, I had gone from:

	"cpp:S0": {
		"level": "Off"
	},

up to

	"cpp:S7000": {
		"level": "Off"
	}

and that appeared to have worked, until I find the next highest…

When I saw 664 rules, I had hoped that I could iterate through them all, but apparently they are all spread out.

Do you know what the max C++ rule is?
The docs don’t seem to list the rule tag, is there anywhere to find that?

Hi,

We’re always writing and implementing new rules. Not to be facetious, but “What’s the highest rule?” is a bit like “What’s the biggest number?”

That said, we store the rule specifications here.

 
HTH,
Ann