Use a Ruby Linter
Published: Nov 17th, 2020
This is part of Joyful Rails, a list of recommendations to make developing your Rails app more productive and joyful.
In this article, we are talking about using a Ruby linter.
When
The longer you wait to add a Ruby linter, the more work you will have to correct style errors that have accumulated. For that reason, I recommend adding a linter, such as RuboCop, as early as possible.
Why
Having a consistent style makes code easier to read and maintain. Using a linter makes it easy to conform to a consistent style. In a lot of cases, your linter can make corrections automatically.
How
- Add the RuboCop gem. Add the
gem 'rubocop'
to the development group of yourGemfile
and runbundle
. - Configure RuboCop. Add a
.rubocop.yml
with the RuboCop configuration. - Run RuboCop with auto-correct,
rubocop --auto-correct
. - Correct errors that RuboCop cannot correct automatically.