class RuboCop::Cop::Lint::DuplicateCaseCondition

end
do_something_else
when ‘second’
do_something
when ‘first
case x
# good
@example
end
do_something_else
when ’first’
do_something
when ‘first’
case x
# bad
@example
used in case ‘when’ expressions.
This cop checks that there are no repeated conditions

def on_case(case_node)

def on_case(case_node)
  case_node.when_branches.each_with_object([]) do |when_node, previous|
    when_node.each_condition do |condition|
      if repeated_condition?(previous, condition)
        add_offense(condition, :expression, MSG)
      end
    end
    previous.push(when_node.conditions)
  end
end

def repeated_condition?(previous, condition)

def repeated_condition?(previous, condition)
  previous.any? { |c| c.include?(condition) }
end