diff --git a/crates/ruff/src/autofix/mod.rs b/crates/ruff/src/autofix/mod.rs index 04e4714bb0b4d..224fb6c7a2252 100644 --- a/crates/ruff/src/autofix/mod.rs +++ b/crates/ruff/src/autofix/mod.rs @@ -65,7 +65,11 @@ fn apply_fixes<'a>( continue; } - for edit in fix.edits() { + for edit in fix + .edits() + .iter() + .sorted_unstable_by_key(|edit| edit.start()) + { // Add all contents from `last_pos` to `fix.location`. let slice = locator.slice(TextRange::new(last_pos.unwrap_or_default(), edit.start())); output.push_str(slice);