Module: Rubocop::Cop::Style::SpaceInside

Includes:
SurroundingSpace
Included in:
SpaceInsideBrackets, SpaceInsideParens
Defined in:
lib/rubocop/cop/style/surrounding_space.rb

Overview

Common functionality for checking for spaces inside various kinds of parentheses.

Constant Summary collapse

MSG =
'Space inside %s detected.'

Instance Method Summary collapse

Methods included from SurroundingSpace

#index_of_first_token, #index_of_last_token, #space_between?, #token_table

Instance Method Details

#investigate(processed_source) ⇒ Object



238
239
240
241
242
243
244
245
246
247
248
249
250
251
# File 'lib/rubocop/cop/style/surrounding_space.rb', line 238

def investigate(processed_source)
  @processed_source = processed_source
  left, right, kind = specifics
  processed_source.tokens.each_cons(2) do |t1, t2|
    if t1.type == left || t2.type == right
      if t2.pos.line == t1.pos.line && space_between?(t1, t2)
        range = Parser::Source::Range.new(processed_source.buffer,
                                          t1.pos.end_pos,
                                          t2.pos.begin_pos)
        add_offence(:convention, range, format(MSG, kind))
      end
    end
  end
end