Skip to content

Fix remaining cop offenses for Performance/OpenStruct

Problem

In https://gitlab.com/gitlab-org/gitlab-styles/-/merge_requests/82 and !55899 (merged) we've introduced a new 👮 Performance/OpenStruct and enabled it in !57257 (merged) to encourage the use of Struct.new(..., keyword_init: true) instead of OpenStruct.new(...).

This MR enabled the 👮 so new offenses are prevented. Current offenses still needs to be fixed. This issue tracks its progress.

Proposed solution

Replace use of OpenStruct in production code (spec are excluded) to use Struct or similar solutions instead.

  1. Pick a file from The List below e.g. Guardfile
  2. Create a branch (e.g. rubocop-performance-openstruct-guardfile)
  3. Delete the file from .rubocop_manual_todo.yml
  4. Check occurences with RuboCop via bundle exec rubocop --auto-correct --only Performance/OpenStruct Guardfile
  5. Convert the use of OpenStruct.new(...) with Struct.new(..., keyword_init: true) or equivalent solution
  6. Commit and create a merge request adding Contributes to #325744 and static code analysis label
  7. Tick off the checkbox(es) and add the MR or mention this merge request in this issue
  8. 🎉

The list

  • Guardfile
  • app/finders/snippets_finder.rb
  • app/helpers/application_settings_helper.rb
  • !59956 (merged) - app/models/cycle_analytics/project_level_stage_adapter.rb
  • ee/lib/gitlab/graphql/aggregations/epics/epic_node.rb
  • ee/lib/gitlab/graphql/aggregations/epics/epic_node.rb
  • lib/api/wikis.rb
  • !58430 (merged) - lib/gitlab/ci/ansi2html.rb
  • !60086 (merged) - lib/gitlab/ci/reports/test_suite_comparer.rb
  • lib/gitlab/git/diff_collection.rb
  • lib/gitlab/import_export/after_export_strategies/base_after_export_strategy.rb
  • lib/gitlab/testing/request_inspector_middleware.rb
  • lib/mattermost/session.rb
Edited by Peter Leitzen