Skip to content

Commit

Permalink
Refactor cop; call to_a on COMPARISON_OPERATORS
Browse files Browse the repository at this point in the history
  • Loading branch information
marcandre committed Jun 7, 2020
1 parent 3425ac1 commit 20f1231
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/rubocop/cop/style/redundant_conditional.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ module Style
class RedundantConditional < Cop
include Alignment

COMPARISON_OPERATORS = RuboCop::AST::Node::COMPARISON_OPERATORS
operators = RuboCop::AST::Node::COMPARISON_OPERATORS.to_a
COMPARISON_OPERATOR_MATCHER = "{:#{operators.join(' :')}}"

MSG = 'This conditional expression can just be replaced ' \
'by `%<msg>s`.'
Expand All @@ -54,11 +55,11 @@ def message(node)
end

def_node_matcher :redundant_condition?, <<~RUBY
(if (send _ {:#{COMPARISON_OPERATORS.join(' :')}} _) true false)
(if (send _ #{COMPARISON_OPERATOR_MATCHER} _) true false)
RUBY

def_node_matcher :redundant_condition_inverted?, <<~RUBY
(if (send _ {:#{COMPARISON_OPERATORS.join(' :')}} _) false true)
(if (send _ #{COMPARISON_OPERATOR_MATCHER} _) false true)
RUBY

def offense?(node)
Expand Down

0 comments on commit 20f1231

Please sign in to comment.