Sha256: 3ca2104099aec782f1e79c4bef5452c1299cd6ef3fd2a762bb1b68618c806406

Contents?: true

Size: 857 Bytes

Versions: 51

Compression:

Stored size: 857 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.'

        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

51 entries across 51 versions & 5 rubygems

Version Path
plaid-14.13.0 vendor/bundle/ruby/3.0.0/gems/rubocop-0.91.1/lib/rubocop/cop/layout/space_after_not.rb
plaid-14.12.1 vendor/bundle/ruby/3.0.0/gems/rubocop-0.91.1/lib/rubocop/cop/layout/space_after_not.rb
plaid-14.12.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.91.1/lib/rubocop/cop/layout/space_after_not.rb
plaid-14.11.1 vendor/bundle/ruby/2.6.0/gems/rubocop-0.91.1/lib/rubocop/cop/layout/space_after_not.rb
plaid-14.10.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.91.1/lib/rubocop/cop/layout/space_after_not.rb
plaid-14.7.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.91.1/lib/rubocop/cop/layout/space_after_not.rb
rubocop-1.20.0 lib/rubocop/cop/layout/space_after_not.rb
rubocop-1.19.1 lib/rubocop/cop/layout/space_after_not.rb
rails_mini_profiler-0.2.0 vendor/bundle/ruby/3.0.0/gems/rubocop-1.18.3/lib/rubocop/cop/layout/space_after_not.rb
rubocop-1.19.0 lib/rubocop/cop/layout/space_after_not.rb
rubocop-1.18.4 lib/rubocop/cop/layout/space_after_not.rb
rubocop-1.18.3 lib/rubocop/cop/layout/space_after_not.rb
rubocop-1.18.2 lib/rubocop/cop/layout/space_after_not.rb
rubocop-1.18.1 lib/rubocop/cop/layout/space_after_not.rb
rubocop-1.18.0 lib/rubocop/cop/layout/space_after_not.rb
rubocop-1.17.0 lib/rubocop/cop/layout/space_after_not.rb
rubocop-1.16.1 lib/rubocop/cop/layout/space_after_not.rb
rubocop-1.16.0 lib/rubocop/cop/layout/space_after_not.rb
rubocop-1.15.0 lib/rubocop/cop/layout/space_after_not.rb
cocRb-0.1.0 .bundle/ruby/3.0.0/gems/rubocop-1.14.0/lib/rubocop/cop/layout/space_after_not.rb