Skip to content

Commit

Permalink
Merge pull request #12102 from koic/fix_an_error_for_style_lambda_call
Browse files Browse the repository at this point in the history
Fix an error for `Style/LambdaCall`
  • Loading branch information
koic committed Aug 8, 2023
2 parents 56b4edf + 57dd392 commit 235f749
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
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

0 comments on commit 235f749

Please sign in to comment.