Search code examples
pythonvisual-studio-codeflake8

Flake8 on VSCODE not highlighting errors


Simply make a file called test.py with following code:

print(x)    

Running flake8 test.py shows the errors as expected:

test.py:1:7: F821 undefined name 'x'   

Yet in VSCODE, nothing is being highlighted! Even on saving, it acts like everything is normal. How can I fix this?

My relevant settings:

{
    "editor.tabSize": 2,
    "editor.rulers": [
        88
    ],
    "sync.gist": "c39568aa1fdffb072eb23bbdcbb26f08",
    "git.autofetch": true,
    "workbench.editor.enablePreview": false,
    "workbench.editorAssociations": [
        {
            "viewType": "jupyter.notebook.ipynb",
            "filenamePattern": "*.ipynb"
        }
    ],
    "python.testing.pytestEnabled": true,
    "editor.formatOnSave": true,
    "python.formatting.provider": "black",
    "kite.showWelcomeNotificationOnStartup": false,
    "python.defaultInterpreterPath": "C:\\Python\\Python39\\python.exe",
    "python.linting.flake8Enabled": true,
    "[json]": {
        "editor.quickSuggestions": {
            "strings": true
        },
        "editor.suggest.insertMode": "replace"
    },
    "python.linting.flake8Args": [
        "--ignore=E203",
        "--ignore=E266",
        "--ignore=E501",
        "--ignore=W503",
        "--max-line-length=88",
        "--select = B,C,E,F,W,T4,B9",
        "--max-complexity = 18"
    ],
    "workbench.colorTheme": "Material Theme Darker",
    "workbench.iconTheme": "eq-material-theme-icons-darker",
    "terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe",
    "terminal.integrated.shellArgs.windows": [
        "--login"
    ],
    "python.linting.flake8CategorySeverity.F": "Error",
    "python.linting.flake8CategorySeverity.E": "Error",
    "python.linting.flake8Path": "C:\\Users\\panda\\Documents\\classrosterbot\\crb2\\Scripts\\flake8"
}

Solution

  • your --ignore, --select, and --max-complexity options are malformed

    I believe you want this:

        "python.linting.flake8Args": [
            "--extend-ignore=E203,E266,E501,W503",
            "--max-line-length=88",
            "--select=B,C,E,F,W,T4,B9",
            "--max-complexity=18"
        ],
    

    with --ignore, the last one will win -- with spaces it will not be parsed properly

    it's also usually better to specify these in the configuration file and not in your editor settings such that other tools and contributors can benefit without having to choose your IDE


    disclaimer: I'm the current flake8 maintainer