Pylint未按预期在VScode中运行

pka*_*mol 1 python lint visual-studio-code

当我通过shell运行时pylint

$ pylint decorator.py 
No config file found, using default configuration
************* Module decorator
C:  7, 0: Unnecessary parens after 'print' keyword (superfluous-parens)
C: 15, 0: Unnecessary parens after 'print' keyword (superfluous-parens)
C:  1, 0: Missing module docstring (missing-docstring)
C:  4, 0: Missing function docstring (missing-docstring)
C:  6, 4: Missing function docstring (missing-docstring)
C: 14, 0: Missing function docstring (missing-docstring)
Run Code Online (Sandbox Code Playgroud)

但是,如下所示,这些警告不会在VSCode中出现

在此处输入图片说明

...尽管实际上已经执行了一些基本检查,如下图所示,但我删除了空白行:

在此处输入图片说明

sny*_*m42 11

我有一个类似的问题,flake8 在 VSCode 中工作但 pylint 没有。以下是我必须检查 pylint 才能开始工作的所有步骤:

  1. 您的.vscode\settings.json文件通过 pylint 启用 linting(这可以手动编辑或通过运行这些命令面板命令:Python: Enable LintingPython: Select Linter

    “python.linting.enabled”:真

    “python.linting.pylintEnabled”:真

  2. 从命令行(在虚拟环境中)确认已安装 pylint 和 pylint-django。

    点显示pylint

    pip 显示 pylint-django

  3. .pylintrc文件添加到包含这些行的根目录。

    [掌握]

    加载插件=pylint_django

(注意:您可以使用 settings.json 中的以下行替换此 pylintrc 文件。)

"python.linting.pylintArgs": ["--load-plugins", "pylint_django"]
Run Code Online (Sandbox Code Playgroud)

有关在 VSCode 中使用 pylint 的更多信息,请参阅https://code.visualstudio.com/docs/python/linting#_pylint

有关 pylintrc 文件的更多信息,请参阅https://docs.pylint.org/en/1.6.0/run.html#command-line-options

  • 您能否澄清一下为什么使用 pylint_django,而不是仅仅使用 pylint? (2认同)
  • 注意:如果您使用 python 扩展,则会缺少一个步骤。验证所选环境(左下角)是否是您想要的环境,并且已安装“pylint”。 (2认同)

luc*_*gcb 5

Assuming you have configured Python's Extension correctly and you have Pylint installed,

VSCode's Python Extension will do minimal checking by default if you do not provide a Pylint configuration option.

Simply enter "python.linting.pylintUseMinimalCheckers": false, into your .vscode/settings.json to force this off.

This is how mine looks:

{
    "autoDocstring.docstringFormat": "numpy",
    "editor.minimap.enabled": false,
    "editor.selectionClipboard": false,
    "python.pythonPath": "/home/jim/anaconda3/envs/dipoleDisplay",
    "window.zoomLevel": 0,
    "terminal.integrated.rendererType": "dom",
    "python.linting.pylintUseMinimalCheckers": false,
}
Run Code Online (Sandbox Code Playgroud)

设定后

  • 截至 2022 年 2 月,此“python.linting.pylintUseMinimalCheckers”似乎不再存在 - 它在 json 编辑器中显示为“未知配置设置”。 (17认同)