Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions crates/ruff_linter/src/rules/refurb/rules/sorted_min_max.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ use crate::checkers::ast::Checker;
/// the same key. However, `min(data, key=itemgetter(0))` will return the _first_
/// "minimum" element in the list in the same scenario.
///
/// As such, this rule's fix is marked as unsafe when the `reverse` keyword is used.
/// As such, this rule's fix is marked as unsafe.
///
/// ## References
/// - [Python documentation: `min`](https://docs.python.org/3/library/functions.html#min)
Expand Down Expand Up @@ -193,11 +193,7 @@ pub(crate) fn sorted_min_max(checker: &Checker, subscript: &ast::ExprSubscript)
};

let replacement = Edit::range_replacement(replacement, subscript.range());
if is_reversed {
Fix::unsafe_edit(replacement)
} else {
Fix::safe_edit(replacement)
}
Fix::unsafe_edit(replacement)
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ help: Replace with `min`
4 |
5 | sorted(l)[-1]
6 |
note: This is an unsafe fix and may change runtime behavior

FURB192 [*] Prefer `max` over `sorted()` to compute the maximum value in a sequence
--> FURB192.py:5:1
Expand All @@ -39,6 +40,7 @@ help: Replace with `max`
6 |
7 | sorted(l, reverse=False)[-1]
8 |
note: This is an unsafe fix and may change runtime behavior

FURB192 [*] Prefer `max` over `sorted()` to compute the maximum value in a sequence
--> FURB192.py:7:1
Expand All @@ -59,6 +61,7 @@ help: Replace with `max`
8 |
9 | sorted(l, key=lambda x: x)[0]
10 |
note: This is an unsafe fix and may change runtime behavior

FURB192 [*] Prefer `min` over `sorted()` to compute the minimum value in a sequence
--> FURB192.py:9:1
Expand All @@ -79,6 +82,7 @@ help: Replace with `min`
10 |
11 | sorted(l, key=key_fn)[0]
12 |
note: This is an unsafe fix and may change runtime behavior

FURB192 [*] Prefer `min` over `sorted()` to compute the minimum value in a sequence
--> FURB192.py:11:1
Expand All @@ -99,6 +103,7 @@ help: Replace with `min`
12 |
13 | sorted([1, 2, 3])[0]
14 |
note: This is an unsafe fix and may change runtime behavior

FURB192 [*] Prefer `min` over `sorted()` to compute the minimum value in a sequence
--> FURB192.py:13:1
Expand All @@ -119,6 +124,7 @@ help: Replace with `min`
14 |
15 | # Unsafe
16 |
note: This is an unsafe fix and may change runtime behavior

FURB192 [*] Prefer `min` over `sorted()` to compute the minimum value in a sequence
--> FURB192.py:17:1
Expand Down