【问题标题】:Real-time linting of Python with VSCode使用 VSCode 对 Python 进行实时 linting
【发布时间】:2017-05-03 08:49:37
【问题描述】:
【问题讨论】:
标签:
visual-studio-code
editor
【解决方案1】:
如果您使用 shift + cmd + P(或 ^+ctrl+P 用于 windows)或转到查看 > 命令面板并输入“Lint”
命令面板允许您执行不同的命令,您可以在此处启用/禁用 Linting 并选择您想要使用的 Linter。最受欢迎的是 PyLint,但您可以选择 Flake8 或 Pep8 或任何您喜欢的。
我相信你需要在 linter 实时工作之前做这些事情。
要扫描代码问题而不先保存,请使用 shift + cmd + M,您将在 vscode 终端中收到错误代码。
【解决方案2】:
将这些行放入.vscode/settings.json
{
"python.linting.pylintEnabled": true,
"python.linting.enabled": true,
"python.pythonPath": "/usr/bin/python3",
"editor.formatOnSave": true
}
并安装autopep8 包。
使用pip安装
python3 -m pip install autopep8
或者在基于 python3-autopep8 的 Debian 中存在于你可以运行的 repo 中
sudo apt install python3-autopep8
然后在 vscode 上的 python linting 将起作用。
此外,警告菜单将激活。
提示我设置了运行 linter onsave。