diff --git a/crates/ruff_linter/src/rules/pyflakes/rules/unused_import.rs b/crates/ruff_linter/src/rules/pyflakes/rules/unused_import.rs index eff33fcb1cc5a..60347b06d95b6 100644 --- a/crates/ruff_linter/src/rules/pyflakes/rules/unused_import.rs +++ b/crates/ruff_linter/src/rules/pyflakes/rules/unused_import.rs @@ -330,7 +330,7 @@ pub(crate) fn unused_import(checker: &Checker, scope: &Scope, diagnostics: &mut fix_by_reexporting( checker, import_statement, - &to_reexport.iter().map(|(b, _)| b).collect::>(), + to_reexport.iter().map(|(b, _)| b).collect::>(), &dunder_all_exprs, ) .ok(), @@ -450,7 +450,7 @@ fn fix_by_removing_imports<'a>( fn fix_by_reexporting( checker: &Checker, node_id: NodeId, - imports: &[&ImportBinding], + mut imports: Vec<&ImportBinding>, dunder_all_exprs: &[&ast::Expr], ) -> Result { let statement = checker.semantic().statement(node_id); @@ -458,6 +458,8 @@ fn fix_by_reexporting( bail!("Expected import bindings"); } + imports.sort_by_key(|b| b.name); + let edits = match dunder_all_exprs { [] => fix::edits::make_redundant_alias( imports.iter().map(|b| b.import.member_name()),