Search code examples
pythonvisual-studio-codecondaflake8

Flake8 in VS Code: unused imports not underlined


I've installed Flake8 using Anaconda prompt, to an environment I'm using. I'm using VS Code.

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.

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.

How can I make the squiggly underlines reappear for F401?

NB. I'm unable to locate the config file discussed in the Flake8 documentation. If I could do so, I imagine I'd just be able to delete the line about ignoring F401. I couldn't find out how to locate the config file that's being applied when I call flake8 from VS Code. (As far as I can tell the documentation only tells you how to create a overriding config file.)


Solution

  • The problem was that I was using an extension called cornflakes-linter and had forgotten to update the path to the flake8 executable.

    In more detail:

    1. Located flake8 executable with the command where flake8 in the VS Code terminal.
    2. Added the following to my settings.json:

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

    I found the relevant documentation here:

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