Sha256: 4be2edac844acb57d13402d34c391c0c3c9098ee9b3ebc24a81f035cb01dab23

Contents?: true

Size: 1.05 KB

Versions: 9

Compression:

Stored size: 1.05 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)
          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

9 entries across 9 versions & 1 rubygems

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