【问题标题】:Auto format flake8 linting errors in VSCodeVSCode 中的自动格式化 flake8 linting 错误
【发布时间】:2021-11-07 13:02:48
【问题描述】:

我正在为 Python 使用 flake8 linter,但我遇到了许多代码格式问题,例如 blank line contains whitespace flake8(W293)

我正在尝试自动修复这些掉毛问题。我有这些设置:

    "python.linting.enabled": true,
    "python.linting.flake8Enabled": true,
    "python.linting.lintOnSave": true,
    "python.linting.flake8Args": [
        "--ignore=E501",
    ],
    "editor.formatOnSave": true

我正在使用默认的autopep8 格式化程序,但它似乎什么也没做。 当我保存文件或运行命令Format Document时没有任何反应。

有没有办法自动修复这些 linting 错误?

【问题讨论】:

    标签: python visual-studio-code formatting flake8 linter


    【解决方案1】:

    例如,我建议使用formatterblack 来解决您的linter 检测到的问题。

    如果是这样,“点安装”它并将其添加到您的 settings.json

    "python.formatting.provider": "black"
    

    然后,按Alt+ShifT+FCtrl+S 应该会触发脚本的格式设置。

    【讨论】:

    【解决方案2】:

    应该是:

     "python.linting.flake8Args": ["--ignore=W293"],
    

    您可以将格式切换为yapfblack

    如果你坚持autopep8,可以在settings.json中添加这个:

    "python.formatting.autopep8Args": ["--select=W293"],
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-06-13
      • 2019-08-12
      • 1970-01-01
      • 1970-01-01
      • 2023-02-20
      • 2021-03-09
      • 1970-01-01
      相关资源
      最近更新 更多