diff --git a/crates/ruff_linter/src/fix/edits.rs b/crates/ruff_linter/src/fix/edits.rs index b3ffbe2dfbca0..0a70cc4e2327c 100644 --- a/crates/ruff_linter/src/fix/edits.rs +++ b/crates/ruff_linter/src/fix/edits.rs @@ -83,6 +83,7 @@ pub(crate) fn delete_comment(range: TextRange, locator: &Locator) -> Edit { } // Ex) `x = 1 # noqa` else if range.end() + trailing_space_len == line_range.end() { + // Replace `x = 1 # noqa` with `x = 1`. Edit::deletion(range.start() - leading_space_len, line_range.end()) } // Ex) `x = 1 # noqa # type: ignore` @@ -93,21 +94,16 @@ pub(crate) fn delete_comment(range: TextRange, locator: &Locator) -> Edit { )) .starts_with('#') { + // Replace `# noqa # type: ignore` with `# type: ignore`. Edit::deletion(range.start(), range.end() + trailing_space_len) } // Ex) `x = 1 # noqa here` else { - if suffix.is_empty() { - // if there's no comment after the deleted noqa, delete the entire range - let full_line_end = locator.full_line_end(line_range.end()); - Edit::deletion(line_range.start() - leading_space_len, full_line_end) - } else { - // if there is something after the deleted noqa, keep it in a comment - Edit::range_replacement( - "# ".to_string(), - TextRange::new(range.start(), range.end() + trailing_space_len), - ) - } + // Replace `# noqa here` with `# here`. + Edit::range_replacement( + "# ".to_string(), + TextRange::new(range.start(), range.end() + trailing_space_len), + ) } }