'Real-time linting of Python with VSCode

Recently I'm using VSCode as my Python IDE, and I install DonJayamanne/pythonVSCode, which supports linting. However, the linter only works when saving, but what I want is real-time linting. The workaround suggested by the author is to set files.autoSave to on, so that the linter will work whenever the file is automatically saved. There's a relevant discussion on Github, for your reference.

Since I don't want to turn on auto-save function, is there any way to do real-time linting of Python with VSCode? Or is there any suggested extension?



Solution 1:[1]

If you use shift + cmd + P (or ^+ctrl+P for windows) or go to View > Command Palette and type "Lint"

The Command Palette allows you to execute different commands, from here you can enable/disable Linting and select which Linter you would like to use. Most popular is PyLint but you can select Flake8 or Pep8 or whatever you like.

I believe you need to do these things before the linter works in real-time.

To scan for problems with your code without saving first, use shift + cmd + M, you will receive an error code in the vscode Terminal.

Solution 2:[2]

Put these lines in .vscode/settings.json

{
    "python.linting.pylintEnabled": true,
    "python.linting.enabled": true,
    "python.pythonPath": "/usr/bin/python3",
    "editor.formatOnSave": true
}

And install autopep8 package.

Use pip to install it

python3 -m pip install autopep8

Or in Debian based as python3-autopep8 exists in repo you can run

sudo apt install python3-autopep8

And then python linting on vscode will work.

Also, the Warning menu will activate.

Hint that I set run linter onsave. warning

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Athina
Solution 2