Skip to content

Commit

Permalink
Make Style/PreferredHashMethods aware of safe navigation operator
Browse files Browse the repository at this point in the history
  • Loading branch information
hoshinotsuyoshi committed Feb 9, 2019
1 parent a285622 commit 5fc114c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/rubocop/cop/style/preferred_hash_methods.rb
Expand Up @@ -41,6 +41,7 @@ def on_send(node)

add_offense(node, location: :selector)
end
alias on_csend on_send

def autocorrect(node)
lambda do |corrector|
Expand Down
9 changes: 9 additions & 0 deletions spec/rubocop/cop/style/preferred_hash_methods_spec.rb
Expand Up @@ -24,6 +24,15 @@
RUBY
end

context 'when using safe navigation operator', :ruby23 do
it 'registers an offense for has_value? with one arg' do
expect_offense(<<-RUBY.strip_indent)
o&.has_value?(o)
^^^^^^^^^^ Use `Hash#value?` instead of `Hash#has_value?`.
RUBY
end
end

it 'accepts has_value? with no args' do
expect_no_offenses('o.has_value?')
end
Expand Down

0 comments on commit 5fc114c

Please sign in to comment.