Sha256: 39e148ee5ad2eb22f1d75bbb5f20bff6c49deaa2d3e3bdaa528d8270aa18d81e

Contents?: true

Size: 1001 Bytes

Versions: 13

Compression:

Stored size: 1001 Bytes

Contents

# 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)
          return unless node.keyword_bang? && whitespace_after_bang_op?(node)

          add_offense(node, :expression)
        end

        def whitespace_after_bang_op?(node)
          receiver, _method_name, *_args = *node
          receiver.loc.column - node.loc.column > 1
        end

        def autocorrect(node)
          lambda do |corrector|
            receiver, _method_name, *_args = *node
            space_range = range_between(node.loc.selector.end_pos,
                                        receiver.source_range.begin_pos)
            corrector.remove(space_range)
          end
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 2 rubygems

Version Path
dirwatch-0.0.9 vendor/bundle/ruby/2.5.0/gems/rubocop-0.46.0/lib/rubocop/cop/style/space_after_not.rb
dirwatch-0.0.8 vendor/bundle/ruby/2.5.0/gems/rubocop-0.46.0/lib/rubocop/cop/style/space_after_not.rb
dirwatch-0.0.6 vendor/bundle/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cop/style/space_after_not.rb
dirwatch-0.0.5 vendor/bundle/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cop/style/space_after_not.rb
dirwatch-0.0.4 vendor/bundle/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cop/style/space_after_not.rb
dirwatch-0.0.3 vendor/bundle/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cop/style/space_after_not.rb
dirwatch-0.0.2 vendor/bundle/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cop/style/space_after_not.rb
rubocop-0.47.1 lib/rubocop/cop/style/space_after_not.rb
rubocop-0.47.0 lib/rubocop/cop/style/space_after_not.rb
rubocop-0.46.0 lib/rubocop/cop/style/space_after_not.rb
rubocop-0.45.0 lib/rubocop/cop/style/space_after_not.rb
rubocop-0.44.1 lib/rubocop/cop/style/space_after_not.rb
rubocop-0.44.0 lib/rubocop/cop/style/space_after_not.rb