Search code examples
visual-studio-codeflake8pycodestyle

How can I change the problem level of a specific pycodestyle error with the VS Code Python extension?


I am using Visual Studio Code, I am linting the code with flake8 and pycodestyle. I would like the line length error (E501) to be considered as a warning.

So far, the only thing that I could find was to ignore totally E501 with the solution found at this link. The solution was to edit the settings by ignoring totally the line length error:

{
    "python.linting.pycodestyleEnabled": true,
    "python.linting.pycodestyleArgs": [
        "--ignore=E501" 
    ]
}

However, it ignores completely the error. What I would like is to set E501 as a warning during the linting process.


Solution

  • From my very cursory understanding, I think you just can't. See also https://pycodestyle.pycqa.org/en/latest/intro.html#error-codes. From how the "E" and "W" are baked into the code names, it seems to me like pycodestyle itself doesn't allow changing the levels of various problems. I suppose it wouldn't be impossible for something like this to be implemented at the VS Code Python extension level- to allow configuring translation of problem levels, but from what I see, the only thing you can do currently is to change the VS Code problem level of all pycodestyle errors/warnings to a specific VS Code problem level together- not at the granularity of individual pycodestyle errors/warnings- using something like: "python.linting.pycodestyleCategorySeverity.E": "Warning".

    Possibly related though for Pyright things is the pyrightconfig.json file, which VS Code's Python extension has support for. You can change the problem levels of things on a case-by-case basis using that. See also the pylint.severity setting for Pylint things.