blanket-ignore (SMP004)¶
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¶
1VALUE = compute() # ty: ignore
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¶
noqaafter an earlier one: Ruff reads only the firstnoqaof a comment, and anoqait rejects still counts as that first one. A later barenoqais therefore not reported by PGH004, and it is reported here.Example: reported
1import os # noqa: F401 # noqaFile-level
noqaafter an earlier one: the same holds forruff: noqaandflake8: noqaon 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-ignoreandsimplint: ignorewithout 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: ignorewithout 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: ignoreandtype: ignorewith a reason or empty brackets: PGH003 reports these only when nothing followsignorebut 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]andpyright: ignore[code]limit the suppression to those errors, andnoqa: CODEdoes 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-levelruff: noqaorflake8: noqa, and PGH003 reports a baretype: ignoreorpyright: ignore. This rule leaves them to Ruff only when the project’s Ruff configuration selects that rule, and Ruff’s own suppressions of it, throughper-file-ignoresornoqa, are respected too.Example: not reported
pyproject.toml1[tool.ruff.lint] 2select = ["PGH003", "PGH004"]
1import os # noqa 2 3# flake8: noqa 4VALUE = 1 # type: ignore
ruff: ignoreandruff: file-ignorewithout 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.toml1[tool.ruff.lint] 2select = ["RUF103"]
1VALUE = 1 # ruff: ignore 2# ruff: file-ignore 3import os
ruff: ignorewith a space before its codes: Ruff reads the codes ofruff: ignore [E501]andruff: file-ignore [E501], so the directive is not a blanket one.Example: not reported
1VALUE = 1 # ruff: ignore [E501]noqacomments Ruff rejects: Ruff warns about anoqawhose 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 itFile-level directives out of place: Ruff applies
# ruff: noqaonly on a line of its own and# ruff: file-ignoreonly at module scope; anywhere else it warns and applies none of it.Example: not reported
1import os # ruff: noqaDirectives 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
ignoredafterty: ignoreis ordinary text.Example: not reported
1ELEVENTH = 11 # ty: ignored laterText 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.