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
-
MSG =
# File 'lib/rubocop/cop/mixin/negative_conditional.rb', line 10'Favor `%<inverse>s` over `%<current>s` for negative conditions.'
Instance Method Summary
- #check_negative_conditional(node, message:, &block) private
- #empty_condition?(node) private
- #single_negative?(node) private
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: , &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 _ :!) :!)'