Sha256: d58e62c3485049c3a0f8c25dadb50bbf10dbf0b17e5fd0efb0645ecbe47d6d01

Contents?: true

Size: 1.07 KB

Versions: 15

Compression:

Stored size: 1.07 KB

Contents

# encoding: utf-8

module RuboCop
  module Cop
    module Style
      # This cop checks for space after `!`.
      #
      # @example
      #   # bad
      #   ! something
      #
      #   # good
      #   !something
      class SpaceAfterNot < Cop
        MSG = 'Do not leave space between `!` and its argument.'

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

          return unless method_name == :!
          return unless node.loc.expression.source =~ /^!\s+\w+/

          # TODO: Improve source range to highlight the redundant whitespace.
          add_offense(node, :selector)
        end

        def autocorrect(node)
          @corrections << lambda do |corrector|
            receiver, _method_name, *_args = *node
            space_range =
              Parser::Source::Range.new(node.loc.selector.source_buffer,
                                        node.loc.selector.end_pos,
                                        receiver.loc.expression.begin_pos)
            corrector.remove(space_range)
          end
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 2 rubygems

Version Path
rubyjobbuilderdsl-0.0.2 vendor/bundle/ruby/2.1.0/gems/rubocop-0.26.0/lib/rubocop/cop/style/space_after_not.rb
rubyjobbuilderdsl-0.0.1 vendor/bundle/ruby/2.1.0/gems/rubocop-0.26.0/lib/rubocop/cop/style/space_after_not.rb
rubocop-0.30.1 lib/rubocop/cop/style/space_after_not.rb
rubocop-0.30.0 lib/rubocop/cop/style/space_after_not.rb
rubocop-0.29.1 lib/rubocop/cop/style/space_after_not.rb
rubocop-0.29.0 lib/rubocop/cop/style/space_after_not.rb
rubocop-0.28.0 lib/rubocop/cop/style/space_after_not.rb
rubocop-0.27.1 lib/rubocop/cop/style/space_after_not.rb
rubocop-0.27.0 lib/rubocop/cop/style/space_after_not.rb
rubocop-0.26.1 lib/rubocop/cop/style/space_after_not.rb
rubocop-0.26.0 lib/rubocop/cop/style/space_after_not.rb
rubocop-0.25.0 lib/rubocop/cop/style/space_after_not.rb
rubocop-0.24.1 lib/rubocop/cop/style/space_after_not.rb
rubocop-0.24.0 lib/rubocop/cop/style/space_after_not.rb
rubocop-0.23.0 lib/rubocop/cop/style/space_after_not.rb