简体   繁体   English

VS Code 中的 Flake8:未使用的导入未加下划线

[英]Flake8 in VS Code: unused imports not underlined

I've installed Flake8 using Anaconda prompt, to an environment I'm using.我已经使用 Anaconda 提示符将 Flake8 安装到我正在使用的环境中。 I'm using VS Code.我正在使用 VS 代码。

I recently used the terminal in VS Code to tell Flake8 to ignore certain errors and I think one of them was F401, which concerns unused imports.我最近在 VS Code 中使用终端告诉 Flake8 忽略某些错误,我认为其中之一是 F401,它涉及未使用的导入。

It's very clear how to ignore a given error, but I can't find anything about how to "unignore" it.很清楚如何忽略给定的错误,但我找不到任何关于如何“忽略”它的信息。

I know Flake8 is working in my environment because other errors are given squiggly underlines in VS Code.我知道 Flake8 在我的环境中工作,因为在 VS Code 中给出了波浪线下划线的其他错误。

How can I make the squiggly underlines reappear for F401?如何使 F401 的波浪下划线重新出现?

NB.注意。 I'm unable to locate the config file discussed in the Flake8 documentation.我找不到 Flake8 文档中讨论的配置文件。 If I could do so, I imagine I'd just be able to delete the line about ignoring F401.如果可以的话,我想我可以删除关于忽略 F401 的行。 I couldn't find out how to locate the config file that's being applied when I call flake8 from VS Code.当我从 VS Code 调用 flake8 时,我找不到如何找到正在应用的配置文件。 (As far as I can tell the documentation only tells you how to create a overriding config file.) (据我所知,文档仅告诉您如何创建覆盖配置文件。)

The problem was that I was using an extension called cornflakes-linter and had forgotten to update the path to the flake8 executable.问题是我使用了一个名为cornflakes-linter linter 的扩展并且忘记更新flake8 可执行文件的路径。

In more detail:更详细地说:

  1. Located flake8 executable with the command where flake8 in the VS Code terminal.使用 VS Code 终端中的命令where flake8 flake8 可执行文件。
  2. Added the following to my settings.json :在我的settings.json添加了以下内容:

     "cornflakes.linter.executablePath": "path/to/venvs/myvenv/bin/flake8"

I found the relevant documentation here:我在这里找到了相关文档:

https://github.com/kevinglasson/vscode-cornflakes-linter https://github.com/kevinglasson/vscode-cornflakes-linter

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM