Add a Rubocop for overlapping methods in rake tasks

Description of the proposal

This change introduces a new RuboCop rule called Rake/TopLevelMethodDefinition that prevents method definitions directly in rake task files. The problem is that methods defined in rake tasks share the same namespace, which can cause conflicts when methods with the same name are defined in different rake files. For example, Fix gitlab:elastic:info rake task (!184278 - merged)

The solution is to move these methods into dedicated modules (like Search::RakeTask::Elastic or Search::RakeTask::Zoekt) instead of defining them directly in the rake task namespaces. The code includes examples of refactoring two rake files (elastic.rake and zoekt.rake) to follow this pattern by moving their helper methods into proper modules.

The change also adds tests for the new cop and updates the RuboCop configuration to enable this rule for rake files, with some existing files temporarily excluded via a "grace period" in the todo list.

#524561 (closed)

Check-list

  • Make sure this MR enables a static analysis check rule for new usage but ignores current offenses.
  • Mention this proposal in the relevant Slack channels (e.g. #development, #backend, #frontend).
  • The MR doesn't have significant objections, and is getting a majority of 👍 vs 👎 (remember that we don't need to reach a consensus).
  • (If applicable) One style is getting a majority of vote (compared to the other choice).
  • (If applicable) Update the MR with the chosen style.
  • Create a follow-up issue to fix the current offenses as a separate iteration: ISSUE_LINK
  • Follow the review process as usual.
  • Once approved and merged by a maintainer, mention it again:
    • In the relevant Slack channels (e.g. #development, #backend, #frontend).
    • (Optional depending on the impact of the change) In the Engineering Week in Review.

/cc @gitlab-org/maintainers/rails-backend

Edited by Dmitry Gruzd

Merge request reports

Loading