microsoft / vscode-flake8

Linting support for python using the flake8 library.
https://marketplace.visualstudio.com/items?itemName=ms-python.flake8
MIT License
40 stars 30 forks source link
flake8 python visual-studio-code

Flake8 extension for Visual Studio Code

A Visual Studio Code extension with support for the Flake8 linter. The extension ships with flake8==7.1.0.

Note: The minimum version of Flake8 this extension supports is 5.0.0. If you are having issues with Flake8, please report it to this issue tracker as this extension is just a wrapper around Flake8.

This extension supports all actively supported versions of the Python language (i.e., Python >= 3.8).

For more information on Flake8, see https://flake8.pycqa.org/

Usage and Features

The Flake8 extension provides features to improve your productivity while working on Python code in Visual Studio Code. Check out the Settings section below for more details on how to customize the extension.

Disabling Flake8

You can skip linting with Flake8 for specific files or directories by setting the flake8.ignorePatterns setting.

If you wish to disable linting with Flake8 for your entire workspace or globally, you can disable this extension in Visual Studio Code. Alternatively, you can also disable Flake8 for your entire workspace by setting "flake8.enabled" : false in your settings.json file.

Settings

There are several settings you can configure to customize the behavior of this extension.

Settings Default Description
flake8.args [] Arguments passed to Flake8 for linting Python files. Each argument should be provided as a separate string in the array.
Example: "flake8.args": ["--config="]
flake8.cwd ${workspaceFolder} Sets the current working directory used to lint Python files with Flake8. By default, it uses the root directory of the workspace ${workspaceFolder}. You can set it to ${fileDirname} to use the parent folder of the file being linted as the working directory for Flake8.
flake8.severity { "convention": "Information", "error": "Error", "fatal": "Error", "refactor": "Hint", "warning": "Warning", "info": "Information" } Mapping of Flake8's message types to VS Code's diagnostic severity levels as displayed in the Problems window. You can also use it to override specific Flake8 error codes.
Example: { "convention": "Information", "error": "Error", "fatal": "Error", "refactor": "Hint", "warning": "Warning", "W0611": "Error", "undefined-variable": "Warning" }
flake8.path [] "Path or command to be used by the extension to lint Python files with Flake8. Accepts an array of a single or multiple strings. If passing a command, each argument should be provided as a separate string in the array. If set to ["flake8"], it will use the version of Flake8 available in the PATH environment variable.
Note: Using this option may slowdown linting.
Examples:
- "flake8.path" : ["~/global_env/flake8"]
- "flake8.path" : ["conda", "run", "-n", "lint_env", "python", "-m", "flake8"]
- "flake8.path" : ["flake8"]
- "flake8.path" : ["${interpreter}", "-m", "flake8"]
flake8.interpreter [] Path to a Python executable or a command that will be used to launch the Flake8 server and any subprocess. Accepts an array of a single or multiple strings. When set to [], the extension will use the path to the selected Python interpreter. If passing a command, each argument should be provided as a separate string in the array.
flake8.importStrategy useBundled Defines which Flake8 binary to be used to lint Python files. When set to useBundled, the extension will use the Flake8 binary that is shipped with the extension. When set to fromEnvironment, the extension will attempt to use the Flake8 binary and all dependencies that are available in the currently selected environment.
Note: If the extension can't find a valid Flake8 binary in the selected environment, it will fallback to using the Flake8 binary that is shipped with the extension. This setting will be overriden if flake8.path is set.
flake8.showNotification off Controls when notifications are shown by this extension. Accepted values are onError, onWarning, always and off.
flake8.ignorePatterns [] Configure [glob patterns](https://docs.python.org/3/library/fnmatch.html) as supported by the fnmatch Python library to exclude files or folders from being linted with Flake8.
flake8.enabled true Specifies whether to enable or disable linting Python files using Flake8. This setting can be applied globally or at the workspace level. If disabled, the linting server itself will continue to be active and monitor read and write events, but it won't perform linting or expose Code Actions.

The following variables are supported for substitution in the flake8.args, flake8.cwd, flake8.path, flake8.interpreter and flake8.ignorePatterns settings:

The flake8.path setting also supports the ${interpreter} variable as one of the entries of the array. This variable is subtituted based on the value of the flake8.interpreter setting.

Commands

Command Description
Flake8: Restart Server Force re-start the linter server.

Logging

From the Command Palette (View > Command Palette ...), run the Developer: Set Log Level... command. Select Flake8 from the Extension logs group. Then select the log level you want to set.

Alternatively, you can set the flake8.trace.server setting to verbose to get more detailed logs from the Flake8 server. This can be helpful when filing bug reports.

To open the logs, click on the language status icon ({}) on the bottom right of the Status bar, next to the Python language mode. Locate the Flake8 entry and select Open logs.

Troubleshooting

In this section, you will find some common issues you might encounter and how to resolve them. If you are experiencing any issues that are not covered here, please file an issue.