Skip to content

Commit

Permalink
[Fix rubocop#10890] Fix an error for Layout/BlockEndNewline when mu…
Browse files Browse the repository at this point in the history
…lti-line blocks with lambda literals

Fix: rubocop#10890
  • Loading branch information
ydah committed Aug 9, 2022
1 parent 4f9cc54 commit c99e7d2
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
@@ -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
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?
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
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

0 comments on commit c99e7d2

Please sign in to comment.