Skip to content

Setup Rubocop for Rails apps

Abraham edited this page Sep 23, 2016 · 2 revisions

This article will provide a base configuration file for rubocop when working on Rails applications.

Base configuration

The base configuration includes:

  • Exclusion of common files we don't actually want to analyze with rubocop
  • The ruby version which we want to run the analysis
  • The code styles/metrics to include or ignore
AllCops:
  TargetRubyVersion:
    2.3
  Exclude:
    - Guardfile
    - Gemfile
    - Gemfile.lock
    - db/schema.rb
    - db/migrate/*
    - db/default/*
    - config/initializers/*
    - config/environments/*
    - bin/*
    - spec/rails_helper.rb
    - spec/spec_helper.rb
    - config.ru
    - Rakefile

Documentation:
  Enabled: false

Metrics/ClassLength:
  Max: 150

Style/AsciiIdentifiers:
  Enabled: false

Style/FrozenStringLiteralComment:
  Enabled: false

Style/DefWithParentheses:
  Enabled: false
    
Metrics/LineLength:
  Enabled: false

Style/BlockComments:
  Enabled: false

Style/BlockDelimiters:
  Enabled: false

Style/CaseIndentation:
  Enabled: false
    
Style/EmptyLinesAroundAccessModifier:
  Enabled: false

Style/EmptyLinesAroundBlockBody:
  Enabled: false

Style/EmptyLinesAroundClassBody:
  Enabled: false

Style/EmptyLinesAroundModuleBody:
  Enabled: false
    
StringLiterals:
  Enabled: false

Style/MethodDefParentheses:
  Enabled: false

Style/TrailingWhitespace:
  Enabled: false

Style/TrailingBlankLines:
  Enabled: false

Style/SpaceBeforeBlockBraces:
  Enabled: false

Style/SpaceBeforeComment:
  Enabled: false

Style/SpaceInsideBlockBraces:
  Enabled: false

This configuration file can easily change and be adapted to other contexts.

Clone this wiki locally