Sha256: 8251c8ea75a3dfdbbb355bcc1caa584a2d8850c2cadf847aa9d6f5c87de0e5a5

Contents?: true

Size: 1.07 KB

Versions: 6

Compression:

Stored size: 1.07 KB

Contents

# encoding: utf-8
# frozen_string_literal: true

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.'.freeze

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

          return unless method_name == :!
          return unless node.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.source_range.begin_pos)
            corrector.remove(space_range)
          end
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
rubocop-0.39.0 lib/rubocop/cop/style/space_after_not.rb
rubocop-0.38.0 lib/rubocop/cop/style/space_after_not.rb
rubocop-0.37.2 lib/rubocop/cop/style/space_after_not.rb
rubocop-0.37.1 lib/rubocop/cop/style/space_after_not.rb
rubocop-0.37.0 lib/rubocop/cop/style/space_after_not.rb
rubocop-0.36.0 lib/rubocop/cop/style/space_after_not.rb