-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Linting
#Linting Linting within the extension is supported on the following:
- Pylint (this is the default linter used)
- Pep8
- Flake8
- mypy
- pydocstyle
- prospector
###Paths
All samples provided here are for windows.
However Mac/Linux paths are also supported.
Note: You could enable all of the above linters if necessary. Or just one or two of them.
This can be achieved by enabling/disabling individual linters.
Linting as you type can be enabled by turning on the 'auto save' feature in Visual Studio Code..
Follow the instructions here to turn on auto save.
By default linting is enabled and uses pylint.
If you wish to turn this off, you could do so either in the User Settings or the Workspace Settings file.
Enabling/disabling could be done by configuring the following property in either one of (User or Workspace settings file) as follows:
"python.linting.enabled": true
The extension will run the linter when ever a file is saved.
This can easily be turned off, once again either within the User or Workspace Settings files with the following configuration change:
"python.linting.lintOnSave": false
###Maximum number of messages
The default maximum number of messages displayed in Visual Studio Code is limited to 100.
If this is to be altered, then change the following configuration settings either in the User or Workspace settings file:
"python.linting.maxNumberOfProblems": 50
###Pylint
As mentioned previously, this is the default linter used by the extension.
Installing Pylint
For this to work properly ensure pylint is installed locally.
You can easily install pylint as follows:
pip install pylint
Enabling/Disabling pylint
If the pylint linter is not to be used by the extension, then disable it as follows either in the User or Workspace settings file:
"python.linting.pylintEnabled": false
Custom Path
This is generally unnecessary. As the Extension will resolve the path to the formatter based on Python executable being used or configured in python.pythonPath of settings.json. If this cannot be found, then the formatter will be resolved based on the current environment Path settings.
If this is not the case or you wish to use another version of pylint, all you need to do is configure the path as follows either in the User or Workspace settings file:
"python.linting.pylintPath": "c:/customPath/pylint.exe"
Pylint Category Mapping
Messages generated by pylint fall into the following categories:
- convention, refactor, warning, error, fatal
Visual Studio Code supports the following categories in linting: - Hint, Error, Information, Warning
By default the extension maps pylint "convention" to "Hint", and so on.
These mappings can be altered either in the User or Workspace settings files as follows:
"python.linting.pylintCategorySeverity.convention": "Information"
Custom Configuration
You can customize the linter by providing a configuration file for pylint and placing it in the necessary location.
For instance you could place a pylintrc or .pylintrc file in the workspace folder.
For further details please refer Pylint Command Line Options
** Disabling (ignoring certain messages)**
- More information can be found here on How do I disable a Pylint warning? @ StackOverflow
- Create a file named
.pylintrc
in your root directory - Add the following contents:
[MESSAGES CONTROL]
# Enable the message, report, category or checker with the given id(s). You can
# either give multiple identifier separated by comma (,) or put this option
# multiple time.
#enable=
# Disable the message, report, category or checker with the given id(s). You
# can either give multiple identifier separated by comma (,) or put this option
# multiple time (only on the command line, not in the configuration file where
# it should appear only once).
#disable=
- Add the messages to be ignored in the disable section.
Pylint Plugins or custom arguments to PyLint
Custom plugins such as pylint plugin for Django can be easily used by modifying the User or Workspace settings as follows:
"python.linting.pylintArgs": ["--load-plugins", "pylint_django"]
###Pep8 As mentioned previously, usage of this linter is turned off by the extension.
Installing Pep8
For this to work properly ensure Pep8 is installed locally.
You can easily install pep8 as follows:
pip install pep8
Enabling/Disabling pep8 If the pep8 linter is to be used by the extension, then enable it as follows either in the User or Workspace settings file:
"python.linting.pep8Enabled": true
Custom Path This is generally unnecessary. As the Extension will resolve the path to the formatter based on Python executable being used or configured in python.pythonPath of settings.json. If this cannot be found, then the formatter will be resolved based on the current environment Path settings.
If this is not the case or you wish to use another version of pep8, all you need to do is configure the path as follows either in the User or Workspace settings file:
"python.linting.pep8Path": "c:/customPath/pep8.exe"
Custom Configuration
The options are read from the [pep8] section of the tox.ini file or the setup.cfg file located in any parent folder of the path(s) being processed.
For further details refer the following Options.
###Flake8 As mentioned previously, usage of this linter is turned off by the extension.
Installing Flake8
For this to work properly ensure Flake8 is installed locally.
You can easily install flake8 as follows:
pip install flake8
Enabling/Disabling flake8 If the flake8 linter is to be used by the extension, then enable it as follows either in the User or Workspace settings file:
"python.linting.flake8Enabled": true
Custom Path This is generally unnecessary. As the Extension will resolve the path to the formatter based on Python executable being used or configured in python.pythonPath of settings.json. If this cannot be found, then the formatter will be resolved based on the current environment Path settings.
If this is not the case or you wish to use another version of pep8, all you need to do is configure the path as follows either in the User or Workspace settings file:
"python.linting.flake8Path": "c:/customPath/flake8.exe"
Custom Configuration
The user settings are read from the ~/.config/flake8 file (or the ~/.flake8 file on Windows).
At the project level, a tox.ini file or a setup.cfg file is read if present. Only the first file is considered. If this file does not have a [flake8] section, no project specific configuration is loaded.
For further details refer Configuration.
###mypy As mentioned previously, usage of this linter is turned off by the extension.
Installing mypy
For this to work properly ensure mypy is installed locally.
You can easily install mypy as follows:
pip3 install mypy-lang
Enabling/Disabling mypy If the flake8 linter is to be used by the extension, then enable it as follows either in the User or Workspace settings file:
"python.linting.mypyEnabled": true
Custom Path This is generally unnecessary. As the Extension will resolve the path to the formatter based on Python executable being used or configured in python.pythonPath of settings.json. If this cannot be found, then the formatter will be resolved based on the current environment Path settings.
If this is not the case or you wish to use another version of mypy, all you need to do is configure the path as follows either in the User or Workspace settings file:
"python.linting.mypyPath": "c:/customPath/mypy.exe"
Custom Configuration Custom command line arguments can be passed into mypy just as with the other linters using the setting:
"python.linting.mypyArgs": []