Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Ruby 2.7's numbered parameter for Lint/SafeNavigationChain #7784

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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