Skip to content

Commit

Permalink
[Fix rubocop#757] Fix a false positive for Rails/ReflectionClassName
Browse files Browse the repository at this point in the history
Fixes rubocop#757.

This PR fixes a false positive for `Rails/ReflectionClassName`
when using Ruby 3.1's hash shorthand syntax.
  • Loading branch information
koic committed Aug 26, 2022
1 parent 6fc6d22 commit 6175e0c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
@@ -0,0 +1 @@
* [#757](https://github.com/rubocop/rubocop-rails/issues/757): Fix a false positive for `Rails/ReflectionClassName` when using Ruby 3.1's hash shorthand syntax. ([@koic][])
2 changes: 2 additions & 0 deletions lib/rubocop/cop/rails/reflection_class_name.rb
Expand Up @@ -34,6 +34,8 @@ class ReflectionClassName < Base

def on_send(node)
association_with_reflection(node) do |reflection_class_name|
next if reflection_class_name.value_omission?

add_offense(reflection_class_name.loc.expression)
end
end
Expand Down
10 changes: 10 additions & 0 deletions spec/rubocop/cop/rails/reflection_class_name_spec.rb
Expand Up @@ -80,4 +80,14 @@
belongs_to :account, class_name: :Account
RUBY
end

context 'Ruby >= 3.1', :ruby31 do
it 'does not register an offense when using shorthand syntax' do
expect_no_offenses(<<~RUBY)
class_name = 'Account'
has_many :accounts, class_name:
RUBY
end
end
end

0 comments on commit 6175e0c

Please sign in to comment.