Search code examples
pythonvisual-studio-codeflake8

How to make sure vscode-python properly display linter entries from `flake8-rst-docstrings` and/or `flake8-black` flake8 extensions?


Contrary to some other flake8 extensions (e.g.: flake8-rst-docstrings), flake8-rst-docstrings and flake8-black output codes with a 3 alphabetic characters instead of 1 (RST299 and BLK100 vs D204) which seems to prevent vscode-python from displaying these entries in vscode's PROBLEMS tab.

For the following snippet:

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

flake8 reports:

$ 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.

while vscode is missing the RST and BLK entries. Please refer to vscode-python/issues/4074 for an image of vscode output as I am not allowed to post it here.

I politely reported vscode-python/issues/4074 on vscode-python, however this d3r3kk guy immediately and abruptly closed the issue referring to flake8 linting documentation for vscode without any concrete solution to my problem.

Can anyone help me setup vscode-python so that I can get all my linter entries, including those from flake8-rst-docstrings and flake8-black ?


Solution

  • You are absolutely right with https://github.com/Microsoft/vscode-python/issues/4074 - this is a bug in vscode, and your fix looks sensible. I've commented there too.

    The longer codes 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.

    Disclosure: Author of flake8-rst-docstrings and flake8-black - thanks for trying them! https://github.com/peterjc/flake8-rst-docstrings https://github.com/peterjc/flake8-black