Repository navigation
Flake8 linter strange behaviour when running for whole project #1705
Description
I have a project with a virtualenv (within a home directory, outside of project root) and want to use flake8 linter. Unfortunately, collected problems look to have messed/lost file information.
I use "Python - Run linter" command to run the linter and it outlines all the problems for each (it looks like) open file. Moreover, for each file it lists all the errors causing lots of false positives.
Example, there are two open files: file1.py and file2.py, they both contain lint errors. "Problems" tab will show all errors for each file. Clearly, file1.py shouldn't have the error from file2.py and vice versa.
The behaviour is changed if flake8Args are dropped (because they specify folder to run against).
Workspace settings:
{
"python.pythonPath": "/home/ramp/.venv/cash-out-gate/bin/python",
"python.linting.enabled": true,
"python.linting.lintOnSave": true,
"python.linting.flake8Enabled": true,
"python.linting.flake8Args": [
"cash_out_gate", "tests"
],
"python.linting.pylintEnabled": false,
"python.linting.pylintArgs": [
"--load-plugins", "pylint_quotes",
"cash_out_gate", "tests"
],
"python.linting.mypyEnabled": false,
"python.linting.mypyArgs": [
"--config", "mypy.ini",
"cash_out_gate", "tests"
],
}Environment data
- VS Code version: 1.23.0
- Extension version (available under the Extensions sidebar): 2018.4.0
- OS and version: archlinux 4.16.7-1-ARCH 1228 multi root master #1 SMP
- Python version (& distribution if applicable, e.g. Anaconda): 3.6.5
- Type of virtual environment used (N/A | venv | virtualenv | conda | ...): virtualenv
- Relevant/affected Python packages and their versions: N/A
Actual behavior
All errors are collected and each open file in "Problems" tab lists them all. Clicking on some errors won't necessary navigate to the error.
Expected behavior
All errors are collected and each problematic file in "Problems" tab lists only its errors. Clicking on an error navigate to the corresponding line.
Steps to reproduce:
Open some project with "File: Open folder", use workspace settings from the example above, introduce some errors and perform a lint operation with "Run linter".
Logs
Output for Python in the Output panel (View→Output, change the drop-down the upper-right of the Output panel to Python)
I have 5 files opened (hence five linting output sections)
##########Linting Output - flake8##########
2,1,F,F401:'django.conf.settings' imported but unused
32,1,W,W391:blank line at end of file
7,32,C,C812:missing trailing comma
##########Linting Output - flake8##########
2,1,F,F401:'django.conf.settings' imported but unused
32,1,W,W391:blank line at end of file
7,32,C,C812:missing trailing comma
2,1,F,F401:'django.conf.settings' imported but unused
##########Linting Output - flake8##########
2,1,F,F401:'django.conf.settings' imported but unused
32,1,W,W391:blank line at end of file
7,32,C,C812:missing trailing comma
7,32,C,C812:missing trailing comma
##########Linting Output - flake8##########
2,1,F,F401:'django.conf.settings' imported but unused
32,1,W,W391:blank line at end of file
7,32,C,C812:missing trailing comma
##########Linting Output - flake8##########
2,1,F,F401:'django.conf.settings' imported but unused
32,1,W,W391:blank line at end of file
7,32,C,C812:missing trailing comma
Output from Console under the Developer Tools panel (toggle Developer Tools on under Help)
No output
Activity
brettcannon commentedon May 17, 2018
If I'm understanding this, your issue is that you don't want problems output for all files when viewing a single file? If that's the case then the solution is to simply not use
Run Linteras that is specifically provided to run the linter over all your files. If you only want to lint the file you have open then you can just wait for it to run on save.If I am misunderstanding what your issue is then please let me know.
rampage644 commentedon May 18, 2018
Brett Cannon (@brettcannon) Thank you for the reply.
I want to run over all files (btw, how does it know what files to run? I'm specifying directories in the
flake8Args).Here is an experiment: I've modified this line in file
test_utils.py:from cash_out_gate.apps.payments.utils import generate_otp, bla(adding fakeblaimport).Here are my open files:

And here is the problem tab view:

Please note the lint error appears under all files and for correct file it appears twice. Clicking on the error on wrong files gets you to incorrect place (since those files don't have that problem).
Another thing I've noticed is that once VS Code is just launched and files are restored from the previous session, only those files that were visited (I have to click/view them manually) participate in the issue described.
rampage644 commentedon May 18, 2018
It seems I can't reopen the issue by myself.
rampage644 commentedon May 21, 2018
Brett Cannon (@brettcannon) Could you please have a look and reopen?
brettcannon commentedon May 23, 2018
You shouldn't be specifying the directories for flake8 to run against in your configuration. We handle that for you based on what's in your workspace folder. That's probably what's tripping up the extension.
rampage644 commentedon May 24, 2018
Brett Cannon (@brettcannon) You're right. Specifying folders for flake was the issue.
Now -- it runs lint for opened files only vs. full project. Is there a way to run against all files, not necessarily open? Should I open another issue or there is just not an option yet?
brettcannon commentedon May 24, 2018
Sergei Turukin (@rampage644) there's already an open issue for that I believe.
rampage644 commentedon May 25, 2018
Thank you, Brett Cannon (@brettcannon)