flake8 not showing fatal erros in vscode
Asked Answered
S

2

8

Vscode is not showing fatal erros in vscode. It is only highlighting warnings in the code. Example:

I have vscode running flake8 from a virtualenv with python 2.7. The settings is as following:

"python.linting.flake8Enabled": true,

I'm comparing the results from vscode "problems" window with the results of running flake8 directly from the command line.

def foo(bar):
    o += 1

    print(bar)

When I run flake8 from the command line on the code above, I get all linting errors and warnings,

> flake8 python/mock.py 
python/mock.py:4:5: F821 undefined name 'o'
python/mock.py:4:5: F841 local variable 'o' is assigned to but never used
python/mock.py:5:1: W293 blank line contains whitespace

while when I lint this code in vscode, I only getting the warnings.

blank line contains whitespace flake8(W293) [5,1]

Am I missing something in the configuration? Is there a way to check how flake8 is being called by vscode?

Stomatal answered 23/7, 2019 at 16:37 Comment(1)
It turns out that the problem was the version of flake8. Using the latest version was not working, so I explicitly set to use flake8==3.5 and then it started working as expected.Stomatal
C
3

The default configuration works for me (also with Python2.7 on virtualenv).

flake8

Check that:

  • The path to the flake8 executable is explicitly specified in settings.json

    # From terminal/console, install flake8 into your virtual environment
    $ pipenv install --dev flake8
    $ which flake8
    /absolute/path/to/virtualenvs/test-v9MbxBL-/bin/flake8
    
    # Set in settings.json
    "python.linting.flake8Path": "/absolute/path/to/virtualenvs/test-v9MbxBL-/bin/flake8",
    
  • The severity for Fatal and Error categories are set to "Error":

    "python.linting.flake8CategorySeverity.F": "Error",
    "python.linting.flake8CategorySeverity.E": "Error",
    
  • There are no ignored errors:

    "python.linting.flake8Args": [
        "--ignore=F821"
    ]
    
  • There are no overriding flake8 settings from external sources

    Flake8 user options are read from the C:\Users\<username>\.flake8 (Windows) or ~/.config/flake8 (macOS/Linux) file.

    At the project level, options are read from the [flake8] section of a tox.ini, setup.cfg, or .flake8 file.

Certie answered 24/7, 2019 at 13:9 Comment(1)
manually specifying the path to flake8 in settings.json worked for meLamentable
I
0

Usually yeah it will. But if it doesn't work for you, then you can try specifying absolute path to flake8 and enable it explicitly like so :

"python.linting.flake8Enabled": true,  
"python.linting.flake8Path": "path/to/flake8",

you can even specify path to your conda environment :

"python.condaPath": "path/to/condaenv/",
Invariant answered 9/1, 2021 at 3:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.