From 4bd395a8504b5b56038ecbec8ea5565d47ccc2c1 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Wed, 31 May 2023 13:26:31 -0400 Subject: [PATCH] Apply edits in sorted order (#4762) --- crates/ruff/src/autofix/mod.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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);