From 17b6f4556ce32aa3239fabed2d92e8fb34c38793 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Fri, 28 Jul 2023 14:35:51 -0400 Subject: [PATCH] Ignore end-of-line file exemption comments --- crates/ruff/src/noqa.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/crates/ruff/src/noqa.rs b/crates/ruff/src/noqa.rs index e609ceb4a8dfa6..0ba222e44cd10c 100644 --- a/crates/ruff/src/noqa.rs +++ b/crates/ruff/src/noqa.rs @@ -249,9 +249,39 @@ impl FileExemption { warn!("Invalid `# ruff: noqa` directive at {path_display}:{line}: {err}"); } Ok(Some(ParsedFileExemption::All)) => { + 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; + } + return Some(Self::All); } Ok(Some(ParsedFileExemption::Codes(codes))) => { + 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; + } + exempt_codes.extend(codes.into_iter().filter_map(|code| { if let Ok(rule) = Rule::from_code(get_redirect_target(code).unwrap_or(code)) {