Skip to content
This repository was archived by the owner on Dec 3, 2019. It is now read-only.

RuboCop

Harry Levine edited this page May 12, 2018 · 3 revisions

How to use RuboCop

RuboCop is a Ruby static code analyzer. Out of the box it will enforce many of the guidelines outlined in the community Ruby Style Guide.

To run it locally with Docker, you will call make rubocop. This will list out any offenses that need to be addressed, before a pull request can be merged to production.

By default, it will be ran as part of the make test command.

How to auto-correct offending files for a cop

Some of RuboCop's cops offer an auto-correct option. Here are the steps to implement that feature, for a given cop.

For this example, we'll use the Style/StringLiterals style cop.

  1. Confirm that the cop is present in the .rubocop_todo.yml file
  2. In the .rubocop_todo.yml file, confirm that the cop supports --auto-correct
  3. Remove the entire cop from the .rubocop_todo.yml file. Here is a sample implementation of that.
  4. With Docker running, run the make rubocop_auto_correct command
  5. Verify the accuracy of all of the changes before committing the code to GitHub
Clone this wiki locally