Skip to content

Commit 0bb3f22

Browse files
committed
[Fix #660] Fix a false positive for Rails/MigrationClassName
Fixes #660. This PR fixes a false positive for `Rails/MigrationClassName` when defining another class.
1 parent 8373c5a commit 0bb3f22

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* [#660](https://github.com/rubocop/rubocop-rails/issues/660): Fix a false positive for `Rails/MigrationClassName` when defining another class. ([@koic][])

lib/rubocop/cop/rails/migration_class_name.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class MigrationClassName < Base
2525
MSG = 'Replace with `%<corrected_class_name>s` that matches the file name.'
2626

2727
def on_class(node)
28-
return if in_migration?(node)
28+
return unless migration_class?(node)
2929

3030
snake_class_name = to_snakecase(node.identifier.source)
3131

spec/rubocop/cop/rails/migration_class_name_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@ class CreateUsers < ActiveRecord::Migration[7.0]
1212
end
1313

1414
context 'when defining another class' do
15+
it 'does not register an offense' do
16+
expect_no_offenses(<<~RUBY, filename)
17+
class Article < ActiveRecord::Base
18+
end
19+
20+
class CreateUsers < ActiveRecord::Migration[7.0]
21+
end
22+
RUBY
23+
end
24+
end
25+
26+
context 'when defining an inner class' do
1527
it 'does not register an offense' do
1628
expect_no_offenses(<<~RUBY, filename)
1729
class CreateUsers < ActiveRecord::Migration[7.0]

0 commit comments

Comments
 (0)