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, #corrections, #debug, #disabled_lines, #offences

Instance Method Summary collapse

Methods included from SurroundingSpace

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

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

#investigate(processed_source) ⇒ Object



315
316
317
318
319
320
321
322
323
324
325
# File 'lib/rubocop/cop/style/surrounding_space.rb', line 315

def investigate(processed_source)
  return unless processed_source.ast
  @processed_source = processed_source
  on_node(:optarg, processed_source.ast) do |optarg|
    index = index_of_first_token(optarg)
    arg, equals, value = processed_source.tokens[index, 3]
    unless space_between?(arg, equals) && space_between?(equals, value)
      add_offence(:convention, equals.pos, MSG)
    end
  end
end