Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/ruff/tests/cli/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1902,7 +1902,7 @@ select = ["D100"]
let test_code =
fs::read_to_string(fixture.root().join("noqa.py")).expect("should read test file");

insta::assert_snapshot!(test_code, @" # noqa: D100");
insta::assert_snapshot!(test_code, @"# noqa: D100");

Ok(())
}
Expand Down Expand Up @@ -1944,7 +1944,7 @@ select = ["D100"]

insta::assert_snapshot!(test_code, @"
#!/usr/bin/env fake command
# noqa: D100
# noqa: D100
");

Ok(())
Expand Down
10 changes: 9 additions & 1 deletion crates/ruff_linter/src/noqa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,7 @@ struct NoqaEdit<'a> {
codes: Option<&'a Codes<'a>>,
line_ending: LineEnding,
reason: Option<&'a str>,
blank_line: bool,
}

impl NoqaEdit<'_> {
Expand All @@ -969,7 +970,10 @@ impl NoqaEdit<'_> {
}

fn write(&self, writer: &mut impl std::fmt::Write) {
write!(writer, " # noqa: ").unwrap();
if !self.blank_line {
write!(writer, " ").unwrap();
}
write!(writer, "# noqa: ").unwrap();
match self.codes {
Some(codes) => {
push_codes(
Expand Down Expand Up @@ -1010,11 +1014,13 @@ fn generate_noqa_edit<'a>(

let edit_range;
let codes;
let blank_line;

// Add codes.
match directive {
None => {
let trimmed_line = locator.slice(line_range).trim_end();
blank_line = trimmed_line.trim_start().is_empty();
Comment thread
amyreese marked this conversation as resolved.
Outdated
edit_range = TextRange::new(TextSize::of(trimmed_line), line_range.len()) + offset;
codes = None;
}
Expand All @@ -1023,6 +1029,7 @@ fn generate_noqa_edit<'a>(
let trimmed_line = locator
.slice(TextRange::new(line_range.start(), existing_codes.start()))
.trim_end();
blank_line = false;
edit_range = TextRange::new(TextSize::of(trimmed_line), line_range.len()) + offset;
codes = Some(existing_codes);
}
Expand All @@ -1035,6 +1042,7 @@ fn generate_noqa_edit<'a>(
codes,
line_ending,
reason,
blank_line,
})
}

Expand Down