Upgrade gitlab-styles to 15.0.0 (RuboCop 1.92.1)

What does this MR do and why?

Upgrades gitlab-styles to 15.0.0, which brings RuboCop 1.92.1 and the latest RuboCop plugins. See the 15.0.0 release for its changes. It also sets RuboCop's TargetRubyVersion to 3.3, the minimum for GitLab 19.0 and for gitlab-styles 15.0.0.

The main reason for the upgrade: RuboCop 1.82.1+ computes its result-cache checksum before forking --parallel workers (https://github.com/rubocop/rubocop/commit/5245f3186). Without that, the weekly housekeeper:generate-rubocop-todos job misses every cached result and times out.

References

Changes in this MR
  • Gemfile, Gemfile.lock, Gemfile.next.lock: gitlab-styles ~> 15.0, locked with bundle lock --conservative --update for gitlab-styles and the 9 RuboCop gems it brings in, so only those 10 gems change. The sha256 checksums match RubyGems.
  • .rubocop.yml: TargetRubyVersion 3.2 → 3.3. RuboCop now parses with Prism. gems/config/rubocop.yml stays at 3.2 until the gems move to gitlab-styles 15.
  • .rubocop.yml: exclude config/puma.rb, a local copy of config/puma.rb.example that .gitignore ignores. Without it, local TODO regeneration adds entries that CI never sees.
  • rubocop/cop/api/entity_field_type.rb: upcase_first capitalized the parsed string in place. Prism's strings are frozen, so the cop raised FrozenError while correcting. It now returns a new string, and a spec example runs with Prism.
  • ee/app/views/groups/saml_providers/_test_button.html.haml: = return unless … → - return unless …. Prism rejects outputting return's value (Lint/Syntax: unexpected void value expression) in haml-lint's generated Ruby. The early return behaves the same; the view no longer writes a stray newline.
  • config/initializers/wikicloth_ruby_3_patch.rb, .haml-lint.yml: gitlab-styles 15.0.0 removes Cop/LineBreakAfterGuardClauses in favour of RuboCop's Layout/EmptyLineAfterGuardClause (gitlab-org/ruby/gems/gitlab-styles!296 (merged)), so remove its disable comments and its haml-lint ignored_cops entry, which RuboCop rejects as an unknown cop. The gems under gems/ lint with their own lockfiles and the released gitlab-styles, so theirs stay.
  • .rubocop.yml: load rubocop-rspec with plugins: instead of require:. rubocop-rspec 3.10 only loads its default config as a plugin. gems/config/rubocop.yml keeps require:, because each gem under gems/ runs RuboCop with its own lockfile, and those pin rubocop-rspec versions without plugin support.
  • spec/rubocop/formatter/graceful_formatter_spec.rb: the fake offense double gets disabled?: false. RuboCop 1.92's SimpleTextFormatter, which GracefulFormatter extends, now calls it.
  • spec/tasks/rubocop_rake_spec.rb: reset RuboCop::PathUtil around each todo:generate example. RuboCop 1.86 caches Dir.pwd for the whole process (https://github.com/rubocop/rubocop/commit/9ce111d38), so every example after the first searched the previous, deleted temporary directory and wrote no TODOs.
  • lib/tasks/rubocop.rake: the docs task finds each cop's gem in Gem.loaded_specs by install path, instead of matching the path with a regex. The regex only matched released gems such as gitlab-styles-14.1.0/, so with gitlab-styles from a git ref, as in this MR's dry run, its cops fell under a nil key and the task raised TypeError.
  • ee/app/views/projects/settings/merge_requests/_target_branch_rules_settings.html.haml: @target_branch_rules&.empty? → @target_branch_rules && @target_branch_rules.empty?, the Lint/SafeNavigationWithEmpty correction. It gives the same result when @target_branch_rules is nil, as in view specs that render without the controller. The rake task only scans Ruby files, so a TODO entry here would have to be added by hand.
  • ee/spec/lib/security/secret_detection/partner_tokens/generator/client_generator_spec.rb: the strings that assert a literal #{} in generated source are now %(…\#{…}…), with the same values. Lint/InterpolationCheck flags 3 more of them, and a TODO entry for the file would make its existing inline disable redundant, which the rake task can't see. The inline disable is removed.
  • .rubocop_todo/ (separate commit): regenerated with bundle exec rake rubocop:todo:generate on top of master, with the Ruby 3.3 target, and not edited by hand. 37 new TODO files, 11 grown and 10 shrunk. All new and grown lists are in the grace period. Cop/AvoidReturnFromBlocks, RSpec/ExampleStartingCharacter and RSpec/EmptyLineAfterSharedExample, which now also check _1 and it blocks, found no new offenses.
TODO generation time

The same full rake rubocop:todo:generate run locally (14 cores): 53 minutes with RuboCop 1.81.7 and about 9 minutes with RuboCop 1.92.1. With 1.81.7, the parent process's cache key differs from the parallel workers', so the serial pass re-inspects every file on one core. The scheduled housekeeper:generate-rubocop-todos job showed 0 hits / 54,478 misses. RuboCop 1.82.1+ computes the checksum before forking (https://github.com/rubocop/rubocop/commit/5245f3186).

Cops with new TODO files

All are in the grace period. Links go to the cop's page on docs.rubocop.org, or to its source at the version used when it has no docs page.

Cops that start running with this upgrade (12)

Cop Files
Capybara/RSpec/HaveContent 1253
Capybara/RSpec/NegationMatcher 1002
Capybara/RSpec/HaveSelector 604
Capybara/RSpec/NegationMatcherAfterVisit 140
Capybara/RSpec/SpecificMatcher 37
Capybara/FindAllFirst 32
Lint/CopDirectiveSyntax 31
Capybara/SpecificActions 28
InternalAffairs/ItblockHandler 19
GraphQL/DefaultForOptionalArgument 9
Capybara/RedundantWithinFind 8
GraphQL/UselessMethodOption 4

Existing cops with new offenses (25)

Cop Files
Layout/ExtraSpacing 113
Lint/RedundantCopDisableDirective 101
Style/HashAsLastArrayItem 87
Rails/Output 61
RSpec/EmptyLineAfterFinalLet 52
Style/EndlessMethod 37
Rails/Exit 32
Rails/Validation 21
GraphQL/OrderedFields 14
Rails/Presence 13
Layout/EmptyLinesAroundBlockBody 6
Rails/HasAndBelongsToMany 6
Layout/SpaceAroundOperators 5
Naming/FileName 5
Rails/AttributeDefaultBlockValue 4
Lint/UselessNumericOperation 3
RSpec/ExpectActual 3
Lint/UselessAssignment 2
Rails/RedundantAllowNil 2
Lint/InterpolationCheck 1
Cop/DestroyAll 1
Layout/SpaceInsideReferenceBrackets 1
Performance/ChainArrayAllocation 1
Rails/EnumHash 1
Rails/HttpPositionalArguments 1

Checklist

  • Verify upcoming release of gitlab-styles
    • Point to "Release" MR of gitlab-styles in Gemfile
    • rubocop job
      • Inspect any warnings/errors
      • (Optional) Generate TODOs for pending offenses
        • Put 🆕 cop rules (or if configuration is changed) in "grace period"
        • (Optional) Remove any offenses for disabled cops
      • (Optional) Autocorrect offenses (only if the changeset is small)
      • Compare the total runtime of rubocop --parallel scan with previous runs
    • Make sure CI passes and does not have "silenced offenses" 💚
    • Don't merge this MR yet!
    • Wait for gitlab-styles to be released
  • Upgrade released version of gitlab-styles
    • Make sure release is complete
    • Rephrase the title and MR description to match final upgrade
    • Point to released version in Gemfile
    • (Optional) Regenerate TODOs for new/changed cop rules
    • Make sure CI passes and does not have "silenced offenses" 💚
    • Let the MR being reviewed again and merged

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist.

After merge

  • Notify team members of the upgrade by creating an announcement in relevant Slack channels (#backend and #development) and Engineering Week In Review (EWIR).
Edited by Abdul Wadood

Merge request reports

Loading
Loading