Sha256: a86a866d0913682b73df7f7620ba18e0485a03e70a7b4aa58c4f1c584d7ce6d5

Contents?: true

Size: 906 Bytes

Versions: 11

Compression:

Stored size: 906 Bytes

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Layout
      # This cop checks for space after `!`.
      #
      # @example
      #   # bad
      #   ! something
      #
      #   # good
      #   !something
      class SpaceAfterNot < Cop
        include RangeHelp

        MSG = 'Do not leave space between `!` and its argument.'.freeze

        def on_send(node)
          return unless node.keyword_bang? && whitespace_after_operator?(node)

          add_offense(node)
        end

        def whitespace_after_operator?(node)
          node.receiver.loc.column - node.loc.column > 1
        end

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

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
rubocop-0.58.2 lib/rubocop/cop/layout/space_after_not.rb
rubocop-0.58.1 lib/rubocop/cop/layout/space_after_not.rb
rubocop-0.58.0 lib/rubocop/cop/layout/space_after_not.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.4.0/gems/rubocop-0.57.2/lib/rubocop/cop/layout/space_after_not.rb
rubocop-0.57.2 lib/rubocop/cop/layout/space_after_not.rb
rubocop-0.57.1 lib/rubocop/cop/layout/space_after_not.rb
rubocop-0.57.0 lib/rubocop/cop/layout/space_after_not.rb
rubocop-0.56.0 lib/rubocop/cop/layout/space_after_not.rb
rubocop-0.55.0 lib/rubocop/cop/layout/space_after_not.rb
rubocop-0.54.0 lib/rubocop/cop/layout/space_after_not.rb
rubocop-0.53.0 lib/rubocop/cop/layout/space_after_not.rb