Fix cop for classes inside migrations
What does this MR do and why?
This fixes an error that appears when a migration contains a class that does not have a parent class. I found this error working on this migration: !122850 (diffs)
How to set up and validate locally
- On the
master
branch. - Create a migration
rails g migration test_rubocop_error
. - Create a class inside the migration.
class TestRubocopError < Gitlab::Database::Migration[2.1] class TestClass end def change end end
- Run rubocop with your migration file
rubocop db/migrate/20230815144647_test_rubocop_error.rb
. - Observe an error
An error occurred while Migration/VersionedMigrationClass cop was inspecting...
. - Switch to the
andysoiron/fix-cop-for-nested-classes-in-migrations
branch. - Run rubocop again
rubocop db/migrate/20230815144647_test_rubocop_error.rb
. - Observe a rubocop failure
Lint/EmptyClass: Empty class detected.
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.