Sha256: 9c04e57251c4fd85718c0a4660cff397d857fa457a8fae769110d08947442e81

Contents?: true

Size: 888 Bytes

Versions: 70

Compression:

Stored size: 888 Bytes

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Layout
      # 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

70 entries across 63 versions & 11 rubygems

Version Path
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/rubocop-1.35.1/lib/rubocop/cop/layout/space_after_not.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/rubocop-1.35.1/lib/rubocop/cop/layout/space_after_not.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/rubocop-1.35.1/lib/rubocop/cop/layout/space_after_not.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-1.35.1/lib/rubocop/cop/layout/space_after_not.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-1.31.2/lib/rubocop/cop/layout/space_after_not.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-1.52.1/lib/rubocop/cop/layout/space_after_not.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-1.36.0/lib/rubocop/cop/layout/space_after_not.rb
rubocop-1.56.2 lib/rubocop/cop/layout/space_after_not.rb
synctera_ruby_sdk-1.1.3 vendor/bundle/ruby/3.2.0/gems/rubocop-1.56.0/lib/rubocop/cop/layout/space_after_not.rb
synctera_ruby_sdk-1.1.2 vendor/bundle/ruby/3.2.0/gems/rubocop-1.56.0/lib/rubocop/cop/layout/space_after_not.rb
synctera_ruby_sdk-1.1.1 vendor/bundle/ruby/3.2.0/gems/rubocop-1.56.0/lib/rubocop/cop/layout/space_after_not.rb
sampero-0.1.0 vendor/bundle/ruby/3.2.0/gems/rubocop-1.56.1/lib/rubocop/cop/layout/space_after_not.rb
rubocop-1.56.1 lib/rubocop/cop/layout/space_after_not.rb
tursodb-0.1.0 vendor/bundle/ruby/3.2.0/gems/rubocop-1.56.0/lib/rubocop/cop/layout/space_after_not.rb
synctera_ruby_sdk-1.0.0 vendor/bundle/ruby/3.2.0/gems/rubocop-1.56.0/lib/rubocop/cop/layout/space_after_not.rb
rubocop-1.56.0 lib/rubocop/cop/layout/space_after_not.rb
rubocop-1.55.1 lib/rubocop/cop/layout/space_after_not.rb
rubocop-1.55.0 lib/rubocop/cop/layout/space_after_not.rb
rubocop-1.54.2 lib/rubocop/cop/layout/space_after_not.rb
mlh-rubocop-config-1.0.2 vendor/bundle/ruby/3.2.0/gems/rubocop-1.54.1/lib/rubocop/cop/layout/space_after_not.rb