15

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?

Gama11
  • 31,714
  • 9
  • 78
  • 100
amigcamel
  • 1,879
  • 1
  • 22
  • 36
  • answer was received here. https://stackoverflow.com/questions/53597752/visual-studio-code-can-you-have-real-time-linting-for-python – Noctsol Dec 03 '18 at 16:58

2 Answers2

0

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.

Athina
  • 55
  • 9
0

EDIT Update 4 Jul 2022 New version of python extension deprecates "python.pythonPath" and suggest to use this instead.

"python.defaultInterpreterPath": "/usr/bin/python3",

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

EsmaeelE
  • 2,331
  • 6
  • 22
  • 31