Module: Rubocop::Cop::Style::AutocorrectAlignment
- Included in:
- AlignArray, AlignParameters
- Defined in:
- lib/rubocop/cop/style/autocorrect_alignment.rb
Overview
This module does auto-correction of nodes that should just be moved to the left or to the right, amount being determined by the instance variable @column_delta.
Instance Method Summary collapse
Instance Method Details
#autocorrect_action(node) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/rubocop/cop/style/autocorrect_alignment.rb', line 10 def autocorrect_action(node) # We can't use the instance variable inside the lambda. That would # just give each lambda the same reference and they would all get # the last value of @column_delta. A local variable fixes the # problem. column_delta = @column_delta @corrections << lambda do |corrector| expr = node.loc.expression if column_delta > 0 corrector.replace(expr, ' ' * column_delta + expr.source) else range = Parser::Source::Range.new(expr.source_buffer, expr.begin_pos + column_delta, expr.end_pos) corrector.replace(range, expr.source) end end end |