ruff
ruff copied to clipboard
new rule - require comment explaining `type:ignore`/`pyright:ignore` 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
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)
true, thanks. i updated the issue