Reputation: 129
For my setup, I have Pylint ==3.0.0a4 and VSCode Version: 1.67.2. In my VSCode settings.json, I have
"editor.formatOnSave": true,
"python.linting.enabled": true,
"python.linting.pylintEnabled": true,
and every time I save a .py file, VSCode runs the following command:
~/.local/share/virtualenvs/hello-world-n4ICiflw/bin/python ~/.vscode/extensions/ms-python.python-2022.6.2/pythonFiles/linter.py -m pylint ~/code/hello-world/src/main.py
which I believe is VSCode running the Python linter via a proxy call to linter.py -m pylint
using --output-format=json
by default, but it fails with the following error
##########Linting Output - pylint##########
[ERROR 2022-4-30 15:11:59.266]: Linter 'pylint' failed to parse the output '. [SyntaxError: Unexpected end of JSON input
at JSON.parse (<anonymous>)
at s.parseMessages (/Users/kevinyang/.vscode/extensions/ms-python.python-2022.6.2/out/client/extension.js:2:518074)
at s.run (/Users/kevinyang/.vscode/extensions/ms-python.python-2022.6.2/out/client/extension.js:2:499508)
at async s.runLinter (/Users/kevinyang/.vscode/extensions/ms-python.python-2022.6.2/out/client/extension.js:2:517589)]
It appears as though the linter.py
cannot handle the JSON output produced by pylint.
I also tried installing the Pylint Extension, but ran into the same problem.
Running $ pylint src/main.py
manually on a shell works just fine.
Has anybody else come across this problem and solved it?
Upvotes: 10
Views: 15160
Reputation: 4869
Add the below path setting in your .vscode/settings.json
.
And install pylint in your virtual environment with pip install pylint
{
"pylint.path": [
"${workspaceFolder}/.venv/python",
"-m",
"pylint"
]
}
Upvotes: 0
Reputation: 37973
Check the vscode setting for python.linting.pylintPath
. I was using Git Bash for Windows, and had python.linting.pylintPath
incorrectly set to /c/Python39/Scripts/pylint
. It didn't like the forward slashes.
I had to change it to c:\Python39\Scripts\pylint
. Or better yet, just leave the setting blank. vscode should be able to find the correct version itself.
Look at the vscode Output > Python window to see the error messages.
Upvotes: 0
Reputation: 321
The problem in my case:
Incorrect pylintrc file path configuration.
Troubleshooting:
Look at Output->Python logs
Try running the pylint command that is being used there:
pylint --rcfile=~/projects/../my_project/pylintrc ~/projects/../my_project/a_script_to_analyze.py
See the error (which is not a Json object, that's why you are getting this weird Json error):
"The config file /home/../my_projects/.pylintrc doesn't exist!"
Solution in my case: Modify your workspace settings to use a valid pylintrc file
"python.linting.pylintArgs": [
"--rcfile=${workspaceFolder}/pylintrc"
]
Upvotes: 3
Reputation: 129
Solved this by downgrading pylint to ==2.13.4. Seems like it's a known issue in recent versions of Pylint.
Upvotes: 2