diff --git a/crates/ruff/src/autofix/codemods.rs b/crates/ruff/src/autofix/codemods.rs index 8d8ab05295912..d08bf12f706c2 100644 --- a/crates/ruff/src/autofix/codemods.rs +++ b/crates/ruff/src/autofix/codemods.rs @@ -127,7 +127,11 @@ pub(crate) fn remove_imports<'a>( } } - Ok(Some(tree.codegen_stylist(&stylist))) + if aliases.is_empty() { + return Ok(None); + } + + Ok(Some(tree.codegen_stylist(stylist))) } /// Given an import statement, remove any imports that are not specified in the `imports` slice.