【问题标题】:Visual Studio code with PyLint and autoPep8: How can I avoid PyLint to complain about my line length?带有 PyLint 和 autoPep8 的 Visual Studio 代码:如何避免 PyLint 抱怨我的行长?
【发布时间】:2019-02-03 03:32:06
【问题描述】:

我最近切换到了 Visual Studio Code,我不得不说到目前为止我很喜欢它。

我正在开发一个 Python 项目,其中包括 pip 包 pylint 和 autopep8,我配置 VSCode 以根据这些包格式化代码。

唯一的问题是:在我正在处理的 Python 项目中,行长是 100。所以我的所有代码都如下所示:

错误提示:E501:line too long (97 > 79 characters)。这是我的 VSCode 设置:

{
  "python.pythonPath": "~/.envs/myProject/bin/python",
  "python.linting.pep8Enabled": true,
  "python.linting.pylintPath": "~/.envs/myProject/bin/pylint",
  "python.linting.pylintArgs": ["--load-plugins", "pylint_django", "--max-line-length=100"],
  "python.formatting.autopep8Args": ["--max-line-length=100"],
  "python.linting.pylintEnabled": true,
  "files.exclude": {
    "**/.git": true,
    "**/.svn": true,
    "**/.hg": true,
    "**/CVS": true,
    "**/.DS_Store": true,
    ".vscode": true,
    "**/*.pyc": true
  }
}

这些设置至少现在可以确保保存时的格式将行数保持在最大 100 行,并且不会将我的所有文件行换成 79 行。如果没有警告,它仍然会很棒。

如何禁用这些 linter 警告?

【问题讨论】:

  • 已确认,它对我也不起作用。我还使用max-line-length=120 创建了一个 .pylintrc,但仍然遇到所有这些烦人的错误

标签: python visual-studio-code pylint linter autopep8


【解决方案1】:

我想出了如何做到这一点。将此行添加到您的设置中:

"python.linting.pep8Args": ["--max-line-length=100"],

【讨论】:

  • "python.linting.pep8Enabled": true 和 "python.formatting.pep8Args": ["--max-line-length=100"] 似乎不再是有效的设置。你的初始配置应该足够了
  • 在撰写本文时,这对我有用:"python.linting.pylintArgs": ["--max-line-length=200"]
【解决方案2】:

对于 Vscode 1.15.1 中的pycodestyle:

"python.linting.pycodestyleArgs": ["--max-line-length=100"],

【讨论】:

    【解决方案3】:

    截至 2021 年 (Pylint reference),将此添加到您的 .vscode/settings.json 文件中:

    "python.linting.pylintArgs": ["--max-line-length=100"]
    

    【讨论】:

    • 这是我认为最干净的解决方案。
    【解决方案4】:

    2020 版:

    将以下条目添加到您的 settings.json 文件中

    "python.linting.pylintArgs": ["-d", "C0301"],
    

    【讨论】:

    • 为什么是C0301?这方面的文档在哪里?
    【解决方案5】:

    对我来说,以下工作。 (VSCode 版本 == 1.41.1)

    转到设置。

    搜索“pylint”。

    向下滚动到“Python > Linting: Pycodestyle Args”

    点击“添加项目”

    输入“python.linting.pep8Args”:[“--max-line-length=200”]

    将 max-line-length 调整为所需的长度。

    【讨论】:

      猜你喜欢
      • 2019-03-31
      • 1970-01-01
      • 1970-01-01
      • 2020-08-28
      • 1970-01-01
      • 1970-01-01
      • 2011-08-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多