Class: RuboCop::Cop::Style::UnlessCorrector
- Inherits:
-
Object
- Object
- RuboCop::Cop::Style::UnlessCorrector
- Extended by:
- ConditionalAssignmentHelper
- Defined in:
- lib/rubocop/cop/style/conditional_assignment.rb
Overview
Corrector to correct conditional assignment in ‘unless` statements.
Constant Summary
Constants included from ConditionalAssignmentHelper
ConditionalAssignmentHelper::ALIGN_WITH, ConditionalAssignmentHelper::END_ALIGNMENT, ConditionalAssignmentHelper::EQUAL, ConditionalAssignmentHelper::KEYWORD
Class Method Summary collapse
Methods included from ConditionalAssignmentHelper
correct_branches, expand_elses, expand_when_branches, indent, lhs, tail
Class Method Details
.correct(cop, node) ⇒ Object
363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 |
# File 'lib/rubocop/cop/style/conditional_assignment.rb', line 363 def correct(cop, node) _condition, else_branch, if_branch = *node if_branch = tail(if_branch) else_branch = tail(else_branch) _variable, *_operator, if_assignment = *if_branch _else_variable, *_operator, else_assignment = *else_branch lambda do |corrector| corrector.insert_before(node.source_range, lhs(if_branch)) corrector.replace(if_branch.source_range, if_assignment.source) corrector.replace(else_branch.source_range, else_assignment.source) corrector.insert_before(node.loc.end, indent(cop, lhs(if_branch))) end end |