Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

flake8 not showing fatal erros in vscode

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?

like image 498
Raphael Philipe Avatar asked Jul 23 '19 16:07

Raphael Philipe


People also ask

How do I use flake8 on VSCode?

ctrl + shift + p. write "select linter" then click on it. click on flake8.

How do I fix Visual Studio code lint issues?

Go to File > Preferences > Settings (or Code > Preferences > Settings). Then click settings. json . Now, undo the fixes you made to the JavaScript file you created earlier.


1 Answers

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.

like image 197
Gino Mempin Avatar answered Sep 24 '22 10:09

Gino Mempin