I use flake8
for linting and black
for formatting.
flake8
produces warnings on execution rules and formatting rules:
I only want to see execution rules. I don't care about formatting rules because they'll automatically get fixed by black
formatting:
I can disable these rules one at a time by running flake8 --ignore=E271,E225,W291,E231
. However, there's no exhaustive list of formatting rules to disable, they have to be discovered one at a time. It would be great to have something similar to JavaScript's eslint, where there's a plugin to disable all formatting rules that are covered by the code formatter.
Is there a similar way to disable all the formatting rules in flake8
?
Solution: Based on the below answer, I ended up ignoring all formatting rules with this command:
flake8 --ignore=E101,E111,E114,E115,E116,E117,E12,E13,E2,E3,E401,E5,E70,W1,W2,W3,W5 file.py
If we ever want to disable Flake8 respecting # noqa comments, we can can refer to flake8 --disable-noqa . Finally, if we have a particularly bad line of code, we can ignore every error using simply # noqa with nothing after it.
[flake8] per-file-ignores = # line too long path/to/file.py: E501, This may be easier than using # noqa comments.
Is there a way to make flake8 fix my code? no, flake8 is a linter only -- you'll want a code formatter to do code formatting (such as autopep8 / add-trailing-comma / yapf / black / etc.)
Flake8 is a Python library that wraps PyFlakes, pycodestyle and Ned Batchelder's McCabe script. It is a great toolkit for checking your code base against coding style (PEP8), programming errors (like “library imported but unused” and “Undefined name”) and to check cyclomatic complexity.
It looks like you can ignore by error code pattern, not just specific error codes, e.g. --ignore=E1,W
for all error codes beginning with E1 and W. Here's a list of current error codes you can use to specify the kind of errors you'd like to ignore.
I also wanted to disable aesthetic errors. I came up with a slightly different list of what to ignore; this is what I have in my setup.cfg
.
[flake8]
extend-ignore =
# Indentation — black handles
E1
W1
# Whitespace — black handles
E2
W2
# Blank lines — black handles
E3
W3
# Imports — isort handles
E4
W4
# Line length — black handles
E5
W5
# No lambdas — too strict
E731
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With