- Creating new RuboCop cops
- Cop grace period
- Enabling a new cop
- Silenced offenses
- Resolving RuboCop exceptions
- Reveal existing RuboCop exceptions
Our codebase style is defined and enforced by RuboCop.
You can check for any offenses locally with
bundle exec rubocop --parallel.
On the CI, this is automatically checked by the
For RuboCop rules that we have not taken a decision on, follow the Ruby style guide to write idiomatic Ruby.
Reviewers/maintainers should be tolerant and not too pedantic about style.
Some RuboCop rules are disabled, and for those, reviewers/maintainers must not ask authors to use one style or the other, as both are accepted. This isn’t an ideal situation because this leaves space for bike-shedding. Ideally we should enable all RuboCop rules to avoid style-related discussions, nitpicking, or back-and-forth in reviews. The GitLab Ruby style guide includes a non-exhaustive list of styles that commonly come up in reviews and are not enforced.
By default, we should not disable a RuboCop rule inline, because it negates agreed-upon code standards that the rule is attempting to apply to the codebase.
If you must use inline disable, provide the reason on the MR and ensure the reviewers agree before merging.
Additionally, we have dedicated test-specific style guides and best practices.
Typically it is better for the linting rules to be enforced programmatically as it reduces the aforementioned bike-shedding.
To that end, we encourage creation of new RuboCop rules in the codebase.
Before adding a new cop to enforce a given style, make sure to discuss it with your team.
We maintain cops across several Ruby code bases, and not all of them are
specific to the GitLab application.
When creating a new cop that could be applied to multiple applications, we encourage you
to add it to our
If the cop targets rules that only apply to the main GitLab application,
it should be added to GitLab instead.
A cop is in a grace period if it is enabled and has
Details: grace period defined in its TODO YAML configuration.
On the default branch, offenses from cops in the grace period do not fail the RuboCop CI job. Instead, the job notifies the
#f_rubocop Slack channel. However, on other branches, the RuboCop job fails.
A grace period can safely be lifted as soon as there are no warnings for 1 week in the
#f_rubocop channel on Slack.
- Enable the new cop in
.rubocop.yml(if not already done via
- Generate TODOs for the new cop.
Set the new cop to
- Create an issue to fix TODOs and encourage community contributions (via ~"quick win" and/or ~"Seeking community contributions"). See some examples.
- Create an issue to remove
grace periodafter 1 week of silence in the
#f_rubocopSlack channel. See an example.
When offenses are silenced for cops in the grace period,
#f_rubocop Slack channel receives a notification message every 2 hours.
To fix this issue:
- Find cops with silenced offenses in the linked CI job.
- Generate TODOs for these cops.
When the number of RuboCop exceptions exceeds the default
exclude-limit of 15,
we may want to resolve exceptions over multiple commits. To minimize confusion,
we should track our progress through the exception list.
The preferred way to generate the initial list or a list for specific RuboCop rules
is to run the Rake task
# Initial list bundle exec rake rubocop:todo:generate # List for specific RuboCop rules bundle exec rake 'rubocop:todo:generate[Gitlab/NamespacedClass,Lint/Syntax]'
This Rake task creates or updates the exception list in
example, the configuration for the RuboCop rule
Make sure to commit any changes in
.rubocop_todo/ after running the Rake task.
To reveal existing RuboCop exceptions in the code that have been excluded via
.rubocop_todo/**/*.yml, set the environment variable
This allows you to reveal existing RuboCop exceptions during your daily work cycle and fix them along the way.