Class: Rubocop::Cop::SpaceAroundEqualsInParameterDefault

Inherits:
Cop
  • Object
show all
Includes:
SurroundingSpace
Defined in:
lib/rubocop/cop/surrounding_space.rb

Constant Summary collapse

MSG =
'Surrounding space missing in default value assignment.'

Instance Attribute Summary

Attributes inherited from Cop

#debug, #disabled_lines, #offences

Instance Method Summary collapse

Methods included from SurroundingSpace

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

Methods inherited from Cop

#add_offence, cop_name, #has_report?, #ignore_node, inherited, #initialize, #name, #on_comment

Constructor Details

This class inherits a constructor from Rubocop::Cop::Cop

Instance Method Details

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



274
275
276
277
278
279
280
281
282
# File 'lib/rubocop/cop/surrounding_space.rb', line 274

def inspect(source, tokens, sexp, comments)
  @source = source
  on_node(:optarg, sexp) do |optarg|
    arg, equals, value = tokens[index_of_first_token(optarg, tokens), 3]
    unless space_between?(arg, equals) && space_between?(equals, value)
      add_offence(:convention, equals.pos.line, MSG)
    end
  end
end