Sha256: 45ec3fb31d6208712d585caccfe03e83fb41ed3b4ba54ad0cf028f5ab639660f

Contents?: true

Size: 818 Bytes

Versions: 8

Compression:

Stored size: 818 Bytes

Contents

# encoding: utf-8

module RuboCop
  module Cop
    module Style
      # This cop checks for uses if the keyword *not* instead of !.
      class Not < Cop
        include AutocorrectUnlessChangingAST

        MSG = 'Use `!` instead of `not`.'

        def on_send(node)
          _receiver, method_name, *args = *node

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

          add_offense(node, :selector)
        end

        private

        def correction(node)
          lambda do |corrector|
            old_source = node.loc.expression.source
            new_source = old_source.sub(/not\s+/, '!')
            corrector.replace(node.loc.expression, new_source)
          end
        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/not.rb
rubyjobbuilderdsl-0.0.1 vendor/bundle/ruby/2.1.0/gems/rubocop-0.26.0/lib/rubocop/cop/style/not.rb
rubocop-0.26.1 lib/rubocop/cop/style/not.rb
rubocop-0.26.0 lib/rubocop/cop/style/not.rb
rubocop-0.25.0 lib/rubocop/cop/style/not.rb
rubocop-0.24.1 lib/rubocop/cop/style/not.rb
rubocop-0.24.0 lib/rubocop/cop/style/not.rb
rubocop-0.23.0 lib/rubocop/cop/style/not.rb