Skip to content

Commit

Permalink
Refactor EmptyCaseCondition#on_case
Browse files Browse the repository at this point in the history
  • Loading branch information
marcandre committed Jun 18, 2020
1 parent 38df07a commit 2b7d41a
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions lib/rubocop/cop/style/empty_case_condition.rb
Expand Up @@ -43,13 +43,15 @@ class EmptyCaseCondition < Cop

def on_case(case_node)
return if case_node.condition
return if case_node.when_branches.any? do |when_branch|
when_branch.each_descendant.any?(&:return_type?)
end

if (else_branch = case_node.else_branch)
return if else_branch.return_type? ||
else_branch.each_descendant.any?(&:return_type?)
branch_bodies = [
*case_node.when_branches.map(&:body),
case_node.else_branch
].compact

return if branch_bodies.any? do |body|
body.return_type? ||
body.each_descendant.any?(&:return_type?)
end

add_offense(case_node, location: :keyword)
Expand Down

0 comments on commit 2b7d41a

Please sign in to comment.