15
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

vscodeにblackを導入したけど、自動フォーマットされない

Posted at

#はじめに
全然効かないblack。
何でだろう?
#チェックポイント

  1. pythonは3.6以降ですか?
  2. 適切な設定をしていますか?
  3. オプションの付け方が間違っていませんか?

私は3番にハマりました。
いきなり色々変更するのはやっぱりよくないですね...

settings.json
    "[python]": {
        "editor.tabSize": 4,
        "editor.detectIndentation": false,
        "editor.formatOnSave": true,
    },
    "python.linting.enabled":true,
    "python.linting.pylintEnabled": false,
    "python.linting.flake8Enabled": true,
    "python.linting.lintOnSave":true,
    "python.formatting.provider": "black",
    "python.linting.flake8Args": [
        "--max-line-length=120",
        "--ignore=E203,W503,W504"
      ],
    "python.formatting.blackArgs": [
        "--line-length=120"
      ],

自動フォーマットが効かない問題は、1行における最大文字数の指定方法でした。

  • flake8→ max-line-length
  • black → line-length
    まじか
    以上。
15
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
15
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?