概要
題名の通り、VSCodeでlinter、formatterとしてflake8、black、isortを使用するための設定方法についての手順メモ。自分用メモなので間違っているかもしれない。
手順
前提
以下を前提とする:
- Python3系がインストール済み
- VSCodeがインストール済み
- VSCodeの拡張機能のPythonがインストール済み
- VSCodeの拡張機能のPylanceがインストール済み(拡張機能のPythonを入れると勝手に入ってるはず)
flake8、blackのpipインストール
上記3つを使うためにとりあえず以下を実行してモジュールをインストールする:
flake8のインストール
pip install flake8
blackのインストール
pip install black
(本当はどちらも次のisortと同じく、VSCodeの拡張機能で入れるのが推奨っぽい)
VSCodeの拡張機能でisortを入れる
VSCodeの「拡張機能」を開き、検索窓から「isort」を検索してisortをインストールする。
settings.jsonへ設定を記載
まず、左下の歯車マークをクリック→設定を選択し、右上の方にある「紙をひっくり返す?」的なマークをクリックしてsettings.jsonを開く。
そして開いたsettings.jsonに次を追記する:
settings.jsonへの追記事項
{
"python.linting.enabled": true,
"python.linting.pylintEnabled": false,
"python.linting.flake8Enabled": true,
"python.formatting.provider": "black",
"editor.defaultFormatter": null,
"editor.formatOnSave": true
}
これである程度PEP8に沿ってプログラミングを進めていける(はず)