Sha256: 7d6db42adb0839e61c2e8a0e701c691fb00beda939a4717ce211d85d8dfd0e30

Contents?: true

Size: 830 Bytes

Versions: 7

Compression:

Stored size: 830 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

7 entries across 7 versions & 1 rubygems

Version Path
rubocop-0.30.1 lib/rubocop/cop/style/not.rb
rubocop-0.30.0 lib/rubocop/cop/style/not.rb
rubocop-0.29.1 lib/rubocop/cop/style/not.rb
rubocop-0.29.0 lib/rubocop/cop/style/not.rb
rubocop-0.28.0 lib/rubocop/cop/style/not.rb
rubocop-0.27.1 lib/rubocop/cop/style/not.rb
rubocop-0.27.0 lib/rubocop/cop/style/not.rb