TL;DR Using WSL and VSCode I had to change settings.json
{
// whatever I had in settings json before plus:
"python.linting.pylintArgs": [
"--rcfile", "~/projects/my-project/.pylintrc"
]
}
and then
pylint --generate-rcfile > .pylintrc
and then I could add for example missing-function-docstring
to my disables
.
The full story:
I wanted the default VSCode pylinting in my code base for version control, and to be able to ignore specific errors.
I had so much trouble getting this to work because there are no errors if you specify the wrong path for --rcfile
it just doesn't lint. And Ctrl-Shift-P -> Run linter
doesn't seem to work so I had to restart VSCode everytime to check if it was working. Anyway, I finally got it working.
Here's what I had to do running VSCode on files on WSL:
- Similar to the top voted answer, I added
python.linting.pylintArgs
to settings.json (Ctrl-Shift-P
-> Preferences: Open User Settings (JSON)
)
"python.linting.pylintArgs": [
"--rcfile", "~/projects/my-project/.pylintrc"
]
Examples of what didn't work as a path and silently errored: \\wsl$\Debian\home\matthias\projects\my-project\.pylintrc
and \\\\wsl$\\Debian\\home\\matthias\\projects\\my-project\\.pylintrc
- I had to realize .pylintrc files are not json but config file format, something like
[MASTER]
# A comma-separated list of package or module names from where C extensions may
# be loaded. Extensions are loading into the active Python interpreter and may
# run arbitrary code.
extension-pkg-whitelist=
# Specify a score threshold to be exceeded before program exits with error.
fail-under=10.0
# Add files or directories to the blacklist. They should be base names, not
# paths.
ignore=CVS
...
Then I found some .pylint file online (and if there's an error it just silently doesn't work), but even though it did work it didn't have the options that come default with VSCode, so I had to follow the instructions here and install pylint
(sudo apt install pylint
) and open a terminal in VScode and run
~/projects/my-project$ pylint --generate-rcfile > .pylintrc
Then I can add specific errors to the disable line in [MESSAGES]
.
Lessons I learned later:
- It is enough to close and reopen the file to get the linting going again.
Extra information:
- If you don't care about having the
.pylintrc
file in version control, you can also disable rules directly in the settings.json file, e.g.
"python.linting.pylintArgs": [
"--disable", "C0116"
]
pylintrc
(without the dot) is automatically detected by VS Code as well – Inevasible