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.'

Constants inherited from Cop

Cop::OPERATOR_METHODS

Instance Attribute Summary

Attributes inherited from Cop

#config, #corrections, #offences, #processed_source

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?, #autocorrect_action, #convention, #cop_config, #cop_name, cop_name, cop_type, #debug?, #ignore_node, inherited, #initialize, lint?, #message, rails?, style?, #warning

Constructor Details

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

Instance Method Details

#investigate(processed_source) ⇒ Object



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

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)
      convention(nil, equals.pos)
    end
  end
end