Class: RuboCop::Cop::Style::CaseCorrector
- Inherits:
-
Object
- Object
- RuboCop::Cop::Style::CaseCorrector
- Extended by:
- ConditionalAssignmentHelper, ConditionalCorrectorHelper
- Defined in:
- lib/rubocop/cop/style/conditional_assignment.rb
Overview
Corrector to correct conditional assignment in ‘case` statements.
Constant Summary
Constants included from ConditionalAssignmentHelper
RuboCop::Cop::Style::ConditionalAssignmentHelper::ALIGN_WITH, RuboCop::Cop::Style::ConditionalAssignmentHelper::END_ALIGNMENT, RuboCop::Cop::Style::ConditionalAssignmentHelper::EQUAL, RuboCop::Cop::Style::ConditionalAssignmentHelper::KEYWORD
Class Method Summary collapse
Methods included from ConditionalCorrectorHelper
assignment, correct_branches, correct_if_branches, remove_whitespace_in_branches, replace_branch_assignment, white_space_range
Methods included from ConditionalAssignmentHelper
end_with_eq?, expand_elses, expand_when_branches, indent, lhs, tail
Methods included from NodePattern::Macros
#def_node_matcher, #def_node_search, #node_search, #node_search_all, #node_search_body, #node_search_first
Class Method Details
.correct(cop, node) ⇒ Object
618 619 620 621 622 623 624 625 626 627 628 629 |
# File 'lib/rubocop/cop/style/conditional_assignment.rb', line 618 def correct(cop, node) when_branches, else_branch = extract_tail_branches(node) lambda do |corrector| corrector.insert_before(node.source_range, lhs(else_branch)) correct_branches(corrector, when_branches) replace_branch_assignment(corrector, else_branch) corrector.insert_before(node.loc.end, indent(cop, lhs(else_branch))) end end |
.move_assignment_inside_condition(node) ⇒ Object
631 632 633 634 635 636 637 638 639 640 641 642 643 644 |
# File 'lib/rubocop/cop/style/conditional_assignment.rb', line 631 def move_assignment_inside_condition(node) column = node.loc.expression.column *_var, condition = *node assignment = assignment(node) lambda do |corrector| corrector.remove(assignment) extract_branches(condition).flatten.each do |branch| move_branch_inside_condition(corrector, branch, condition, assignment, column) end end end |