E402: noqa that affects lints on other lines
:wave:
I'm scoping implementing: warn on unused noqa comments (for flake8) and I've noticed a problem with my initial approach, the E402 error can be suppressed by a noqa comment on a line that is not the line where the error occurs
current state
Take the following:
import os
x = 1
import foo
which produces:
$ ~/opt/venv/bin/pycodestyle t.py
t.py:5:1: E402 module level import not at top of file
there are two ways currently to suppress this:
import os
x = 1 # noqa
import foo
and
import os
x = 1
import foo # noqa
===============
proposal 1
the first proposal would be to change the reported location of the errors to the non-import offending line of code. in files where there are lots of imports after some code (take for instance gevent monkepatching) the entirety of the (many) E402 would be silence-able with a single noqa (still) but the reported line and noqa line would be consistent such that the "warn unused noqas" can work
proposal 2
don't allow noqa on the non-import offending line of code and require it to be on the individual imports afterwards
this has a negative in that those which are using the first noqa strategy above would have to add many new noqa comments on each import, but it would satisfy what I want to do
proposal 3
???
===================
related: https://github.com/asottile/yesqa/issues/19 https://github.com/PyCQA/pycodestyle/issues/871