Sha256: dfd500c33518998416676c3e45b5579585a69ec07dc96fb96944f6c701c955e3

Contents?: true

Size: 897 Bytes

Versions: 22

Compression:

Stored size: 897 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 < Base
        include RangeHelp
        extend AutoCorrector

        MSG = 'Do not leave space between `!` and its argument.'
        RESTRICT_ON_SEND = %i[!].freeze

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

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

        private

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

Version data entries

22 entries across 22 versions & 4 rubygems

Version Path
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-1.26.0/lib/rubocop/cop/layout/space_after_not.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rubocop-1.26.0/lib/rubocop/cop/layout/space_after_not.rb
rubocop-1.29.1 lib/rubocop/cop/layout/space_after_not.rb
rubocop-1.29.0 lib/rubocop/cop/layout/space_after_not.rb
rubocop-1.28.2 lib/rubocop/cop/layout/space_after_not.rb
rubocop-1.28.1 lib/rubocop/cop/layout/space_after_not.rb
rubocop-1.28.0 lib/rubocop/cop/layout/space_after_not.rb
rubocop-1.27.0 lib/rubocop/cop/layout/space_after_not.rb
rubocop-1.26.1 lib/rubocop/cop/layout/space_after_not.rb
op_connect-0.1.2 vendor/bundle/ruby/3.1.0/gems/rubocop-1.26.0/lib/rubocop/cop/layout/space_after_not.rb
rubocop-1.26.0 lib/rubocop/cop/layout/space_after_not.rb
rubocop-1.25.1 lib/rubocop/cop/layout/space_after_not.rb
rubocop-1.25.0 lib/rubocop/cop/layout/space_after_not.rb
phillipug-foodie-0.1.0 .vendor/ruby/3.0.0/gems/rubocop-1.24.0/lib/rubocop/cop/layout/space_after_not.rb
rubocop-1.24.1 lib/rubocop/cop/layout/space_after_not.rb
rubocop-1.24.0 lib/rubocop/cop/layout/space_after_not.rb
rubocop-1.23.0 lib/rubocop/cop/layout/space_after_not.rb
rubocop-1.22.3 lib/rubocop/cop/layout/space_after_not.rb
rubocop-1.22.2 lib/rubocop/cop/layout/space_after_not.rb
rubocop-1.22.1 lib/rubocop/cop/layout/space_after_not.rb