blanket-ignore (SMP004)

SMP004No fixCommentsAll rules

Flags suppression comments that name no error code, except the forms Ruff’s PGH003, PGH004 and RUF103 report while the project’s Ruff configuration selects them, such as a bare # noqa, # type: ignore or # ruff: ignore. It covers the rest, such as # ty: ignore. A blanket suppression hides every error on its line or in its file, including errors that appear there later.

Why is this bad?

A blanket suppression hides every error on its line, or in its file, including errors that appear there later. A real bug that lands on the same line passes unnoticed, and the comment never says which error it was meant for.

Example

Flagged
1VALUE = compute()  # ty: ignore
Preferred
1VALUE = compute()  # ty: ignore[invalid-assignment]

What it does

No fix is offered: the comment does not say which codes it should name.

Active on

  • noqa after an earlier one: Ruff reads only the first noqa of a comment, and a noqa it rejects still counts as that first one. A later bare noqa is therefore not reported by PGH004, and it is reported here.

    Example: reported
    1import os  # noqa: F401 # noqa
    
  • File-level noqa after an earlier one: the same holds for ruff: noqa and flake8: noqa on a line of its own, where Ruff reads only the first one of a comment.

    Example: reported
    1# flake8: noqa # ruff: noqa
    2import os
    
  • ruff: ignore, ruff: file-ignore and simplint: ignore without codes: each directive whose brackets are missing or empty.

    Example: reported
    1VALUE = 1  # ruff: ignore
    2OTHER = 2  # simplint: ignore
    
    Example: reported
    1# ruff: file-ignore
    2import os
    
  • ty: ignore, pyrefly: ignore without codes: each directive whose brackets are missing or empty, with or without a reason after it, since the reason does not limit what it hides.

    Example: reported
    1VALUE = 1  # ty: ignore
    2THIRD = 3  # pyrefly: ignore
    3FIFTH = 5  # ty: ignore because the stub is wrong
    
  • pyright: ignore and type: ignore with a reason or empty brackets: PGH003 reports these only when nothing follows ignore but whitespace or another comment. A reason after them, or empty brackets, leaves them to this rule.

    Example: reported
    1OTHER = 2  # pyright: ignore because the stub is wrong
    2SIXTH = 6  # type: ignore because the stub is wrong
    3FOURTH = 4  # type: ignore[]
    
  • Each directive of a comment: a comment can hold several directives, and each one without codes is reported.

    Example: reported
    1TENTH = 10  # ty: ignore[unresolved-import] # pyrefly: ignore
    

Exceptions

  • Directives that name codes: ty: ignore[code] and pyright: ignore[code] limit the suppression to those errors, and noqa: CODE does the same for Ruff.

    Example: not reported
    1import os  # noqa: F401
    2
    3SEVENTH = 7  # ty:ignore[unresolved-import]
    4EIGHTH = 8  # pyright: ignore[reportAttributeAccessIssue]
    
  • Forms Ruff reports: Ruff’s PGH004 reports a bare noqa, a file-level ruff: noqa or flake8: noqa, and PGH003 reports a bare type: ignore or pyright: ignore. This rule leaves them to Ruff only when the project’s Ruff configuration selects that rule, and Ruff’s own suppressions of it, through per-file-ignores or noqa, are respected too.

    Example: not reported

    pyproject.toml

    1[tool.ruff.lint]
    2select = ["PGH003", "PGH004"]
    
    1import os  # noqa
    2
    3# flake8: noqa
    4VALUE = 1  # type: ignore
    
  • ruff: ignore and ruff: file-ignore without codes: Ruff’s invalid-suppression-comment (RUF103) reports them while the project’s Ruff configuration selects it, and this rule leaves them to Ruff then.

    Example: not reported

    pyproject.toml

    1[tool.ruff.lint]
    2select = ["RUF103"]
    
    1VALUE = 1  # ruff: ignore
    2# ruff: file-ignore
    3import os
    
  • ruff: ignore with a space before its codes: Ruff reads the codes of ruff: ignore [E501] and ruff: file-ignore [E501], so the directive is not a blanket one.

    Example: not reported
    1VALUE = 1  # ruff: ignore [E501]
    
  • noqa comments Ruff rejects: Ruff warns about a noqa whose colon names no code, or whose code runs into other text, and applies none of it, so the comment hides nothing.

    Example: not reported
    1import sys  # noqa: because plugins import it
    
  • File-level directives out of place: Ruff applies # ruff: noqa only on a line of its own and # ruff: file-ignore only at module scope; anywhere else it warns and applies none of it.

    Example: not reported
    1import os  # ruff: noqa
    
  • Directives that take no codes: coverage.py’s pragmas name no error, so they are not blanket suppressions.

    Example: not reported
    1if DEBUG:  # pragma: no cover
    2    VALUE = 1
    
  • Words that only start with a directive: a directive must be a whole word, so ignored after ty: ignore is ordinary text.

    Example: not reported
    1ELEVENTH = 11  # ty: ignored later
    
  • Text inside strings: only comments count, so a directive written in a string literal is not checked.

    Example: not reported
    1THIRTEENTH = "# ty: ignore"
    

Ruff overlap

Ruff’s blanket-noqa (PGH004) and blanket-type-ignore (PGH003) own the forms that name no code and that Ruff reads as blanket: the first noqa of a comment and the first file-level ruff: noqa or flake8: noqa, and a type: ignore or pyright: ignore with nothing after ignore. Ruff’s invalid-suppression-comment (RUF103) owns a ruff: ignore or ruff: file-ignore whose brackets name no code. This rule leaves those forms to Ruff only while the project’s Ruff configuration selects the rule that reports them, and Ruff’s own suppressions of it, through per-file-ignores or noqa, are respected too. It keeps the rest, including the noqa that follows an earlier one in the same comment, and the ty, pyrefly and simplint forms.

Other tools

  • Ruff: variation of released rules PGH003, PGH004 and RUF103, which report a bare type: ignore, the first noqa of a comment, and ruff: ignore without codes; this rule leaves those to them and covers the ty, pyright, pyrefly and simplint directives and the rest.