Python Issue Suppression Improvements (NOSONAR) and New Rules

Hello Python Developers,

It fills us with great pleasure to announce the long-awaited feature to finally be able to suppress individual rules with # NOSONAR(SXXXX, ...). The most recent release allows you to specify which rules the # NOSONAR comment should suppress by adding the rule IDs in parentheses. For example, # NOSONAR(S1578, S7500) would therefore suppress S1578 and S7500. You will still be able to use # NOSONAR without the rule key to suppress all issues in the line.

Alongside this, support for noqa has been added. For the uninitiated, noqa is an almost universal way of telling linters and IDEs to not raise an issue. Like with # NOSONAR, it is possible to specify exactly which rules should be suppressed by appending the rule key after a colon in a comma-separated list, like # noqa: S1720, S7500.

Example:

def main():
    i1, i2 = input("Enter first number: "), input("Enter second number: ")
    result = executeOperator(
        i1, # NOSONAR(S5655) i1 should be an int
        i2, # noqa: S5655 i2 should also be an int
        "+"
    )
    print(f"Result: {result}")

def executeOperator(i1: int, i2: int, operator: str) -> int: # noqa: S1172, S1542
    return i1 + i2

As you can see in the example above, # NOSONAR(S5655) prevents an issue being raised about i1 being a str and executeOperator expecting an int. The same works with # noqa: S5655 on the next line. Further down, # noqa: S1172, S1542 suppresses that executeOperator should really be named execute_operator, and that operator is never used.

If you’d like to keep track of usage of # NOSONAR and # noqa, rules S1291 and S1309 can be enabled, and they will subsequently raise an issue whenever a # NOSONAR or # noqa comment is found.

Additionally, we have added S7632 to check for correct usage of # NOSONAR & # noqa.

All of this will be available in the upcoming releases of SonarQube Cloud, SonarQube IDE, SonarQube Server 2025.4 and SonarQube Community Build 25.8. Try it out and leave your feedback below!

9 Likes

Hi, nice improvement!

Currently we also use ruff on our code, which uses noqa comments and which has rules with similar and even identical IDs as sonarqube: Rules | Ruff

I assume this will lead to conflicts. E.g. # noqa: S107 will suppress S107 (Functions, methods and lambdas should not have too many parameters) in SonarQube and hardcoded-password-default (S107) | Ruff in ruff. Am I correct?

To prevent such conflicts, is it possible to prevent sonarqube from interpreting noqa comments?

2 Likes

Hi @StefanDensow,

Thanks for reaching out to us.

You’re indeed correct. # noqa: S107 would be interpreted by both ruff and SQ. Unfortunately, there is currently no way of preventing SQ to interpret both # NOSONAR and # noqa. I’ve created a ticket internally to address this.

Best,
Sebastian

2 Likes

Yes You need tospecified the noqa as comment so that sonar can understand else you need to keep deactivate the rule which is not a right approach