Skip to content

Commit

Permalink
Merge pull request #8750 from koic/fix_error_for_style_multiline_when…
Browse files Browse the repository at this point in the history
…_then

Fix an incorrect auto-correct for `Style/MultilineWhenThen`
  • Loading branch information
koic committed Sep 21, 2020
2 parents 760d98b + c5e6105 commit 4d6e725
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -11,6 +11,7 @@
* [#8740](https://github.com/rubocop-hq/rubocop/issues/8740): Fix a false positive for `Style/HashAsLastArrayItem` when the hash is in an implicit array. ([@dvandersluis][])
* [#8739](https://github.com/rubocop-hq/rubocop/issues/8739): Fix an error for `Lint/UselessTimes` when using empty block argument. ([@koic][])
* [#8742](https://github.com/rubocop-hq/rubocop/issues/8742): Fix some assignment counts for `Metrics/AbcSize`. ([@marcandre][])
* [#8750](https://github.com/rubocop-hq/rubocop/pull/8750): Fix an incorrect auto-correct for `Style/MultilineWhenThen` when line break for multiple condidate values of `when` statement. ([@koic][])

### Changes

Expand Down
1 change: 1 addition & 0 deletions lib/rubocop/cop/style/multiline_when_then.rb
Expand Up @@ -58,6 +58,7 @@ def on_when(node)
private

def require_then?(when_node)
return true if when_node.conditions.count >= 2
return false unless when_node.body

when_node.loc.line == when_node.body.loc.line
Expand Down
9 changes: 9 additions & 0 deletions spec/rubocop/cop/style/multiline_when_then_spec.rb
Expand Up @@ -136,4 +136,13 @@
end
RUBY
end

it 'does not register an offense when line break for multiple condidate values of `when`' do
expect_no_offenses(<<~RUBY)
case foo
when bar,
baz then do_something
end
RUBY
end
end

0 comments on commit 4d6e725

Please sign in to comment.