Class: RuboCop::Cop::Workit::RedundantBooleanConditional

Inherits:
Base
  • Object
show all
Extended by:
AutoCorrector
Defined in:
lib/rubocop/cop/workit/redundant_boolean_conditional.rb

Overview

Checks for redundant boolean conditions.

Examples:

# bad
true if x == y

# good
x == y

Constant Summary collapse

MSG =
"This conditional expression can just be replaced by `%<replaced>s`."

Instance Method Summary collapse

Instance Method Details

#on_if(node) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/rubocop/cop/workit/redundant_boolean_conditional.rb', line 25

def on_if(node)
  return unless redundant?(node)

  add_offense(node, message: offense_message(node)) do |corrector|
    corrector.replace(node, replacement_condition(node))
  end
end

#true_or_false?(node) ⇒ Object



21
22
23
# File 'lib/rubocop/cop/workit/redundant_boolean_conditional.rb', line 21

def_node_matcher :true_or_false?, <<~RUBY
  ({:true :false})
RUBY