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

Fix an error for Style/LambdaCall #12102

Merged
merged 1 commit into from
Aug 8, 2023
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/fix_an_error_for_style_lambda_call.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#12102](https://github.com/rubocop/rubocop/pull/12102): Fix an error for `Style/LambdaCall` when using nested lambda call `x.().()`. ([@koic][])
5 changes: 5 additions & 0 deletions lib/rubocop/cop/style/lambda_call.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module Style
# lambda.(x, y)
class LambdaCall < Base
include ConfigurableEnforcedStyle
include IgnoredNode
extend AutoCorrector

MSG = 'Prefer the use of `%<prefer>s` over `%<current>s`.'
Expand All @@ -33,8 +34,12 @@ def on_send(node)
current = node.source

add_offense(node, message: format(MSG, prefer: prefer, current: current)) do |corrector|
next if part_of_ignored_node?(node)

opposite_style_detected
corrector.replace(node, prefer)

ignore_node(node)
end
else
correct_style_detected
Expand Down
12 changes: 12 additions & 0 deletions spec/rubocop/cop/style/lambda_call_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@
RUBY
end

it 'registers an offense for x.().()' do
expect_offense(<<~RUBY)
x.(a, b).(c)
^^^^^^^^^^^^ Prefer the use of `x.(a, b).call(c)` over `x.(a, b).(c)`.
^^^^^^^^ Prefer the use of `x.call(a, b)` over `x.(a, b)`.
RUBY

expect_correction(<<~RUBY)
x.(a, b).call(c)
RUBY
end

it 'registers an offense for correct + opposite' do
expect_offense(<<~RUBY)
x.call(a, b)
Expand Down