Sha256: 9fedaddea1568744fe2e0e468bfe718543d6de24f4189f0e01c3dc9d1cdc1fd3

Contents?: true

Size: 912 Bytes

Versions: 8

Compression:

Stored size: 912 Bytes

Contents

# encoding: utf-8

module RuboCop
  module Cop
    module Style
      # This cop checks for uses of double negation (!!) to convert something
      # to a boolean value. As this is both cryptic and usually redundant it
      # should be avoided.
      #
      # @example
      #
      #   # bad
      #   !!something
      #
      #   # good
      #   !something.nil?
      class DoubleNegation < Cop
        MSG = 'Avoid the use of double negation (`!!`).'

        def on_send(node)
          return unless not_node?(node)

          receiver, _method_name, *_args = *node

          add_offense(node, :selector) if not_node?(receiver)
        end

        private

        def not_node?(node)
          _receiver, method_name, *args = *node

          # ! does not take any arguments
          args.empty? && method_name == :! &&
            node.loc.selector.is?('!')
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
rubyjobbuilderdsl-0.0.2 vendor/bundle/ruby/2.1.0/gems/rubocop-0.26.0/lib/rubocop/cop/style/double_negation.rb
rubyjobbuilderdsl-0.0.1 vendor/bundle/ruby/2.1.0/gems/rubocop-0.26.0/lib/rubocop/cop/style/double_negation.rb
rubocop-0.26.1 lib/rubocop/cop/style/double_negation.rb
rubocop-0.26.0 lib/rubocop/cop/style/double_negation.rb
rubocop-0.25.0 lib/rubocop/cop/style/double_negation.rb
rubocop-0.24.1 lib/rubocop/cop/style/double_negation.rb
rubocop-0.24.0 lib/rubocop/cop/style/double_negation.rb
rubocop-0.23.0 lib/rubocop/cop/style/double_negation.rb