0
0

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.

intelij(JetBrains製IDE)でファイル保存時にコマンドを実行する

Last updated at Posted at 2020-09-16

ファイル保存時にリンターやフォーマッターを実行させたい時に便利です。
参考:blackとpylintを使った快適なPython開発

File Watchersのインストール

Preferences > Plugins
からFile Watchersをインストールする(インストール後にintelijの再起動が必要)

スクリーンショット 2020-09-16 23.13.05.png

File Watchersの設定

Preferences > Tools > File Watchers
+ > <custom> からファイル保存時に実行したいコマンドを追加できる
スクリーンショット 2020-09-16 23.17.33.png

開いたWindowに実行したいコマンドを入力してOKを押せば保存される

項目名 説明
Name 任意の名前
FileType どの拡張子ファイルを保存した時にコマンドを実行するか
Scope 基本的にCurrentFIleでOK
Program 実行したいコマンドの最初のワード
Arguments 実行したいコマンドの二つ目以降のワード
Working directory コマンドを実行する際のカレントディレトリ
Advanced Options 自動保存時にもコマンドを実行するかなど チェックを外しておくのが無難

以下はPythonファイル保存時にpoetryでpylintを実行する場合の例
スクリーンショット 2020-09-16 23.26.54.png

$FilePath$は保存したファイルのパスのマクロ
$FileDir$は保存したファイルののディレクトリパスのマクロ
入力欄の+からマクロ一覧が見れる
スクリーンショット 2020-09-16 23.34.45.png

プロジェクト間での設定の共有

複数のリポジトリで使いたい時はLevelをGlobalに設定すると、
他のプロジェクトでもFile Watchers設定画面で表示される
デフォルトでEnabledのチェックは外れてるので使用したい場合はチェックを入れる必要あり
スクリーンショット 2020-09-16 23.35.42.png

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?