VS Code config

Code チェッカーとフォッマッターをインストールする

PEP8に沿ったコーディングのために関連ライブラリをインストール

LibraryDescription
flake8PEP8に沿った書き方かチェック
blackPEP8に沿った書き方に自動整形
isortimport文をPEP8に沿った書き方に並べ替え
mypyタイプヒントの型チェック
$ . .venv/bin/activate
(.venv) ~$ pip install flake8 black isort mypy

VS Code の設定

.vscode/setting.jason

{
    "python.linting.flake8Enabled":true,
    "python.linting.mypyEnabled":true,
    "python.linting.flake8Args":[
        "--max-line-length=88",
    ],
    "python.formatting.provider":"black",
    "editor.formatOnSave":true,
    "editor.codeActionsOnSave":{
        "source.organizeImports":true
    }
}
{
    "python.linting.flake8Args": [
        "--ignore=E501"
    ]
}

VS Codeの拡張機能でサポートすることになったので、setting.jsonに上段のような記載することが推奨されなくなっている。上記は、79行を超える記載が必要なときにE501ルールを無視する設定

設定項目

  • Python > Linting : Pyling Enabled ※ Flake8をEnabledにすると自動的にdisableになっている
  • Python > Linting : Enabled
  • Python > Linting : Flake8 Enabled
  • Python > Linting : Flake8 Args [ –max-line-length=88 ]
  • Python > Formatting : Provider = > select “balck”
  • Editor : Format On Save
  • “editor.codeActionsOnSave” : {
    “source.organizeImports” : true
    }
  • Python > Linting : Mypy Enabled

VS Code 項目

ショートカットの設定

コマンド 実行内容
Ctrl + rpythonスクリプの実行
Ctrl + ;エディタとターミナル間の移動