Skip to content

Commit 06f44a3

Browse files
committed
refactor(linter_codegen): simplify sorting rules (#13575)
Follow-on after #13138, as per [this comment](#13138 (comment)). Pure refactor. Simplify sorting rules, by leaning on derived traits instead of manual implementation.
1 parent b81f081 commit 06f44a3

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

tasks/linter_codegen/src/main.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ fn find_rule_source_file(root: &Path, rule: &RuleEntry) -> Option<std::path::Pat
9393
}
9494

9595
/// Represents a lint rule entry in the `declare_all_lint_rules!` macro.
96+
#[derive(PartialEq, Eq, PartialOrd, Ord)]
9697
struct RuleEntry<'e> {
9798
/// The module name of the rule's plugin, like `eslint` in `eslint::no_debugger::NoDebugger`.
9899
plugin_module_name: &'e str,
@@ -141,14 +142,7 @@ fn get_all_rules(contents: &str) -> io::Result<Vec<RuleEntry<'_>>> {
141142
rule_entries.push(RuleEntry { plugin_module_name, rule_module_name });
142143
}
143144
// Sort deterministically
144-
rule_entries.sort_by(|a, b| {
145-
let ord = a.plugin_module_name.cmp(b.plugin_module_name);
146-
if ord == std::cmp::Ordering::Equal {
147-
a.rule_module_name.cmp(b.rule_module_name)
148-
} else {
149-
ord
150-
}
151-
});
145+
rule_entries.sort_unstable();
152146

153147
Ok(rule_entries)
154148
}

0 commit comments

Comments
 (0)