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

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

Two things that annoy me. First is the warning Flake8 gives me when I type more than 80 characters on a line. Second is the warnings I get when I haven't yet used a module name that I imported. I've looked at all the documentation on using Flake8 in the terminal. No use.

flake8 --ignore=E402
flake8 --max-line-length=120

This doesn't work. At least VS Code doesn't show any effect.

ベストアンサー1

NOTE THAT HIS ANSWER HAS BEEN DEPRECATED! THANKS TO ALL WHO UP-VOTED! I'VE MOVED THE CHECKMARK TO THE BEST ANSWER AS OF MARCH 2024.

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

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

Legend:

  • E402: Module level import not at top of file
  • F841: Local variable is assigned to but never used
  • F401: Module imported but unused
  • E302: 2 行の空白行が必要ですが、0 行見つかりました
  • E305: クラスまたは関数定義の後に2行の空白行が必要ですが、1行見つかりました

おすすめ記事