Sha256: 23b95ff70274f06762439c6e66893f2eba4d9ea653ad3cfa46952a8f0a0f4cc2

Contents?: true

Size: 1.07 KB

Versions: 19

Compression:

Stored size: 1.07 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    # Common functionality for checking surrounding space.
    module SurroundingSpace
      def space_between?(t1, _t2)
        # Check if the range between the tokens starts with a space. It can
        # contain other characters, e.g. a unary plus, but it must start with
        # space.
        t1.pos.source_buffer.source.match(/\G\s/, t1.pos.end_pos)
      end

      def index_of_first_token(node)
        range = node.source_range
        token_table[range.line][range.column]
      end

      def index_of_last_token(node)
        range = node.source_range
        table_row = token_table[range.last_line]
        (0...range.last_column).reverse_each do |c|
          ix = table_row[c]
          return ix if ix
        end
      end

      def token_table
        @token_table ||= begin
          table = {}
          @processed_source.tokens.each_with_index do |t, ix|
            table[t.pos.line] ||= {}
            table[t.pos.line][t.pos.column] = ix
          end
          table
        end
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 2 rubygems

Version Path
dirwatch-0.0.9 vendor/bundle/ruby/2.5.0/gems/rubocop-0.46.0/lib/rubocop/cop/mixin/surrounding_space.rb
dirwatch-0.0.8 vendor/bundle/ruby/2.5.0/gems/rubocop-0.46.0/lib/rubocop/cop/mixin/surrounding_space.rb
dirwatch-0.0.6 vendor/bundle/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cop/mixin/surrounding_space.rb
dirwatch-0.0.5 vendor/bundle/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cop/mixin/surrounding_space.rb
dirwatch-0.0.4 vendor/bundle/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cop/mixin/surrounding_space.rb
dirwatch-0.0.3 vendor/bundle/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cop/mixin/surrounding_space.rb
dirwatch-0.0.2 vendor/bundle/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cop/mixin/surrounding_space.rb
rubocop-0.51.0 lib/rubocop/cop/mixin/surrounding_space.rb
rubocop-0.50.0 lib/rubocop/cop/mixin/surrounding_space.rb
rubocop-0.49.1 lib/rubocop/cop/mixin/surrounding_space.rb
rubocop-0.49.0 lib/rubocop/cop/mixin/surrounding_space.rb
rubocop-0.48.1 lib/rubocop/cop/mixin/surrounding_space.rb
rubocop-0.48.0 lib/rubocop/cop/mixin/surrounding_space.rb
rubocop-0.47.1 lib/rubocop/cop/mixin/surrounding_space.rb
rubocop-0.47.0 lib/rubocop/cop/mixin/surrounding_space.rb
rubocop-0.46.0 lib/rubocop/cop/mixin/surrounding_space.rb
rubocop-0.45.0 lib/rubocop/cop/mixin/surrounding_space.rb
rubocop-0.44.1 lib/rubocop/cop/mixin/surrounding_space.rb
rubocop-0.44.0 lib/rubocop/cop/mixin/surrounding_space.rb