Module: RuboCop::Cop::SurroundingSpace
- Included in:
- SpaceInside, RuboCop::Cop::Style::SpaceAroundEqualsInParameterDefault, RuboCop::Cop::Style::SpaceInsideBlockBraces, RuboCop::Cop::Style::SpaceInsideHashLiteralBraces, RuboCop::Cop::Style::TrailingUnderscoreVariable
- Defined in:
- lib/rubocop/cop/mixin/surrounding_space.rb
Overview
Common functionality for checking surrounding space.
Instance Method Summary collapse
- #index_of_first_token(node) ⇒ Object
- #index_of_last_token(node) ⇒ Object
- #space_between?(t1, t2) ⇒ Boolean
- #token_table ⇒ Object
Instance Method Details
#index_of_first_token(node) ⇒ Object
19 20 21 22 |
# File 'lib/rubocop/cop/mixin/surrounding_space.rb', line 19 def index_of_first_token(node) b = node.source_range.begin token_table[b.line][b.column] end |
#index_of_last_token(node) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/rubocop/cop/mixin/surrounding_space.rb', line 24 def index_of_last_token(node) e = node.source_range.end (0...e.column).to_a.reverse_each do |c| ix = token_table[e.line][c] return ix if ix end end |
#space_between?(t1, t2) ⇒ Boolean
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/rubocop/cop/mixin/surrounding_space.rb', line 8 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 |
#token_table ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/rubocop/cop/mixin/surrounding_space.rb', line 32 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 |