LoginSignup
1
0

More than 5 years have passed since last update.

Rubocop実行待ちの辛さを和らげるコマンド

Last updated at Posted at 2018-10-05

私はRubocopが大好きです!!

Gemfilegem 'rubocop'を無いRubyプロジェクトなど、福神漬けの無いライスカレーのようなものだと思います 1

しかし、Rubocopの実行をじっと待つのはあまり楽しくはありません。5秒10秒ならまだしも、ファイル数が増えて1分を超えてくると、フロー状態が途切れてしまいます。

そこで「開発中のGitブランチで変更があったファイルのみRubocopでチェックする」スクリプトを作りました。必要なファイルだけ検査するので、実行時間が大幅短縮できます。

以下のコマンドを適当な名前(私は~/bin/rubo)で保存してください。

#!/bin/bash
valid_file() {
  while read -r f; do
    if [ -e "$f" ]; then
      echo "$f"
    fi
  done
}

git diff --name-only origin/master | valid_file | xargs rubocop --auto-correct "$@"

  1. 僕はラッキョウが嫌いです。 

1
0
3

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