wemake-python-styleguide icon indicating copy to clipboard operation
wemake-python-styleguide copied to clipboard

Forbid unused `noqa` comments

Open sobolevn opened this issue 6 years ago • 7 comments

Rule request

Thesis

We should raise a warning when noqa comment is unused. However, I am not sure that this is possible without patching flake8.

Reasoning

Consider this example:

some_variable = 12  # noqa: A001

A001 means that your name overrides some python builtin. But, it does not look like so. Or does it?

This kind of errors happen to have historical roots. At some point in time they were actually used, but then the code was refactored. But the comment was left untouched.

sobolevn avatar Sep 30 '18 17:09 sobolevn

See https://github.com/snoack/flake8-per-file-ignores/blob/master/flake8_per_file_ignores.py#L61-L65

This is already implemented. We just need to copy this logic.

sobolevn avatar Nov 17 '18 13:11 sobolevn

Related: https://github.com/asottile/yesqa

sobolevn avatar Mar 19 '20 11:03 sobolevn

We can also warn about unused ignore= and per-file-ignores=

sobolevn avatar Mar 19 '20 11:03 sobolevn

I think there is another related option: https://pypi.org/project/flake8-noqa/

maltevesper avatar Mar 21 '21 22:03 maltevesper

I think there is another related option: https://pypi.org/project/flake8-noqa/ It's a nice package indeed. Added it to one of my projects and it "just worked"!

aleksey-sergey avatar Sep 21 '21 12:09 aleksey-sergey

I am really interested in this. It is also useful to remove the silencing of false positives when they are fixed.

vnmabus avatar Jul 22 '22 09:07 vnmabus

@vnmabus May be just use flake8-noqa?

urtow avatar Aug 21 '23 15:08 urtow