Skip to content

Commit

Permalink
[Fix rubocop#7791] Fix an error for Layout/BlockEndNewline
Browse files Browse the repository at this point in the history
Fixes rubocop#7791.

This PR fixes an error on auto-correction for `Layout/BlockEndNewline`
when `}` of multiline block without processing is not on its own line.
  • Loading branch information
koic committed Mar 11, 2020
1 parent 03a58c9 commit 954568a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -11,6 +11,7 @@
* [#7779](https://github.com/rubocop-hq/rubocop/issues/7779): Fix a false positive for `Style/MultilineMethodCallIndentation` when using Ruby 2.7's numbered parameter. ([@koic][])
* [#7733](https://github.com/rubocop-hq/rubocop/issues/7733): Fix rubocop-junit-formatter imcompatibility XML for JUnit formatter. ([@koic][])
* [#7767](https://github.com/rubocop-hq/rubocop/issues/7767): Skip array literals in `Style/HashTransformValues` and `Style/HashTransformKeys`. ([@tejasbubane][])
* [#7791](https://github.com/rubocop-hq/rubocop/issues/7791): Fix an error on auto-correction for `Layout/BlockEndNewline` when `}` of multiline block without processing is not on its own line. ([@koic][])

## 0.80.1 (2020-02-29)

Expand Down
8 changes: 5 additions & 3 deletions lib/rubocop/cop/layout/block_end_newline.rb
Expand Up @@ -52,9 +52,11 @@ def message(node)
end

def delimiter_range(node)
Parser::Source::Range.new(node.loc.expression.source_buffer,
node.children.last.loc.expression.end_pos,
node.loc.expression.end_pos)
Parser::Source::Range.new(
node.loc.expression.source_buffer,
node.children.compact.last.loc.expression.end_pos,
node.loc.expression.end_pos
)
end
end
end
Expand Down
15 changes: 15 additions & 0 deletions spec/rubocop/cop/layout/block_end_newline_spec.rb
Expand Up @@ -44,4 +44,19 @@
}
RUBY
end

it 'registers an offense and corrects when `}` of multiline block ' \
'without processing is not on its own line' do
expect_offense(<<~RUBY)
test {
|foo| }
^ Expression at 2, 9 should be on its own line.
RUBY

expect_correction(<<~RUBY)
test {
|foo|
}
RUBY
end
end

0 comments on commit 954568a

Please sign in to comment.