mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-02 22:55:08 +00:00
Implement FURB136 (#8664)
## Summary Implements [FURB136](https://github.com/dosisod/refurb/blob/master/docs/checks.md#furb136-use-min-max) that checks for `if` expressions that can be replaced with `min()` or `max()` calls. See issue #1348 for more information. This implementation diverges from Refurb's original implementation by retaining the order of equal values. For example, Refurb suggest that the following expressions: ```python highest_score1 = score1 if score1 > score2 else score2 highest_score2 = score1 if score1 >= score2 else score2 ``` should be to rewritten as: ```python highest_score1 = max(score1, score2) highest_score2 = max(score1, score2) ``` whereas this implementation provides more correct alternatives: ```python highest_score1 = max(score2, score1) highest_score2 = max(score1, score2) ``` ## Test Plan Unit test checks all eight possibilities.
This commit is contained in:
parent
a783b14e7d
commit
0e2ece5217
9 changed files with 414 additions and 6 deletions
|
@ -947,6 +947,7 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<(RuleGroup, Rule)> {
|
|||
(Refurb, "131") => (RuleGroup::Nursery, rules::refurb::rules::DeleteFullSlice),
|
||||
#[allow(deprecated)]
|
||||
(Refurb, "132") => (RuleGroup::Nursery, rules::refurb::rules::CheckAndRemoveFromSet),
|
||||
(Refurb, "136") => (RuleGroup::Preview, rules::refurb::rules::IfExprMinMax),
|
||||
(Refurb, "140") => (RuleGroup::Preview, rules::refurb::rules::ReimplementedStarmap),
|
||||
(Refurb, "145") => (RuleGroup::Preview, rules::refurb::rules::SliceCopy),
|
||||
(Refurb, "148") => (RuleGroup::Preview, rules::refurb::rules::UnnecessaryEnumerate),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue