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?

Spaceship222
  • 759
  • 10
  • 20

2 Answers2

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

anthony sottile
  • 61,815
  • 15
  • 148
  • 207
  • So there is no direct way to only detect errors since `E` does not mean error? – Spaceship222 Aug 23 '20 at 03:44
  • 3
    Yeah, it would be nice to easily switch off any "cosmetic" warnings as opposed to errors that will make the program fail :) – smcs Nov 19 '20 at 18:51
  • What do you mean X, Y Z ? – John Smith Optional May 23 '22 at 11:18
  • Is that particular error codes ? Or is that E, W, C ? – John Smith Optional May 23 '22 at 11:18
  • 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. – wordsforthewise Nov 01 '22 at 09:00
  • @wordsforthewise you're fine to have that opinion -- but that's not how things work – anthony sottile Nov 01 '22 at 14:38
  • 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? – wordsforthewise Nov 02 '22 at 10:20
  • @wordsforthewise my answer is short and addresses your question – anthony sottile Nov 02 '22 at 13:27
  • 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 assignment – wordsforthewise Nov 03 '22 at 14:01
  • Or if someone had a good list of selects for CI, that would be helpful. – wordsforthewise Nov 03 '22 at 14:05
  • such a thing is intractable (and opinion based) -- flake8 is a plugin framework not just the things it includes out of the box – anthony sottile Nov 03 '22 at 18:12
0

Add following settings to settings.json:

Dauren Akilbekov
  • 4,627
  • 2
  • 27
  • 32