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 #10890] Fix an error for Layout/BlockEndNewline when multi-lineblocks with lambda literals #10891

Closed
wants to merge 1 commit into from
Closed
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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#10890](https://github.com/rubocop/rubocop/issue/10890): Fix an error for `Layout/BlockEndNewline` when multi-line blocks with lambda literals. ([@ydah][])
3 changes: 2 additions & 1 deletion lib/rubocop/cop/layout/block_end_newline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ def message(node)
end

def last_heredoc_argument(node)
return unless (arguments = node&.arguments)
return unless node&.send_type?
dvandersluis marked this conversation as resolved.
Show resolved Hide resolved
return unless (arguments = node.arguments)

heredoc = arguments.reverse.detect(&:heredoc?)
return heredoc if heredoc
Expand Down
16 changes: 16 additions & 0 deletions spec/rubocop/cop/layout/block_end_newline_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,22 @@
RUBY
end


it 'registers an offense and corrects when multiline block `}` is not on its own line' \
'with lambda literal `->`.' do
expect_offense(<<~RUBY)
-> {
nil }
^ Expression at 2, 7 should be on its own line.
RUBY

expect_correction(<<~RUBY)
-> {
nil
}
RUBY
end

it 'registers an offense and corrects when `}` of multiline block ' \
'without processing is not on its own line' do
expect_offense(<<~RUBY)
Expand Down