mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-01 22:31:23 +00:00
Fix Ord
of cmp_fix
(#12471)
This commit is contained in:
parent
f0fc6a95fe
commit
3af6ccb720
1 changed files with 7 additions and 7 deletions
|
@ -130,14 +130,14 @@ fn apply_fixes<'a>(
|
||||||
/// Compare two fixes.
|
/// Compare two fixes.
|
||||||
fn cmp_fix(rule1: Rule, rule2: Rule, fix1: &Fix, fix2: &Fix) -> std::cmp::Ordering {
|
fn cmp_fix(rule1: Rule, rule2: Rule, fix1: &Fix, fix2: &Fix) -> std::cmp::Ordering {
|
||||||
// Always apply `RedefinedWhileUnused` before `UnusedImport`, as the latter can end up fixing
|
// Always apply `RedefinedWhileUnused` before `UnusedImport`, as the latter can end up fixing
|
||||||
// the former.
|
// the former. But we can't apply this just for `RedefinedWhileUnused` and `UnusedImport` because it violates
|
||||||
{
|
// `< is transitive: a < b and b < c implies a < c. The same must hold for both == and >.`
|
||||||
|
// See https://github.com/astral-sh/ruff/issues/12469#issuecomment-2244392085
|
||||||
match (rule1, rule2) {
|
match (rule1, rule2) {
|
||||||
(Rule::RedefinedWhileUnused, Rule::UnusedImport) => return std::cmp::Ordering::Less,
|
(Rule::RedefinedWhileUnused, _) => std::cmp::Ordering::Less,
|
||||||
(Rule::UnusedImport, Rule::RedefinedWhileUnused) => return std::cmp::Ordering::Greater,
|
(_, Rule::RedefinedWhileUnused) => std::cmp::Ordering::Greater,
|
||||||
_ => std::cmp::Ordering::Equal,
|
_ => std::cmp::Ordering::Equal,
|
||||||
}
|
}
|
||||||
}
|
|
||||||
// Apply fixes in order of their start position.
|
// Apply fixes in order of their start position.
|
||||||
.then_with(|| fix1.min_start().cmp(&fix2.min_start()))
|
.then_with(|| fix1.min_start().cmp(&fix2.min_start()))
|
||||||
// Break ties in the event of overlapping rules, for some specific combinations.
|
// Break ties in the event of overlapping rules, for some specific combinations.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue