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

#build_token_table, #index_of_first_token, #index_of_last_token, #space_between?

Instance Method Details

#inspect(source_buffer, source, tokens, sexp, comments) ⇒ Object



225
226
227
228
229
230
231
232
233
234
235
236
237
238
# File 'lib/rubocop/cop/style/surrounding_space.rb', line 225

def inspect(source_buffer, source, tokens, sexp, comments)
  @source = source
  left, right, kind = specifics
  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)
        space_range = Parser::Source::Range.new(source_buffer,
                                                t1.pos.end_pos,
                                                t2.pos.begin_pos)
        add_offence(:convention, space_range, format(MSG, kind))
      end
    end
  end
end