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

Inherits:
Cop
  • Object
show all
Includes:
SurroundingSpace
Defined in:
lib/rubocop/cop/style/space_around_equals_in_parameter_default.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

Constants included from Util

Util::PROC_NEW_NODE

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?, #config_to_allow_offences, #config_to_allow_offences=, #cop_config, cop_name, #cop_name, cop_type, #debug?, #exclude_file?, #exclude_paths, #ignore_node, #include_file?, #include_paths, inherited, #initialize, lint?, #message, non_rails, rails?, #relevant_file?, style?, #support_autocorrect?

Methods included from Util

block_length, command?, comment_line?, const_name, first_part_of_call_chain, lambda?, lambda_or_proc?, line_range, on_node, proc?, range_with_surrounding_space, source_range, strip_quotes

Constructor Details

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

Instance Method Details

#autocorrect(range) ⇒ Object



24
25
26
27
28
29
# File 'lib/rubocop/cop/style/space_around_equals_in_parameter_default.rb', line 24

def autocorrect(range)
  @corrections << lambda do |corrector|
    corrector.insert_before(range, ' ')
    corrector.insert_after(range, ' ')
  end
end

#investigate(processed_source) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/rubocop/cop/style/space_around_equals_in_parameter_default.rb', line 12

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