Sha256: c6bcd6b0965ec86d8e09693ae281a87ef7bebeedaca7d41c7039494e2346c637

Contents?: true

Size: 772 Bytes

Versions: 6

Compression:

Stored size: 772 Bytes

Contents

# encoding: utf-8
# frozen_string_literal: true

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

      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

        return unless single_negative?(condition) &&
                      !(node.loc.respond_to?(:else) && node.loc.else)

        add_offense(node, :expression)
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
fluent-plugin-detect-memb-exceptions-0.0.2 vendor/bundle/ruby/2.0.0/gems/rubocop-0.42.0/lib/rubocop/cop/mixin/negative_conditional.rb
fluent-plugin-detect-memb-exceptions-0.0.1 vendor/bundle/ruby/2.0.0/gems/rubocop-0.42.0/lib/rubocop/cop/mixin/negative_conditional.rb
rubocop-0.42.0 lib/rubocop/cop/mixin/negative_conditional.rb
rubocop-0.41.2 lib/rubocop/cop/mixin/negative_conditional.rb
rubocop-0.41.1 lib/rubocop/cop/mixin/negative_conditional.rb
rubocop-0.41.0 lib/rubocop/cop/mixin/negative_conditional.rb