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!