Skip to content

Flake8 linter strange behaviour when running for whole project #1705

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
rampage644 opened this issue May 17, 2018 · 8 comments
Closed

Flake8 linter strange behaviour when running for whole project #1705

rampage644 opened this issue May 17, 2018 · 8 comments

Comments

@rampage644
Copy link

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 (ViewOutput, 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

@brettcannon
Copy link
Member

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 Linter as 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
Copy link
Author

@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 fake bla import).

Here are my open files:
2018-05-18-081111_504x40_scrot

And here is the problem tab view:
2018-05-18-081100_544x310_scrot

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
Copy link
Author

rampage644 commented May 18, 2018

It seems I can't reopen the issue by myself.

@rampage644
Copy link
Author

@brettcannon Could you please have a look and reopen?

@brettcannon
Copy link
Member

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
Copy link
Author

rampage644 commented May 24, 2018

@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
Copy link
Member

@rampage644 there's already an open issue for that I believe.

@rampage644
Copy link
Author

Thank you, @brettcannon

@lock lock bot locked as resolved and limited conversation to collaborators Jul 10, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants