Class: Rubocop::Cop::Style::SpaceAroundEqualsInParameterDefault
- 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
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?, #convention, #cop_config, cop_name, #cop_name, cop_type, #debug?, #ignore_node, inherited, #initialize, lint?, #message, non_rails, rails?, style?, #support_autocorrect?, #warning
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) convention(equals.pos, equals.pos) end end end |