diff --git a/crates/ruff/tests/integration_test.rs b/crates/ruff/tests/integration_test.rs index 109239da4d96a7..b794495d1fd803 100644 --- a/crates/ruff/tests/integration_test.rs +++ b/crates/ruff/tests/integration_test.rs @@ -1228,8 +1228,8 @@ fn deprecated_multiple_direct() { Found 2 errors. ----- stderr ----- - warning: Rule `RUF921` is deprecated and will be removed in a future release. warning: Rule `RUF920` is deprecated and will be removed in a future release. + warning: Rule `RUF921` is deprecated and will be removed in a future release. "###); } @@ -1297,8 +1297,8 @@ fn deprecated_multiple_direct_preview_enabled() { ----- stderr ----- ruff failed Cause: Selection of deprecated rules is not allowed when preview is enabled. Remove selection of: - - RUF921 - RUF920 + - RUF921 "###); } diff --git a/crates/ruff_linter/src/rule_selector.rs b/crates/ruff_linter/src/rule_selector.rs index b7e0745d903bcb..50baf6d987b08e 100644 --- a/crates/ruff_linter/src/rule_selector.rs +++ b/crates/ruff_linter/src/rule_selector.rs @@ -44,6 +44,20 @@ impl From for RuleSelector { } } +impl Ord for RuleSelector { + fn cmp(&self, other: &Self) -> std::cmp::Ordering { + // TODO(zanieb): We ought to put "ALL" and "Linter" selectors + // above those that are rule specific but it's not critical for now + self.prefix_and_code().cmp(&other.prefix_and_code()) + } +} + +impl PartialOrd for RuleSelector { + fn partial_cmp(&self, other: &Self) -> Option { + self.prefix_and_code().partial_cmp(&other.prefix_and_code()) + } +} + impl FromStr for RuleSelector { type Err = ParseError; diff --git a/crates/ruff_workspace/src/configuration.rs b/crates/ruff_workspace/src/configuration.rs index ea0abf4322fe8c..0c21393509e9c3 100644 --- a/crates/ruff_workspace/src/configuration.rs +++ b/crates/ruff_workspace/src/configuration.rs @@ -951,7 +951,7 @@ impl LintConfiguration { } } - let removed_selectors = removed_selectors.iter().collect::>(); + let removed_selectors = removed_selectors.iter().sorted().collect::>(); match removed_selectors.as_slice() { [] => (), [selection] => { @@ -974,7 +974,7 @@ impl LintConfiguration { } } - for (from, target) in redirects { + for (from, target) in redirects.iter().sorted_by_key(|item| item.0) { // TODO(martin): This belongs into the ruff crate. warn_user_once_by_id!( from, @@ -984,7 +984,10 @@ impl LintConfiguration { ); } - let deprecated_nursery_selectors = deprecated_nursery_selectors.iter().collect::>(); + let deprecated_nursery_selectors = deprecated_nursery_selectors + .iter() + .sorted() + .collect::>(); match deprecated_nursery_selectors.as_slice() { [] => (), [selection] => { @@ -1005,14 +1008,14 @@ impl LintConfiguration { } if preview.mode.is_disabled() { - for selection in deprecated_selectors { + for selection in deprecated_selectors.iter().sorted() { let (prefix, code) = selection.prefix_and_code(); warn_user!( "Rule `{prefix}{code}` is deprecated and will be removed in a future release.", ); } } else { - let deprecated_selectors = deprecated_selectors.iter().collect::>(); + let deprecated_selectors = deprecated_selectors.iter().sorted().collect::>(); match deprecated_selectors.as_slice() { [] => (), [selection] => { @@ -1033,7 +1036,7 @@ impl LintConfiguration { } } - for selection in ignored_preview_selectors { + for selection in ignored_preview_selectors.iter().sorted() { let (prefix, code) = selection.prefix_and_code(); warn_user!("Selection `{prefix}{code}` has no effect because preview is not enabled.",); }