Sha256: aae8fab9a1ed6b333f75f9cd87fda5c0b3ee65234e4c1e220866956842ee7f98

Contents?: true

Size: 912 Bytes

Versions: 117

Compression:

Stored size: 912 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.source_range.begin_pos - node.source_range.begin_pos > 1
        end
      end
    end
  end
end

Version data entries

117 entries across 117 versions & 8 rubygems

Version Path
rubocop-1.69.0 lib/rubocop/cop/layout/space_after_not.rb
rubocop-1.68.0 lib/rubocop/cop/layout/space_after_not.rb
rubocop-1.67.0 lib/rubocop/cop/layout/space_after_not.rb
rubocop-1.66.1 lib/rubocop/cop/layout/space_after_not.rb
rubocop-1.66.0 lib/rubocop/cop/layout/space_after_not.rb
rubocop-1.65.1 lib/rubocop/cop/layout/space_after_not.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/rubocop-1.64.1/lib/rubocop/cop/layout/space_after_not.rb
rubocop-1.65.0 lib/rubocop/cop/layout/space_after_not.rb
katalyst-govuk-formbuilder-1.9.2 vendor/bundle/ruby/3.3.0/gems/rubocop-1.64.1/lib/rubocop/cop/layout/space_after_not.rb
rubocop-1.64.1 lib/rubocop/cop/layout/space_after_not.rb
rubocop-1.63.4 lib/rubocop/cop/layout/space_after_not.rb
rubocop-1.63.3 lib/rubocop/cop/layout/space_after_not.rb
rubocop-1.63.2 lib/rubocop/cop/layout/space_after_not.rb
harbr-2.8.1 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/layout/space_after_not.rb
rubocop-1.63.1 lib/rubocop/cop/layout/space_after_not.rb
rubocop-1.63.0 lib/rubocop/cop/layout/space_after_not.rb
bison-0.1.0 vendor/bundle/ruby/3.2.0/gems/rubocop-1.62.1/lib/rubocop/cop/layout/space_after_not.rb
rubocop-1.62.1 lib/rubocop/cop/layout/space_after_not.rb
rubocop-1.62.0 lib/rubocop/cop/layout/space_after_not.rb
rubocop-1.61.0 lib/rubocop/cop/layout/space_after_not.rb