Installing Rubocop and Overcommit
Install gems
$ gem install rubocop $ gem install overcommit
sets up githooks
$ overcommit –install
Sign changes to overcommit.yml
$ overcommit –sign
Run Rubocop against project
Displays Filename, line and description of error
$ rubocop
Rubocop Output
Symbol Description
. No issues
C Convention
E Error
F Fatal error
W Warning
Output offense name and count
$ rubocop –format offenses
Show cop definition
$ rubocop –show-cop Style/ZeroLengthPredicate
List all cops with description, key/values and link to style guide
$ rubocop –show-cops
Output offense name and count
$ rubocop –format offenses
Run a specific cop against project
$ rubocop –only Style/StringLiterals
Check a specific file with all cops
$ rubocop ./app/models/app_namespace/api/v1/saved_calendar.rb
Check a specific file with all cops
$ rubocop ./app/models/app_namespace/api/v1/saved_calendar.rb –only Style/StringLiterals
Check a specific file output errors as json
$ rubocop –format json app/models/app_namespace/api/v1/project.rb
Auto-correct with a specific cop
$ rubocop –auto-correct –only RedundantParentheses
Output offenses w formatted suggestion,
url to additional comments / example
$ rubocop –display-style-guide
Displays Filename, line and description of error
With url to documentation for this cop
$ rubocop –display-style-guide –display-cop-names
Show code correctness
$ rubocop –lint
List Files
$ rubocop –list-target-files
In the instance of a Merge, it may be required to Skip RuboCop
$ SKIP=RuboCop git commit -am “Merge”
Generate todo list / Turn off all cops
$ rubocop –auto-gen-config