Rubocopセットアップ
前提
あとで大変なことにならないよう、今のうちからRubocopを入れておく
セットアップ
rubocop.ymlの作成
とりあえず適当に、下記からファイルを持ってくる。
Gemfileに以下を追加
group :development do ... gem 'rubocop', require: false gem 'rubocop-rails' .. end
再ビルド
% docker-compose run web bundle update % docker-compose build
rubocop.ymlの修正
ymlの内容が古いため、このままだとエラーで動かないので修正。
変更前
# Railsのチェックを有効にする Rails: Enabled: true
変更後
# Railsのチェックを有効にする require: rubocop-rails
次の箇所は削除
# hashをメソッドの引数にするときに{}を省略できるけど、書いてもいい設定 Style/BracesAroundHashParameters: Enabled: false
実行
% docker-compose run --rm web rubocop Starting rails-sample_db_1 ... done /app/.rubocop.yml: Warning: no department given for AsciiComments. /app/.rubocop.yml: Warning: no department given for ClassAndModuleChildren. /app/.rubocop.yml: Warning: no department given for AccessorMethodName. /app/.rubocop.yml: Warning: no department given for AndOr. /app/.rubocop.yml: Warning: no department given for LineLength. The following cops were added to RuboCop, but are not configured. Please set Enabled to either `true` or `false` in your `.rubocop.yml` file: - Layout/EmptyLinesAroundAttributeAccessor (0.83) - Layout/SpaceAroundMethodCallOperator (0.82) - Lint/RaiseException (0.81) - Lint/StructNewOverride (0.81) - Style/ExponentialNotation (0.82) - Style/HashEachMethods (0.80) - Style/HashTransformKeys (0.80) - Style/HashTransformValues (0.80) - Style/SlicingWithRange (0.83) For more information: https://docs.rubocop.org/en/latest/versioning/ Inspecting 2 files .. 2 files inspected, no offenses detected
rubocop.ymlの内容の調整はしたほうが良さそうだが、一旦動いた。