Skip to content

Commit

Permalink
Remove redundant code for Style/MultilineWhenThen
Browse files Browse the repository at this point in the history
I noticed this in the implementation of #9834.
  • Loading branch information
koic committed Jun 5, 2021
1 parent 632e2f1 commit 73975f9
Showing 1 changed file with 2 additions and 11 deletions.
13 changes: 2 additions & 11 deletions lib/rubocop/cop/style/multiline_when_then.rb
Expand Up @@ -35,17 +35,7 @@ class MultilineWhenThen < Base
MSG = 'Do not use `then` for multiline `when` statement.'

def on_when(node)
# Without `then`, there's no offense
return unless node.then?

# Single line usage of `then` is not an offense
return if !node.children.last.nil? && !node.multiline?

# Requires `then` for write `when` and its body on the same line.
return if require_then?(node)

# For arrays and hashes there's no offense
return if accept_node_type?(node.body)
return if !node.then? || require_then?(node)

range = node.loc.begin
add_offense(range) do |corrector|
Expand All @@ -57,6 +47,7 @@ def on_when(node)

private

# Requires `then` for write `when` and its body on the same line.
def require_then?(when_node)
unless when_node.conditions.first.first_line == when_node.conditions.last.last_line
return true
Expand Down

0 comments on commit 73975f9

Please sign in to comment.