Auto-generating Configuration
If you have a code base with an overwhelming amount of offenses, it can
be a good idea to use rubocop --auto-gen-config, which creates
.rubocop_todo.yml and adds inherit_from: .rubocop_todo.yml in your
.rubocop.yml. The generated file .rubocop_todo.yml contains
configuration to disable cops that currently detect an offense in the
code by changing the configuration for the cop, excluding the offending
files, or disabling the cop altogether once a file count limit has been
reached.
By adding the option --exclude-limit COUNT, e.g., rubocop
--auto-gen-config --exclude-limit 5, you can change how many files are
excluded before the cop is entirely disabled. The default COUNT is 15.
If you don’t want the cop to be entirely disabled regardless of the
number of files, use the --no-exclude-limit option, e.g.,
rubocop --auto-gen-config --no-exclude-limit.
Working through the TODO
The next step is to cut and paste configuration from .rubocop_todo.yml
into .rubocop.yml for everything that you think is in line with your
(organization’s) code style and not a good fit for a todo list.
Pay attention to the comments above each entry in .rubocop_todo.yml.
They can reveal configuration parameters such as EnforcedStyle, which can
be used to modify the behavior of a cop instead of disabling it completely.
|
Then you can start removing the entries in the generated
.rubocop_todo.yml file one by one as you work through all the offenses
in the code. You can also regenerate your .rubocop_todo.yml using
the same options by running rubocop --regenerate-todo.
Another way of silencing offense reports, aside from configuration, is through source code directives. These can be added manually or automatically.
Metrics cops
The cops in the Metrics department will by default get Max parameters
generated in .rubocop_todo.yml. The value of these will be just high enough
so that no offenses are reported the next time you run rubocop. If you
prefer to exclude files, like for other cops, add --auto-gen-only-exclude
when running with --auto-gen-config. It will still change the maximum if the
number of excluded files is higher than the exclude limit.
EnforcedStyle
Some cops have a configurable option named EnforcedStyle.
By default, when generating the .rubocop_todo.yml, if one style is used
for all files, these cops will add the settings for the style being used.
If you want to exclude on a file-by-file basis,
add the --no-auto-gen-enforced-style option along with --auto-gen-config.