Improve Rake/TopLevelMethodDefinition cop

What does this MR do and why?

This is a follow-up to !184279 (comment 2429045740)

Summary of Changes

This change expands the scope of the Rake/TopLevelMethodDefinition RuboCop rule to check more files. Previously, the rule only checked .rake files, but now it will also check Rakefile files and potentially other files based on configuration. The rule warns against defining methods, classes, or modules at the top level in rake files because they can cause namespace collisions.

The implementation was simplified by removing the file extension check from the cop itself and instead relying on RuboCop's file inclusion configuration. The rule configuration was updated in both the main .rubocop.yml and the gems configuration to include **/Rakefile patterns. Tests were also updated to verify the rule works correctly with Rakefiles and other files that match the inclusion patterns.

References

Screenshots or screen recordings

Before After

How to set up and validate locally

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Dmitry Gruzd

Merge request reports

Loading