Skip to content

Commit ba2d060

Browse files
committed
Only consider migration classes for MigrationClassName
1 parent 8813b04 commit ba2d060

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* [#657](https://github.com/rubocop/rubocop-rails/pull/657): Only consider migration classes for `Rails/MigrationClassName`. ([@sunny][])

lib/rubocop/cop/rails/migration_class_name.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,13 @@ module Rails
2020
#
2121
class MigrationClassName < Base
2222
extend AutoCorrector
23+
include MigrationsHelper
2324

2425
MSG = 'Replace with `%<corrected_class_name>s` that matches the file name.'
2526

2627
def on_class(node)
28+
return if in_migration?(node)
29+
2730
snake_class_name = to_snakecase(node.identifier.source)
2831

2932
return if snake_class_name == basename_without_timestamp

spec/rubocop/cop/rails/migration_class_name_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,17 @@ class CreateUsers < ActiveRecord::Migration[7.0]
1010
end
1111
RUBY
1212
end
13+
14+
context 'when defining another class' do
15+
it 'does not register an offense' do
16+
expect_no_offenses(<<~RUBY, filename)
17+
class CreateUsers < ActiveRecord::Migration[7.0]
18+
class Article < ActiveRecord::Base
19+
end
20+
end
21+
RUBY
22+
end
23+
end
1324
end
1425

1526
context 'when the class name does not match its file name' do

0 commit comments

Comments
 (0)