Search code examples
visual-studio-codepluginsflake8

How to make VSCode Flake8 extension to use the plugin "pep8-naming"?


By default, VSCode has stopped using project installed static analysis tool. Now it relies on VSCode Flake8 Extension for this functionality. The extension has its own Flake8 linter embedded.

While this change is understandable, I am unsure how to configure flake8 plugins under the new setup.

Previously, when using flake8 installed in my virtual environment, I only needed to install the pep8-naming plugin to enable it.

Now I'm using the Flake8 VSCode extension and its bundled package. How do I configure the pep8-naming plugin now that the VSCode extension handles all the static analysis?


Solution

  • You cannot simultaneously use plugins and the built-in Flake8 within the Microsoft Flake8 extension.

    To achieve this, you must install Flake8 and the desired plugin within your virtual environment and then configure VSCode Flake8 Extension to utilize them.

    Follow the steps below to use plugins:

    1. Within your virtual environment (venv), install flake8, pep8-naming, and any additional Flake8 compliant plugins you prefer. Include these in your development requirements file.

    2. In your settings.json, specify that the project will prefer to use the Flake8 installed in your environment with the following configuration: "flake8.importStrategy": "fromEnvironment", This setting instructs the system to look for an installed Flake8 in the venv. Beware, if Flake8 package isn't found, it will default to the built-in version, which does not include the plugins.

    Note: One drawback of this approach is that Flake8 operates more slowly when using the linter from the environment.

    For reference, see this discussion.