Visual studio 代码抑制 pep8 警告

Visual studio code suppress pep8 warnings

如何在 Visual studio 代码中抑制 pep8 警告?我想要做的是抑制 E501 警告我不想在我的代码长度超过 80 个字符时收到警告。我正在使用 Don Jayamanne's Python extension,这是 vscode

的配置文件
{
    "python.linting.pylintEnabled": false,
    "python.linting.pep8Enabled": true,
    "python.pythonPath": "/workspace/virtualenvs/abr/bin/python3",
    "python.linting.enabled": true
}

我知道还有另一种选择 "python.linting.pep8Args": [] 但我无法让它工作。我在 virtualenv

上安装了 pep8

我已经尝试过的。

  1. "python.linting.pep8Args": ['--ignore=E501']
  2. "Searched all visual studio code settings"

几周前我还在为这个问题而苦恼。我最终做的是将 setup.cfg 文件添加到我的项目的根文件夹中,并将以下内容放入其中:

[pep8]
ignore = E501

你做的是正确的。但是,您必须启动 VScode 才能看到差异。 (我更喜欢自动更新本身。)

请尝试使用双引号 " 而不是单引号 '

['--ignore=E501'] --> ["--ignore=E501"]

它对我有用。不要忘记重新启动程序。

对单个项目使用 setup.cfg 或更改所有 py 文件的用户设置。

{
    "python.linting.pycodestyleEnabled": true,
    "python.linting.pycodestyleArgs": [
        "--ignore=E501" 
    ]
}

October 2019 之前,所有 pycodestyle 设置都被命名为 pep8:

{
    "python.linting.pep8Enabled": true,
    "python.linting.pep8Args": [
        "--ignore=E501" 
    ]
}

这对我有用:

"python.linting.flake8Enabled": true,
"python.linting.flake8Args": ["--ignore=E501"]

如果您想更改行长,请将其添加到您的用户设置文件中

{ 
  "python.linting.pep8Enabled": true,
  "python.linting.pep8Args": ["--max-line-length=120" ]
}

之前的代码给我 'EOF' 错误,所以我编辑了它

我在 https://code.visualstudio.com/docs/python/linting 找到了 vscode 1.31.1

的答案

通过修改解决了 settings.json

{
    "workbench.iconTheme": "material-icon-theme",
    "workbench.colorTheme": "Material Theme Ocean",
    "git.autofetch": true,
    "python.linting.flake8Args": ["--ignore=E501", "--verbose"]
}

要忽略多个 pycodestyle 警告:

{
    "python.linting.pycodestyleEnabled": true,
    "python.linting.pycodestyleArgs": [
        "--ignore=E501,W503" 
    ]
}

如果您使用的不是 flake8Args,而是 Pylama(例如),settings.json 上的配置更改与之前描述的类似: "python.linting.pylamaArgs": ["--max_line_length=120"] 要么 "python.linting.pylamaArgs": [""--ignore=E501" "]

对我有用的是将下面的代码片段添加到我的用户 settings.json 文件中。上面提到过,但没有 settings.json.

"python.linting.flake8Enabled": true,
"python.linting.flake8Args": ["--ignore=E501"]