How can I make flake8 only detect errors?
Asked Answered
K

2

8

I use flake8 as python linter in vscode. I want flake8 to ignore all warning, but I can't find any option to detect error-only after searching flake8 documentation. So, how can I achieve this? Any help?

Krystinakrystle answered 21/8, 2020 at 5:4 Comment(0)
M
9

though flake8 has things that are marked "E" and "F" and "W" they don't stand for "error" / "failure" / "warning". these are codes for particular plugins ("E" / "W" are pycodestyle, "F" is pyflakes)

if you want to exclude a particular set of warnings, you'd use the --extend-ignore=X argument (or the --ignore=X argument, though the former is preferable since it doesn't reset the default set of ignores).

It's usually easier to set this in a flake8 configuration file (tox.ini / setup.cfg / .flake8) such that others can take advantage of this setting without needing to use your IDE-specific setting.

[flake8]
extend-ignore = X, Y, Z

If you know you only want a particular set of codes, you can also utilize --select

[flake8]
select = F,E

disclaimer: I am the current maintainer of flake8

Mary answered 21/8, 2020 at 16:10 Comment(11)
So there is no direct way to only detect errors since E does not mean error?Krystinakrystle
Yeah, it would be nice to easily switch off any "cosmetic" warnings as opposed to errors that will make the program fail :)Freeliving
What do you mean X, Y Z ?Janeejaneen
Is that particular error codes ? Or is that E, W, C ?Janeejaneen
I prefer the pylint system where E stands for Error, W for Warning, C for Convention, and R for refactor. And, you can ignore C,W,R so it only shows errors (and F codes, failures or something like that). It's much easier that way so you can fail linting only if there is a syntax or import error, for example, rather than trying to cherry-pick all the specific syntax and import errors from a huge list of codes.Dunderhead
@Dunderhead you're fine to have that opinion -- but that's not how things workMary
E is errors in pylint, like syntax and import errors that will cause code to fail. So if I only want to get code-crashing failures/errors from my linting, it doesn't seem easy to do with flake8. Or is there some way to do it with flake8 and/or pyflakes?Dunderhead
@Dunderhead my answer is short and addresses your questionMary
Yes, I think I get it. From a practical usability perspective it would be nice to have a list somewhere in the docs of all codes that are related to Exceptions, so that it could be used easily. Or an option to only include codes for exceptions. For example, I only want to block the CI process or pre-commit step if flake8 finds something that would cause an Exception, not simply a style issue or something like an unused import. F823 - local variable name … referenced before assignmentDunderhead
Or if someone had a good list of selects for CI, that would be helpful.Dunderhead
such a thing is intractable (and opinion based) -- flake8 is a plugin framework not just the things it includes out of the boxMary
A
0

Add following settings to settings.json:

Ankle answered 21/8, 2020 at 7:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.