Descriptive flake8 errors in PyCharm

前端 未结 4 746
太阳男子
太阳男子 2021-02-02 12:52

PyCharm does not have a built-in support for flake8 at the moment. But, flake8 can be configured to run as an external tool.

Sometimes, especia

4条回答
  •  忘掉有多难
    2021-02-02 13:30

    It is definitely possible.

    One approach would be to adjust the flake8 output using the --format command-line option to specify http(s) links to the Flake8Rules catalog:

    --format='%(path)s:%(row)d,%(col)d:%(code)s:%(text)s:https://lintlyci.github.io/Flake8Rules/rules/%(code)s.html'
    

    The problem then is for the console or PyCharm output window to render the links properly.

    Fortunately, we can do that using the plugins - "Awesome Console" for the terminal and "Console Link" for the output window.


    ##Step-by-step Instructions

    1. make sure to have flake8 installed in the current Python environment
    2. install "Awesome Console" plugin:
    • go to PyCharm Preferences -> Plugins -> Browser Repositories...
    • find "Awesome Console" and install (PyCharm restart required):
    1. configure "flake8" as an External Tool:
    • go to PyCharm Preferences -> Tools -> External Tools -> "+"
    • configure the path to flake8 as well as $FilePath$ placeholder for the desired directory/path to be processed:

    ##Demo

    Now, let's say we have created this test.py file with a few violations:

    def f(a = 10):
      return a*10
    

    If we right-click on a test.py file, select External Tools -> flake8, this is the output we are going to get (note the clickable links for every warning):

    Now, whenever in doubt, we can follow the link for additional details about a warning.

    This is just one way to do it, would be happy to hear if there is an easier or better way to combine these tools and projects.

提交回复
热议问题