Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flake8 disable all formatting rules

I use flake8 for linting and black for formatting.

flake8 produces warnings on execution rules and formatting rules:

enter image description here

I only want to see execution rules. I don't care about formatting rules because they'll automatically get fixed by black formatting:

enter image description here

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
like image 805
Brian Malehorn Avatar asked Dec 08 '19 23:12

Brian Malehorn


People also ask

How do I turn off flake8 rule?

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.

How do I ignore E501 in flake8?

[flake8] per-file-ignores = # line too long path/to/file.py: E501, This may be easier than using # noqa comments.

Can flake8 fix errors?

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.)

What is a flake8 file?

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.


2 Answers

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.

like image 175
xc938 Avatar answered Sep 21 '22 09:09

xc938


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
like image 44
Maximilian Avatar answered Sep 23 '22 09:09

Maximilian