Skip to content
David Cook edited this page Oct 23, 2023 · 2 revisions

Rubocop is a linter that helps us enforce consistency in coding style.

Automatic correction

There is script to do the below steps quickly: see instructions inside script/rubocop-autocorrect.sh

Fixing all violations of a single cop

In order to fix all the existing occurrences of a cop, we need to run Rubocop with the --auto-correct flag and regenerate the .rubocop_todo.yml to remove the previous exclusion of that same cop.

So first, fix the violations of that particular cop like so:

bundle exec rubocop --auto-correct --only <cop_name> path/to/file

Where <cop_name> is the identifier of the cop. Something like Layout/BlockEndNewline, the one we fixed in https://github.com/openfoodfoundation/openfoodnetwork/pull/2063. You will find their names in .rubocop_todo.

Now, that these violations are fixed, we have to get rid of them in the .rubocop_todo.yml. They are no longer true.

To do that, go check the header of that file. It specifies how to do it:

# This configuration was generated by
# `rubocop --auto-gen-config --exclude-limit 1400`
# on 2018-01-20 12:46:57 +0100 using RuboCop version 0.49.1.

so, just run:

bundle exec rubocop --auto-gen-config --exclude-limit 1400

Notice that we must precede the command with bundle exec in order for ruby to pick the rubocop version from the app's Gemfile.

We're done. Stash all these changes, commit and push them here. Then, open a pull request so that we can all review them. Congratulations 🎉! by making our codebase closer to our style guide you are one step closer to heaven 👼

Clone this wiki locally