How do I get flake8 to reliably ignore rules in VS Code?

The solution proposed by reka18 is great and was no doubt written specifically for the original question.

From a more general stand point, I would advise against using this kind of trick if you work on a project that has dedicated configuration files.

You are guaranteed to run into incomprehensible configuration conflicts and will possibly ignore rules that were purposefully enforced by the project.

In this case, you should use the following instead:

assuming the file is named .flake8 and is present at the project's root folder

// .vscode/settings.json
"python.linting.flake8Args": ["--config", ".flake8"],

Add your arguments to your USER SETTINGS json file like this:

"python.linting.flake8Args": [
    "--max-line-length=120",
    "--ignore=E402,F841,F401,E302,E305",
],

note that flake8 uses

"python.linting.flake8Args": [

whereas black seems to use:

"python.formatting.blackArgs": [

if you're using both (or toggling) these settings maybe helpful:

    {
        "python.linting.pylintEnabled": false,
        "python.linting.flake8Enabled": true,
        "python.linting.enabled": true,
        "python.formatting.provider": "black",
        "python.formatting.blackArgs": [
            "--line-length",
            "120"
        ],
        
        "python.linting.flake8Args": [
            "--max-line-length=120",
            "--ignore=E402",
        ],
    
        "python.pythonPath": "venv/bin/python"
    }


I ran into this problem recently. I ran into problems because I was setting the argument to --config flake8.cfg instead of --config=flake8.cfg. Under the hood, vscode puts the CLI argument in quotes. Adding "--config flake8.cfg" to the flake8 command seems to confuse flake8 into thinking that it's looking at a file path and not a CLI argument.

The solution for me was to either set the args as --config=flake8.cfg (with the equals sign) or the args up into separate items in the array:

"python.linting.flake8Args": [
  "--config",
  "flake8.cfg"
]