Skip to content

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

  1. On the master branch.
  2. Create a migration rails g migration test_rubocop_error.
  3. Create a class inside the migration.
      class TestRubocopError < Gitlab::Database::Migration[2.1]
        class TestClass
        end
    
        def change
        end
      end
  4. Run rubocop with your migration file rubocop db/migrate/20230815144647_test_rubocop_error.rb.
  5. Observe an error An error occurred while Migration/VersionedMigrationClass cop was inspecting....
  6. Switch to the andysoiron/fix-cop-for-nested-classes-in-migrations branch.
  7. Run rubocop again rubocop db/migrate/20230815144647_test_rubocop_error.rb.
  8. 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.

Merge request reports

Loading