LoginSignup
46
28

More than 5 years have passed since last update.

Rubocop を使っているアナタがするべき2つのこと

Last updated at Posted at 2017-09-27

1. とりあえず -D -E -S -P をつけるべし

オプションはいくつもありますが、-D -E -S は特に副作用がないので、常に有効化することをオススメします。また、-P をつけると処理速度が向上します。

$ export RUBOCOP_OPTS='-D -E -S -P' # おすすめ設定
$ bundle exec rubocop

export RUBOCOP_OPTS='-D -E -S -P'~/.bashrc などに書いておきましょう。

それぞれの意味はこちら:

-D, --display-cop-names    Display cop names in offense messages.
-E, --extra-details        Display extra details in offense messages.
-S, --display-style-guide  Display style guide URLs in offense messages.
-P, --parallel             Use available CPUs to execute inspection in

ただし、-P オプションは --auto-gen-config と併用できないので、--auto-gen-configを使う時は無効化する必要があります。

$ RUBOCOP_OPTS= bundle exec rubocop --auto-gen-config

2. --auto-gen-config には --exclude-limit=99999 もつけるべし

1種類のCopについて、違反しているファイルが15個以上になると、

# Offense count: 23
# Cop supports --auto-correct.
Layout/BlockEndNewline:
  Enabled: false

のように、Cop自体を無効化する設定が .rubocop_todo.yml に生成されてしまいます。これでは、新たに追加するファイルに対しても警告がされません。
そこで、--exclude-limit に大きな数値を指定して、Enabled: false が生成されないようにしましょう。

また、--no-offense-counts--no-auto-gen-timestamp も指定しておくと、.rubocop_todo.yml を再生成した時の差分が小さくなり Gitのログが見やすくなります。

        --exclude-limit COUNT        Used together with --auto-gen-config to
                                     set the limit for how many Exclude
                                     properties to generate. Default is 15.
        --no-offense-counts          Do not include offense counts in configuration
                                     file generated by --auto-gen-config.
        --no-auto-gen-timestamp      Do not include the date and time when
                                     the --auto-gen-config was run in the file it
                                     generates.
$ RUBOCOP_OPTS= bundle exec rubocop --auto-gen-config --exclude-limit=99999 --no-offense-counts --no-auto-gen-timestamp
46
28
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
46
28