flake8 icon indicating copy to clipboard operation
flake8 copied to clipboard

flake8 should only consider a noqa comment if it is actually a comment

Open asottile opened this issue 4 years ago • 2 comments

minimal reproduction:

def f():
    x = '# noqa'

I expect this to report the same as if that were an unrelated string:

def f():
    x = '......'
$ flake8 unrelated.py
unrelated.py:2:5: F841 local variable 'x' is assigned to but never used

asottile avatar Apr 24 '21 20:04 asottile

Did you already have something in mind to fix this?

If I'm following correctly (disclaimer: I'm new to Flake8's internals), the inline noqa check comes from this regex, is it desired to come up with a solution to this that fits into the regex? Or, maybe overthinking, can we do something like tokenize the line if the regex matches and check for a noqa comment (around here)?

sco1 avatar May 05 '21 02:05 sco1

yeah I'm planning to maybe rework this into a pipeline based on the tokenization (since that has to happen for linting anyway) -- I don't really want to shoehorn it into the existing structure as I'll probably be reworking that. I think the regex is still relevant but it should only be tested against COMMENT tokens

asottile avatar May 05 '21 02:05 asottile