Skip to content

Add rake task rubocop:check:graceful

Peter Leitzen requested to merge pl-rubocop-rake-ci into master

What does this MR do and why?

This MR adds a new rake task rake rubocop:check:graceful which runs RuboCop checks in CI as usual but ignores offenses from "silenced" cop rules. We silence a cop if it is enabled has Details: grace period in the YAML configuration defined.

This new rake task is run on CI twice:

  • In scheduled pipelines via update-static-analysis-cache
    • In case of silenced offenses Slack is notified
  • On master or MRs with RuboCop-related changes via rubocop job
    • In case of silenced offenses Slack is NOT notified to avoid spam

See #370433 (comment 1059067801).

Silencing cop rules does not work with haml-lint. So each time we enable a cop with a grace period we need to either fix the offenses or disable the cop rule in .haml-lint.yml`.

Screenshots

update-static-analysis-cache - No offenses update-static-analysis-cache - Silenced offenses 📣 rubocop - No offenses rubocop - Silenced offenses rubocop - Active offense 🔴
https://gitlab.com/gitlab-org/gitlab/-/jobs/2991249901 Screenshot_from_2022-09-07_14-54-13 https://gitlab.com/gitlab-org/gitlab/-/jobs/2991158530 Screenshot_from_2022-09-07_14-53-59 https://gitlab.com/gitlab-org/gitlab/-/jobs/2991158530 Screenshot_from_2022-09-07_14-57-19 https://gitlab.com/gitlab-org/gitlab/-/jobs/2991249938 Screenshot_from_2022-09-07_14-58-32 https://gitlab.com/gitlab-org/gitlab/-/jobs/2991145665 Screenshot_from_2022-09-07_14-57-33
Slack notification
Screenshot_from_2022-09-01_17-56-09

How to set up and validate locally

# Run uncached to trigger potential warnings from cops - see below
# --cache false won't work with --parallel
rm -fr tmp/rubocop_cache 
bundle exec rake rubocop:check:graceful

# Enable some cop rules with TODOs and re-run

rm -fr tmp/rubocop_cache 
bundle exec rake rubocop:check:graceful

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Peter Leitzen

Merge request reports