⛳
rubocop-rails-omakaseから始めるrubocop
Rails7.2からrails new
で、rubocop-rails-omakaseが導入できるようになっている。
生成されたrubocopは軽量なrubocopとなっているため、あくまでプロジェクトの出発点として考えるべき。(omakaseのみのゼロコンフィギュレーションは現実的ではない)
rubocop-rails-omakaseは、初期設定がすべてEnabled: false
にしており個別に有効化している。有効化されているCopについては比較的少なく、Layoutルールに対する設定が多く見られる。また、minitestの利用が前提になっている。
例えば、Lintルールは、全体60に対し下記の3ルールのみの有効化となっている。
Lint/UselessAssignmentなど、実装時の不具合が検出できるLint設定が無効化されているので、積極的にrubocopの設定をしていくべき。
rspec/factory_botを利用を前提にし、下記のrubocop設定から出発する。
inherit_gem: { rubocop-rails-omakase: rubocop.yml }
require:
- rubocop-rspec
- rubocop-factory_bot
AllCops:
NewCops: enable
#################### Bundler ###########################
Bundler:
Enabled: true
#################### Lint ###########################
Lint:
Enabled: true
#################### Rails ###########################
Rails:
Enabled: true
Rails/DynamicFindBy: # generate_token_forによる定義される`find_by_token_for`で利用。
Enabled: false
Rails/I18nLocaleTexts:
Enabled: false
Rails/NotNullColumn:
Enabled: false
Rails/InverseOf:
Enabled: false
#################### Security ###########################
Security:
Enabled: true
参考資料
Discussion