[Python] Add inline disabling of specific rule

Currently Sonar has no option to disable specific rule for certain line in Python code. It is possible to completely disable certain line check via “# /NOSONAR” but that’s not the case if we would like to suppress only certain check. Something line: “# noinspection <rule_name>” would be great.

1 Like

Hi,

This is available in the UI. Would you mind giving your use case for doing it in code instead?

 
Thx,
Ann

Sharing in project to other users? Currently all of them should manually set that, disabling it via code could be more elegant.

pon., 29 sie 2022, 18:35 użytkownik G Ann Campbell via Sonar Community <notifications@sonarcommunity.discoursemail.com> napisał:

1 Like

Is it possible, that Sonar will incorporate that?

What about the same as @SuppressWarning(rule_id) in Java? Is consistency with the same tool in other language not a good reason by itself?
Btw another OBVIOUS reason is to make the rule project-dependent, and not IDE-dependent or user-dependent.

I’m being compelled to use Sonarcloud at work. This is absolutely needed and standard in other linting solutions (flake8) etc…

We’ll have to switch to a different product if this isn’t available.

1 Like

The use case is that sometimes we have a good reason to break the rule ONCE. But we still want the rule to apply to the entire rest of the code. This also makes it visible that the rules are being broken and we want to have git-tracked evidence that this is happening as opposed to people silently changing settings in places that aren’t tracked by git.

3 Likes

Not having the ability to suppress a warning IN THE CODE makes this pretty much a useless project. In the pylint plugin I can do # pylint: disable=import-error,no-name-in-module. This has been a feature of linters for a long long time. Until this is fixed, I’ll not be recommending SonarLint to my colleagues. Disappointing.

1 Like