Skip to content
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

Flake8 extensions/plugin (black, rst-docstrings, and other) entries not reported by vscode #4074

Closed
jraygauthier opened this issue Jan 22, 2019 · 16 comments
Assignees
Labels
area-editor-* User-facing catch-all area-linting feature-request Request for new features or functionality verification-needed Verification of issue is requested verified Verification succeeded
Milestone

Comments

@jraygauthier
Copy link

Environment data

  • VS Code version: 1.26.1
  • Extension version (available under the Extensions sidebar): 2018.7.0
  • OS and version: nixos 18.03.git.ccea532 (Impala)
  • Python version (& distribution if applicable, e.g. Anaconda): Python 3.6.6
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): nix
  • Relevant/affected Python packages and their versions: None

Expected behaviour

Given the following mymodule.py file:

from collections import \
    namedtuple, \
    deque

class ControlAlgoCoreSimpleSlots:
    """My non pydocstring compliant
    summary which should make `flake8-docstrings` bark.

    Here's some markdown code block (non valid sphinx syntax
    which should make `flake8-rst-docstrings` bark.

    ```
    def my_blocking_closure_fn():
        return long_blocking_call_on(my_argument_data)
    return self.make_blocking_job(my_blocking_closure_fn)
    ```
    """
    pass

which when linted with flake8 and its plugins (see below for details) gives:

$ flake8 '--format=%(row)d,%(col)d,%(code).1s,%(code)s:%(text)s' ./mymodule.py
1,1,F,F401:'collections.namedtuple' imported but unused
1,1,F,F401:'collections.deque' imported but unused
1,1,D,D100:Missing docstring in public module
1,25,B,BLK100:Black would make changes.
5,1,E,E302:expected 2 blank lines, found 1
6,1,D,D204:1 blank line required after class docstring
6,1,D,D205:1 blank line required between summary line and description
6,1,D,D400:First line should end with a period
12,1,R,RST299:Inline literal start-string without end-string.
14,1,R,RST301:Unexpected indentation.
15,1,R,RST201:Block quote ends without a blank line; unexpected unindent.
15,1,R,RST299:Inline literal start-string without end-string.
15,1,R,RST299:Inline interpreted text or phrase reference start-string without end-string.

I would expect to get the same list of issue in vscode.

Note that the format string used is the same as the one used by vscode-python/src/client/linters/flake8.ts to run flake8.

Actual behaviour

Instead, I get:

image

See that none of the BLK entries from the flake8-black plugin are present, nor any RST entries from the flake8-rst-docstrings plugin. However, the D entries from the flake8-docstrings are properly reported.

The problem is with code prefix of more than a single alphabetical character.

Steps to reproduce:

Make sure you launch vscode in an environement with flake8 installed and the following flake8 plugins:

  • flake8-black
  • flake8-docstrings
  • flake8-rst-docstrings

Make sure vscode has flake8 linter active and global linting:

"python.linting.enabled": true,
"python.linting.lintOnSave": true,
"python.linting.flake8Enabled": true,
"python.linting.flake8Path": "flake8",

Launch Python: Run Linting on the provided mymodule.py module. Look at the Problems listing in vscode.

Logs

Output for Python in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Python)

##########Linting Output - flake8##########
1,1,F,F401:'collections.namedtuple' imported but unused
1,1,F,F401:'collections.deque' imported but unused
1,1,D,D100:Missing docstring in public module
1,25,B,BLK100:Black would make changes.
5,1,E,E302:expected 2 blank lines, found 1
6,1,D,D204:1 blank line required after class docstring
6,1,D,D205:1 blank line required between summary line and description
6,1,D,D400:First line should end with a period
12,1,R,RST299:Inline literal start-string without end-string.
14,1,R,RST301:Unexpected indentation.
15,1,R,RST201:Block quote ends without a blank line; unexpected unindent.
15,1,R,RST299:Inline literal start-string without end-string.
15,1,R,RST299:Inline interpreted text or phrase reference start-string without end-string.

Output from Console under the Developer Tools panel (toggle Developer Tools on under Help; turn on source maps to make any tracebacks be useful by running Enable source map support for extension debugging)

Console is empty after performing the linting action. I'm not sure about this source map thing however:

Suggested fix

In vscode-python/src/client/linters/baseLinter.ts, change REGEX from:

const REGEX = '(?<line>\\d+),(?<column>-?\\d+),(?<type>\\w+),(?<code>\\w\\d+):(?<message>.*)\\r?(\\n|$)';

which matches only codes with a single alphabetic character

to

const REGEX = '(?<line>\\d+),(?<column>-?\\d+),(?<type>\\w+),(?<code>\\w+\\d+):(?<message>.*)\\r?(\\n|$)';

which should now match codes with more that a single alphabetic character.

@ghost ghost added the triage-needed Needs assignment to the proper sub-team label Jan 22, 2019
@jraygauthier
Copy link
Author

jraygauthier commented Jan 22, 2019

Note that as this regexp is not specific to the flake8.ts module but in the baseLinter.ts module, other linters might be affected by the same issue.

@d3r3kk
Copy link

d3r3kk commented Jan 22, 2019

You can configure the arguments you wish to use in the "python.linting.flake8Args" setting in your workspace, please see our documentation on linting.

@d3r3kk d3r3kk closed this as completed Jan 22, 2019
@ghost ghost removed the triage-needed Needs assignment to the proper sub-team label Jan 22, 2019
@jraygauthier
Copy link
Author

jraygauthier commented Jan 22, 2019

@d3r3kk: Please provide an example of what you suggest because the possibility of customizing flake argument won't allow me to get my extension issues listing in the vscode PROBLEMS tab. The issue is with an hardcoded regexpr in the vscode extension's codebase which couldn't be customized via a flake argument. I specifically listed the problematic module and gave a possible solution.

@DonJayamanne DonJayamanne reopened this Jan 23, 2019
@ghost ghost added the triage-needed Needs assignment to the proper sub-team label Jan 23, 2019
@DonJayamanne DonJayamanne added feature-request Request for new features or functionality needs PR labels Jan 23, 2019
@ghost ghost removed the triage-needed Needs assignment to the proper sub-team label Jan 23, 2019
@DonJayamanne DonJayamanne added area-linting triage-needed Needs assignment to the proper sub-team labels Jan 23, 2019
@ghost ghost removed the triage-needed Needs assignment to the proper sub-team label Jan 23, 2019
@peterjc
Copy link

peterjc commented Feb 19, 2019

This reflects a change in flake8 v3, http://flake8.pycqa.org/en/latest/plugin-development/registering-plugins.html

Please Note: Your entry point does not need to be exactly 4 characters as of Flake8 3.0. Consider using an entry point with 3 letters followed by 3 numbers (i.e. ABC123 ).

The original convention of a single letter and three numbers had lead to a number of flake8 plugin codes clashing.

(Commenting as the author of two of the flake8 plugins mentioned - nice to see them being used)

@peterjc
Copy link

peterjc commented Feb 19, 2019

Since the triage seems to want this as a pull request, I turned @jraygauthier's sensible suggestion into PR #4443.

Update: I closed the PR, the process was more involved than I expected.

@jraygauthier
Copy link
Author

@peterjc thanks for the PR. Can I help in any way to re-open the PR? I yield any copyright on the suggested change (if any).

@peterjc
Copy link

peterjc commented Feb 21, 2019

@jraygauthier probably simplest to make a new pull request yourself, and if possible do this at home outside of work hours (to avoid the awkward question about if you have your employer's permission to give Microsoft the legal permissions they want).

On the technical side, you need to commit the fix itself in src/client/linters/baseLinter.ts, and they want you to include a short description of the work for their news summary in a file named news/2 Fixes/4443.md (because you are fixing issue 4443).

@jraygauthier
Copy link
Author

Alright, will try to take some time to do this.

@FraBle
Copy link

FraBle commented Aug 13, 2019

FYI: This also applies to wemake-python-styleguide.
The custom warnings for code complexity are not displayed in VS Code, but are visible on the Output for Python.

@adam-grant-hendry
Copy link

Has this issue been resolved? I am experiencing this problem as well:

VSCode: 1.67.0
OS: Windows x64 10
Python: 3.8.10
flake8: 4.0.1

@adam-grant-hendry
Copy link

Has this issue been resolved? I am experiencing this problem as well:

VSCode: 1.67.0
OS: Windows x64 10
Python: 3.8.10
flake8: 4.0.1

The REGEX fix still does not appear to fix the problem.

@adam-grant-hendry
Copy link

The `REGEX` fix still does not appear to fix the problem.

False alarm, apologies. I improperly typed my workspace folder variable as ${workspacefolder} instead of ${workspaceFolder} (capital F). Silly mistake. I didn't get an error that vscode-python couldn't find flake8.exe, so I assumed the path was fine (until I checked the Output tab).

I can confirm the REGEX fix solves the problem for me.

@adam-grant-hendry
Copy link

I didn't get an error that vscode-python couldn't find flake8.exe, so I assumed the path was fine (until I checked the Output tab).

FYI, in my case, the OUTPUT tab showed

.\.venv\Scripts\python.exe ~\.vscode\extensions\ms-python.python-2022.6.0\pythonFiles\linter.py -p flake8 ${workspacefolder}/Scripts/flake8.exe the_file.py

and flake8 failed silently.

@karrtikr
Copy link

karrtikr commented May 6, 2022

@adam-grant-hendry Can you open a separate issue for "and flake8 failed silently.", we would like to know more details about it.

Also seems like the original bug in the issue was fixed by #6925 but we forgot to close it?

@jraygauthier
Copy link
Author

I confirm this is now fixed:

image

Closing the issue.

@karrtikr karrtikr self-assigned this May 6, 2022
@karrtikr karrtikr added the verified Verification succeeded label May 6, 2022
@karrtikr karrtikr added this to the May 2022 milestone May 6, 2022
@adam-grant-hendry
Copy link

@karrtikr Yes, of course. Please see #19086 .

@joaomoreno joaomoreno added the verification-needed Verification of issue is requested label Jun 1, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 2, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-editor-* User-facing catch-all area-linting feature-request Request for new features or functionality verification-needed Verification of issue is requested verified Verification succeeded
Projects
None yet
Development

No branches or pull requests

9 participants