lib/rubocop/cop/mixin/negative_conditional.rb in rubocop-0.42.0 vs lib/rubocop/cop/mixin/negative_conditional.rb in rubocop-0.43.0
- old
+ new
@@ -4,22 +4,22 @@
module RuboCop
module Cop
# Some common code shared between FavorUnlessOverNegatedIf and
# FavorUntilOverNegatedWhile.
module NegativeConditional
- def self.included(mod)
- mod.def_node_matcher :single_negative?, '(send !(send _ :!) :!)'
- end
+ extend NodePattern::Macros
+ include IfNode
+ def_node_matcher :single_negative?, '(send !(send _ :!) :!)'
+
def check_negative_conditional(node)
condition, _body, _rest = *node
# Look at last expression of contents if there are parentheses
# around condition.
- condition = condition.children.last while condition.type == :begin
+ condition = condition.children.last while condition.begin_type?
- return unless single_negative?(condition) &&
- !(node.loc.respond_to?(:else) && node.loc.else)
+ return unless single_negative?(condition) && !if_else?(node)
add_offense(node, :expression)
end
end
end