This rule raises an issue when issue suppression comments have an incorrect format or syntax.

Why is this an issue?

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.

What is the potential impact?

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.

How to fix it

Fix the syntax of issue suppression comments to follow the correct format.

For # NOSONAR:

For # noqa:

Code examples

Noncompliant code example

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

Compliant solution

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

Resources

Documentation