There were a few changes needed:
* Plugins are now specified through `plugin:` config keyword.
* All plugin gems need to be specified explicitly in Gemfile since they
are no longer dependencies of plugins already specified explicitly.
* All plugin gems need to be updated in other to use the new APIs.
* One cop was renamed.
* New offenses safe to correct were corrected directly with `bundle exec
rubocop -a`.
* New offenses unsafe to correct were added to the TODO configuration
with `bundle exec rubocop --auto-gen-config --auto-gen-only-exclude
--exclude-limit 1400 --no-auto-gen-timestamp`.
I think that rspec-rails loaded the other extensions already but Rubocop
was suggesting these extensions to be loaded as well.
The alternative is to disable suggestions of new extensions but that
could hide new shiny tools when they become available.
We used to keep a manual file for metrics violations because the
automatic file didn't exclude on a file-by-file basis. But Rubocop has
an additional option these days so that we can generate that
automatically in the normal todo list.
The todo list was also out of date.
We configured Code Climate to be aware of all open issues instead of
ignoring open issues via the rubocop todo lists. We were hoping that
Code Climate could give us some nice stats like progress if it's aware
of all our open issues. But the graphs don't tell us anything. So it's
better to have one source of truth for our open style issues and that is
our rubocop config in this repository. It contains two todo lists that
document all violations we would like to fix in the future but it's okay
to submit pull requests that don't fix those.
Instead of accepting new style issues in Code Climate, every pull
request with new violations has to add them to the rubocop config. I
hope that this will make rubocop more useful and encourage developers to
reduce code style debt.
Our rubocop config hides all current violations. It allows us to have a
passing rubocop run on the current code and improve it gradually. It
detects new violations, but doesn't annoy us with all the existing ones.
Code Climate has its own way of remembering all current violations which
is more sophisticated than ours. The new config for Code Climate doesn't
hide any violations so that Code Climate can give us a realistic score
of code quality and warn us about every new violation.
Splitting the configuration into the main three parts gives a quicker
overview and makes maintaining the parts easier.
The file .rubocop_todo.yml is generated automatically and contains a
configuration to make all files pass. For a lot of cops it just lists
the offending files. But for some cops it sets a different metric.
Since we don't want these lax metrics, we override them in our config
file .rubocop.yml. This leads to a lot of offences again. This patch
lists all offending files for each cop to make rubocop pass. We can
improve the code over time and remove items from the list.
One of the biggest pros of linters like Rubocop is to get valuable feedback to
help write better code. The way we have Rubocop configured now we don't prevent
new code from adhere improved code quality and this is specially important when
touching code that already suffers from complexity.
Without all Rubocop's Metrics cops enabled there's no way to get this insights
and write better code. This enables them while regenerating the
`.rubocop_todo.yml` to hide the current violations.
So, next time we touch existing code that we think could be simpler, we should
go to `.rubocop_todo.yml` and remove any occurrences of the file in question.
This way we could Rubocop's feedback right in the editor. This is tremendously
helpful when refactoring. It shows you where to start.
This enforces the ruby 1.9 symbol hash syntax and consistency among the
style of the keys.
# bad
{:a => 1, :b => 2}
{c: 2, 'd' => 3} # should just use hash rockets
# good
{a: 1, b: 2}
{:c => 3, 'd' => 4}
The .rubocop-todo.yml is also updated to keep track of the existing
violations.
This enables the Rubocop's Style/MultilineMethodCallIndentation cop with
indentend enforced style. Which makes you split multiline method calls like:
orders = Spree::Order
.an_scope
.another_scope
.where(id: list_of_ids)
It also autofixes the current violations and updates the
rubocop_todo.yml