Skip to content

Commit

Permalink
Ignore end-of-line file exemption comments
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Jul 29, 2023
1 parent 047c211 commit b6a7a0e
Showing 1 changed file with 34 additions and 15 deletions.
49 changes: 34 additions & 15 deletions crates/ruff/src/noqa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,22 +248,41 @@ impl FileExemption {
let path_display = relativize_path(path);
warn!("Invalid `# ruff: noqa` directive at {path_display}:{line}: {err}");
}
Ok(Some(ParsedFileExemption::All)) => {
return Some(Self::All);
}
Ok(Some(ParsedFileExemption::Codes(codes))) => {
exempt_codes.extend(codes.into_iter().filter_map(|code| {
if let Ok(rule) = Rule::from_code(get_redirect_target(code).unwrap_or(code))
{
Some(rule.noqa_code())
} else {
#[allow(deprecated)]
let line = locator.compute_line_index(range.start());
let path_display = relativize_path(path);
warn!("Invalid code provided to `# ruff: noqa` at {path_display}:{line}: {code}");
None
Ok(Some(exemption)) => {
if !locator
.slice(TextRange::new(
locator.line_start(range.start()),
range.start(),
))
.chars()
.all(char::is_whitespace)
{
#[allow(deprecated)]
let line = locator.compute_line_index(range.start());
let path_display = relativize_path(path);
warn!("Unexpected end-of-line `# ruff: noqa` directive at {path_display}:{line}");
continue;
}

match exemption {
ParsedFileExemption::All => {
return Some(Self::All);
}
}));
ParsedFileExemption::Codes(codes) => {
exempt_codes.extend(codes.into_iter().filter_map(|code| {
if let Ok(rule) = Rule::from_code(get_redirect_target(code).unwrap_or(code))
{
Some(rule.noqa_code())
} else {
#[allow(deprecated)]
let line = locator.compute_line_index(range.start());
let path_display = relativize_path(path);
warn!("Invalid code provided to `# ruff: noqa` at {path_display}:{line}: {code}");
None
}
}));
}
}
}
Ok(None) => {}
}
Expand Down

0 comments on commit b6a7a0e

Please sign in to comment.