forked from rubocop/rubocop
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[rubocop#3558] ConditionCorrector extraction
- Loading branch information
1 parent
7fc023e
commit 69e3382
Showing
5 changed files
with
36 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# frozen_string_literal: true | ||
|
||
module RuboCop | ||
module Cop | ||
# This class does condition auto-correction | ||
class ConditionCorrector | ||
class << self | ||
def correct_negative_condition(node) | ||
condition = negated_condition(node) | ||
|
||
lambda do |corrector| | ||
corrector.replace(node.loc.keyword, node.inverse_keyword) | ||
corrector.replace(condition.source_range, | ||
condition.children.first.source) | ||
end | ||
end | ||
|
||
private | ||
|
||
def negated_condition(node) | ||
condition = node.condition | ||
condition = condition.children.first while condition.begin_type? | ||
condition | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters