Sha256: 168a8dc5626c2309fbcdb1aa38aa366265525ca00c5cae62c6fe699c6ffe3c20

Contents?: true

Size: 796 Bytes

Versions: 9

Compression:

Stored size: 796 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)
          old_source = node.loc.expression.source
          new_source = old_source.sub(/not\s+/, '!')
          ->(corrector) { corrector.replace(node.loc.expression, new_source) }
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
rubocop-0.35.1 lib/rubocop/cop/style/not.rb
rubocop-0.35.0 lib/rubocop/cop/style/not.rb
rubocop-0.34.2 lib/rubocop/cop/style/not.rb
rubocop-0.34.1 lib/rubocop/cop/style/not.rb
rubocop-0.34.0 lib/rubocop/cop/style/not.rb
rubocop-0.33.0 lib/rubocop/cop/style/not.rb
rubocop-0.32.1 lib/rubocop/cop/style/not.rb
rubocop-0.32.0 lib/rubocop/cop/style/not.rb
rubocop-0.31.0 lib/rubocop/cop/style/not.rb