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 an incorrect auto-correct for Style/MultilineWhenThen #8750

Merged
merged 1 commit into from Sep 21, 2020
Merged
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
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