Rails Using Rubocop

Rubocop is a code analyzer and code formatter. This tool will apply recommended guidelines from the ([Ruby Style Guide])(https://github.com/rubocop-hq/ruby-style-guide). We encourage all Rails projects to adopt this tool.

Recommended settings

inherit_from: .rubocop_todo.yml
require: rubocop-rspec

Style/FrozenStringLiteralComment:
  EnforcedStyle: never

Style/StringLiterals:
  EnforcedStyle: double_quotes

Style/HashSyntax:
  EnforcedStyle: ruby19

Layout/IndentationConsistency:
  EnforcedStyle: rails

Layout/CaseIndentation:
  EnforcedStyle: end

Layout/BlockAlignment:
  Enabled: false

Layout/EndAlignment:
  EnforcedStyleAlignWith: start_of_line

AllCops:
  Exclude:
    - 'vendor/**/*'
    - 'node_modules/**/*'
    - 'db/migrate/*'
    - 'db/schema.rb'
    - 'db/seeds.rb'
    - 'bin/*'
  TargetRubyVersion: 2.6.0

Notes

  • Make sure that TargetRubyVersion is the latest Ruby version.

  • You don't need rubocop-rspec if your project is using minitest.

  • Try to fix all the issues reported in the .rubocop_todo.yml file. Treat it as a proper TODO and not a hack to avoid rubocop warnings or errors.

Resources