Sha256: 6f76aef8ce99a41463fb919c07a544c94a6d93399c201df6be94244236a0a5c8

Contents?: true

Size: 1.13 KB

Versions: 17

Compression:

Stored size: 1.13 KB

Contents

# encoding: utf-8

module RuboCop
  module Cop
    # Common functionality for checking surrounding space.
    module SurroundingSpace
      def space_between?(t1, t2)
        between = Parser::Source::Range.new(t1.pos.source_buffer,
                                            t1.pos.end_pos,
                                            t2.pos.begin_pos).source

        # 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.
        between =~ /^\s/
      end

      def index_of_first_token(node)
        b = node.loc.expression.begin
        token_table[[b.line, b.column]]
      end

      def index_of_last_token(node)
        e = node.loc.expression.end
        (0...e.column).to_a.reverse.find do |c|
          ix = token_table[[e.line, 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, t.pos.column]] = ix
          end
          table
        end
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 2 rubygems

Version Path
rubyjobbuilderdsl-0.0.2 vendor/bundle/ruby/2.1.0/gems/rubocop-0.26.0/lib/rubocop/cop/mixin/surrounding_space.rb
rubyjobbuilderdsl-0.0.1 vendor/bundle/ruby/2.1.0/gems/rubocop-0.26.0/lib/rubocop/cop/mixin/surrounding_space.rb
rubocop-0.34.0 lib/rubocop/cop/mixin/surrounding_space.rb
rubocop-0.33.0 lib/rubocop/cop/mixin/surrounding_space.rb
rubocop-0.32.1 lib/rubocop/cop/mixin/surrounding_space.rb
rubocop-0.32.0 lib/rubocop/cop/mixin/surrounding_space.rb
rubocop-0.31.0 lib/rubocop/cop/mixin/surrounding_space.rb
rubocop-0.30.1 lib/rubocop/cop/mixin/surrounding_space.rb
rubocop-0.30.0 lib/rubocop/cop/mixin/surrounding_space.rb
rubocop-0.29.1 lib/rubocop/cop/mixin/surrounding_space.rb
rubocop-0.29.0 lib/rubocop/cop/mixin/surrounding_space.rb
rubocop-0.28.0 lib/rubocop/cop/mixin/surrounding_space.rb
rubocop-0.27.1 lib/rubocop/cop/mixin/surrounding_space.rb
rubocop-0.27.0 lib/rubocop/cop/mixin/surrounding_space.rb
rubocop-0.26.1 lib/rubocop/cop/mixin/surrounding_space.rb
rubocop-0.26.0 lib/rubocop/cop/mixin/surrounding_space.rb
rubocop-0.25.0 lib/rubocop/cop/mixin/surrounding_space.rb