LoginSignup
0
0

More than 1 year has passed since last update.

pylintをLinter, BlackをFormatterとして導入する [VSCode]

Posted at

概要

PythonでもLinter, Formatterを使いたいと思い、検索したところ、
色々ありましたが、Formatterとしては厳しめのBlack、Linterのpylintを
使ってみることにしました!
VSCodeの拡張機能+αで簡単にできる内容なので、ぜひやってみてください〜🙌

LinterやFormatterのメリットは以下の記事が参考になります!

導入

pylintの導入

まずは、拡張機能でpylintと検索し、インストールしましょう!

image.png

Blackの導入

次に、Blackも拡張機能で検索し、インストールしましょう!

image.png

設定の編集

最後に、プロジェクトの直下に.vscode/settings.jsonを作成します

VSCode自体の設定ファイルを変更しても問題ありません

settings.json
{
  // pylintの有効化
  "python.linting.pylintEnabled": true,
  // pythonのlinterを有効化
  "python.linting.enabled": true,
  // formatterとしてBlackを設定
  "python.formatting.provider": "black",
  "[python]": {
    // Pythonのコードサジェストを有効にする
    "editor.wordBasedSuggestions": true,
    // VSCodeのデフォルトのフォーマッターにblackを指定
    "editor.defaultFormatter": "ms-python.black-formatter",
    // ファイルの保存時(command+s or ctrl+s)でコード整形
    "editor.formatOnSave": true
  }
}

最後に

いかがでしたでしょうか?
普段の筆者はJavaScript/TypeScriptを使っていてLinter, Formatterが当たり前にある中
Pythonはないのかなぁ、と探した結果、見つかったので良かったなぁと思っています!
どのLinter, Formatterが適しているか、は使う方によっても変わってくるかもしれないので
検討してみるのも面白いかもしれませんね✨

筆者は以下の記事を参考に検討しました!

Linter, Formatterを設定して
コードを安全に、わかりやすく運用しましょう!
それでは👋

参考文献

0
0
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
0
0