123456789_123456789_123456789_123456789_123456789_

Module: RuboCop::Cop::NegativeConditional

Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Included In:
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, Macros
Defined in: lib/rubocop/cop/mixin/negative_conditional.rb

Overview

Some common code shared between NegatedIf and NegatedWhile cops.

Constant Summary

Instance Method Summary

Instance Method Details

#check_negative_conditional(node, message:, &block) (private)

[ GitHub ]

  
# File 'lib/rubocop/cop/mixin/negative_conditional.rb', line 20

def check_negative_conditional(node, message:, &block)
  condition = node.condition

  return if empty_condition?(condition)

  condition = condition.children.last while condition.begin_type?

  return unless single_negative?(condition)
  return if node.if_type? && node.else?

  add_offense(node, message: message, &block)
end

#empty_condition?(node) (private)

[ GitHub ]

  
# File 'lib/rubocop/cop/mixin/negative_conditional.rb', line 18

def_node_matcher :empty_condition?, '(begin)'

#single_negative?(node) (private)

[ GitHub ]

  
# File 'lib/rubocop/cop/mixin/negative_conditional.rb', line 15

def_node_matcher :single_negative?, '(send !(send _ :!) :!)'