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

标签 python-2.7 visual-studio-code flake8

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 a tox.ini, setup.cfg, or .flake8 file.


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

    相关文章:

    python - python 上的列表始终附加相同的值

    python/kivy : How to pass text value from another class in . kv 文件

    python - 连接字符串文字以生成变量名

    javascript - 为什么我的网页在应用 CSS 样式之前呈现原始 html - 既通过 Visual Studio Code 和 Firefox 在本地也托管在 github 上?

    python - Flake8 linter 检查仅在推送文件上通过 Bitbucket 管道

    默认情况下不存在 flake8 配置文件

    algorithm - 是有效的哥伦布标尺

    typescript - VSCode、Prettier 和 TSLint : formatOnSafe messes up auto sort of imports

    python - 未检测到 VS 代码 venv (WSL)

    python-2.7 - 如何在 circle.yml 中运行 flake8