Skip to content

Commit

Permalink
Support Ruby 2.7's numbered parameter for Lint/SafeNavigationChain
Browse files Browse the repository at this point in the history
This PR supports Ruby 2.7's numbered parameter for `Lint/SafeNavigationChain`.
  • Loading branch information
koic committed Mar 19, 2020
1 parent 8633992 commit 212c12d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -9,6 +9,7 @@
* [#7783](https://github.com/rubocop-hq/rubocop/pull/7783): Support Ruby 2.7's numbered parameter for `Style/RedundantSort`. ([@koic][])
* [#7795](https://github.com/rubocop-hq/rubocop/issues/7795): Make `Layout/EmptyLineAfterGuardClause` aware of case where `and` or `or` is used before keyword that break control (e.g. `and return`). ([@koic][])
* [#7786](https://github.com/rubocop-hq/rubocop/pull/7786): Support Ruby 2.7's pattern match for `Layout/ElseAlignment` cop. ([@koic][])
* [#7784](https://github.com/rubocop-hq/rubocop/pull/7784): Support Ruby 2.7's numbered parameter for `Lint/SafeNavigationChain`. ([@koic][])

### Bug fixes

Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/lint/safe_navigation_chain.rb
Expand Up @@ -32,7 +32,7 @@ class SafeNavigationChain < Cop
def_node_matcher :bad_method?, <<~PATTERN
{
(send $(csend ...) $_ ...)
(send $(block (csend ...) ...) $_ ...)
(send $({block numblock} (csend ...) ...) $_ ...)
}
PATTERN

Expand Down
11 changes: 11 additions & 0 deletions spec/rubocop/cop/lint/safe_navigation_chain_spec.rb
Expand Up @@ -89,6 +89,17 @@
RUBY
end

context '>= Ruby 2.7', :ruby27 do
it 'registers an offense for ordinary method chain exists after ' \
'safe navigation method call with a block using numbered parameter' do
expect_offense(<<~RUBY)
something
x&.select { foo(_1) }.bar
^^^^ Do not chain ordinary method call after safe navigation operator.
RUBY
end
end

it 'registers an offense for safe navigation with < operator' do
expect_offense(<<~RUBY)
x&.foo < bar
Expand Down

0 comments on commit 212c12d

Please sign in to comment.