This rule raises an issue when issue suppression comments have an incorrect format or syntax.
Issue suppression comments like # NOSONAR and # noqa are essential tools for controlling code analysis. When these
comments have incorrect syntax, they may not work as expected, leading to confusion about which issues are actually suppressed.
Python code analysis supports two main suppression formats: - # NOSONAR - SonarQube’s suppression comment - # noqa -
Python’s standard "no quality assurance" comment
Each format has specific syntax rules. When these rules are violated, the suppression might fail silently or behave unexpectedly, making it unclear whether issues are intentionally ignored or accidentally unsuppressed.
Incorrectly formatted suppression comments can lead to unintended code analysis behavior. Issues that developers think are suppressed might still be reported, while malformed syntax might cause the analyzer to ignore more issues than intended. This creates confusion during code review and reduces confidence in the analysis results.
Fix the syntax of issue suppression comments to follow the correct format.
For # NOSONAR:
# NOSONAR alone to suppress all issues on the line # NOSONAR() with empty parentheses to suppress all issues # NOSONAR(ruleKey1, ruleKey2) to suppress specific rules # NOSONAR(,) S7632 or NoSonar For # noqa:
# noqa alone to suppress all issues on the line # noqa: rule1,rule2 to suppress specific rules (with or without spaces after colon) # noqa: ,rule1 :) between noqa and the rule ID, and don’t use other punctuation
def example():
x = 1 # NOSONAR( # Noncompliant
y = 2 # NOSONAR(a,) # Noncompliant
z = 3 # NOSONAR)( # Noncompliant
a = 4 # NOSONAR(python:S7632) # Noncompliant
b = 5 # noqa: ,rule1 # Noncompliant
c = 6 # noqa- rule1,rule2 # Noncompliant
def example():
x = 1 # NOSONAR
y = 2 # NOSONAR(a)
z = 3 # NOSONAR
a = 4 # NOSONAR(S7632)
b = 5 # noqa: rule1
c = 6 # noqa: rule1,rule2