pythonvisual-studio-codeflake8

In VS Code, how can I change the problem level of a certain error/violation from the Flake8 extension?


I'm using VS Code with Flake8 configured to check some obvious issues for my Python code. However, some of its errors are not really errors in my current development phase, e.g. E501 (line too long) and F401 (unused import).

The annoying thing is that the relevant lines are marked in red, which makes more serious errors non-obvious.

Is there a way I can tell Flake8 to treat them as warnings instead of errors?

I searched all over, but only discovered ways to either ignore the check all together, or explicitly mark one line as ignored, e.g. How to tell flake8 to ignore comments. They are not what I need.


Solution

  • Use the flake8.severity setting contributed by the Flake8 extension. See https://github.com/microsoft/vscode-flake8#settings.

    Quoting from the docs, the default value is:

    {
      "convention": "Information",
      "error": "Error",
      "fatal": "Error",
      "refactor": "Hint",
      "warning": "Warning",
      "info": "Information"
    }
    

    The description in the docs is:

    Controls mapping of severity from flake8 to VS Code severity when displaying in the problems window. You can override specific flake8 error codes

    {
      "convention": "Information",
      "error": "Error",
      "fatal": "Error",
      "refactor": "Hint",
      "warning": "Warning",
      "W0611": "Error",
      "undefined-variable": "Warning"
    }
    

    Pay particular attention to the property W0611 in that example above. See also https://flake8.pycqa.org/en/latest/user/error-codes.html.

    Since Flake8 uses other plugins, you'll need to refer to the readmes and docs of those plugins to find out what error codes they provide (I think Flake8 mostly just uses them without any sort of translation):