ruff icon indicating copy to clipboard operation
ruff copied to clipboard

new rule - require comment explaining `type:ignore`/`pyright:ignore` comments

Open DetachHead opened this issue 2 years ago • 2 comments

it would be nice to have a rule that enforces that type:ignore comments have a comment above them describing the reason the error is being suppressed, eg:

incorrect:

def foo():
    a: str = 1  # type:ignore[assignment] # error: add a comment on the line above explaining why the error is being ignored

correct:

def foo():
    # false positive, see https://github.com/python/mypy/issues/1
    a: str = 1  # type:ignore[assignment]

eslint has a rule for this: https://typescript-eslint.io/rules/ban-ts-comment/

related: #5182

DetachHead avatar Nov 03 '23 01:11 DetachHead

Does this request extend to checker-specific suppression comments as well? (# pyright: ignore is the only one I can think of, since # noqa is requested here: https://github.com/astral-sh/ruff/issues/5182)

Avasam avatar Apr 08 '24 23:04 Avasam

true, thanks. i updated the issue

DetachHead avatar Apr 08 '24 23:04 DetachHead