Reputation: 773
Is there a way to get flake8
to ignore only a specific rule for an entire file? Specifically, I'd like to ignore just F401
for an entire file.
I have a file like __init__.py
where I import symbols that are never used within that file. I'd rather not add # noqa
to each line. I can add # flake8: noqa
to the beginning of the file, but that ignores all rules. I'd like to ignore just the F401
rule.
Upvotes: 48
Views: 28735
Reputation: 6354
Default config doesn't allow to specify the 'ignores' in the file itself, only in the general config but this plugin allows it (I'm the author)
https://github.com/bagerard/flake8-in-file-ignores
Upvotes: 0
Reputation: 69844
there is not currently a way to do what you're asking with only source inside the file itself
the current suggested way is to use the per-file-ignores
feature in your flake8
configuration:
[flake8]
per-file-ignores =
*/__init__.py: F401
Note that F401
in particular can be solved in a better way, any names that are exposed in __all__
will be ignored by pyflakes
:
from foo import bar # would potentially trigger F401
__all__ = ('bar',) # not any more!
(disclaimer: I'm the current maintainer of flake8
and one of the maintainers of pyflakes
)
Upvotes: 67
Reputation: 6132
According to the Documentation it's as easy as changing # noqa
by:
# noqa: F401
Upvotes: 9