gpt4 book ai didi

python-2.7 - flake8 在 vscode 中没有显示 fatal error

转载 作者:行者123 更新时间:2023-12-04 11:57:58 26 4
gpt4 key购买 nike

vscode 在 vscode 中没有显示 fatal error 。它只是突出显示代码中的警告。例子:

我使用 python 2.7 从 virtualenv 运行 flake8 的 vscode。设置如下:

"python.linting.flake8Enabled": true,

我正在将 vscode“问题”窗口的结果与直接从命令行运行 flake8 的结果进行比较。

def foo(bar):
o += 1

print(bar)

当我从上面代码的命令行运行 flake8 时,我收到所有 linting 错误和警告,
> flake8 python/mock.py 
python/mock.py:4:5: F821 undefined name 'o'
python/mock.py:4:5: F841 local variable 'o' is assigned to but never used
python/mock.py:5:1: W293 blank line contains whitespace

而当我在 vscode 中整理这段代码时,我只收到警告。
blank line contains whitespace flake8(W293) [5,1]

我在配置中遗漏了什么吗?有没有办法检查 vscode 是如何调用 flake8 的?

最佳答案

默认配置适用于我(也适用于 virtualenv 上的 Python2.7)。
flake8
检查:

  • flake8的路径可执行文件在 settings.json 中明确指定
    # From terminal/console, install flake8 into your virtual environment
    $ pipenv install --dev flake8
    $ which flake8
    /absolute/path/to/virtualenvs/test-v9MbxBL-/bin/flake8

    # Set in settings.json
    "python.linting.flake8Path": "/absolute/path/to/virtualenvs/test-v9MbxBL-/bin/flake8",
  • 致命和错误类别的严重性设置为“错误”:
    "python.linting.flake8CategorySeverity.F": "Error",
    "python.linting.flake8CategorySeverity.E": "Error",
  • 没有被忽略的错误:
    "python.linting.flake8Args": [
    "--ignore=F821"
    ]
  • 没有覆盖 flake8 设置 from external sources

    Flake8 user options are read from the C:\Users\<username>\.flake8(Windows) or ~/.config/flake8 (macOS/Linux) file.

    At the project level, options are read from the [flake8] section of atox.ini, setup.cfg, or .flake8 file.


  • 关于python-2.7 - flake8 在 vscode 中没有显示 fatal error ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57168690/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com