Class: Rubocop::Cop::Style::SpaceAroundEqualsInParameterDefault

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

Overview

Checks that the equals signs in parameter default assignments have surrounding space.

Constant Summary collapse

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

Instance Attribute Summary

Attributes inherited from Cop

#autocorrect, #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, all, #autocorrect_action, cop_name, cop_type, #do_autocorrect, #ignore_node, inherited, #initialize, lint?, #name, rails?, style?

Constructor Details

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

Instance Method Details

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



300
301
302
303
304
305
306
307
308
309
310
# File 'lib/rubocop/cop/style/surrounding_space.rb', line 300

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