Skip to content

unmatched-suppression-comment (RUF104)

Preview (since 0.14.11) · Related issues · View source

This rule is unstable and in preview. The --preview flag is required for use.

What it does

Checks for unmatched range suppression comments

Why is this bad?

Unmatched range suppression comments can inadvertently suppress violations over larger sections of code than intended, particularly at module scope.

Example

def foo():
    # ruff: disable[E501]  # unmatched
    REALLY_LONG_VALUES = [...]

    print(REALLY_LONG_VALUES)

Use instead:

def foo():
    # ruff: disable[E501]
    REALLY_LONG_VALUES = [...]
    # ruff: enable[E501]

    print(REALLY_LONG_VALUES)

References