Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 1 addition & 2 deletions crates/ruff_linter/src/checkers/noqa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ pub(crate) fn check_noqa(
FileNoqaDirectives::extract(locator, comment_ranges, &settings.external, path);

// Extract all `noqa` directives.
let mut noqa_directives =
NoqaDirectives::from_commented_ranges(comment_ranges, &settings.external, path, locator);
let mut noqa_directives = NoqaDirectives::from_commented_ranges(comment_ranges, path, locator);

if file_noqa_directives.is_empty() && noqa_directives.is_empty() && suppressions.is_empty() {
return Vec::new();
Expand Down
28 changes: 2 additions & 26 deletions crates/ruff_linter/src/noqa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub fn generate_noqa_edits(
) -> Vec<Option<Edit>> {
let file_directives = FileNoqaDirectives::extract(locator, comment_ranges, external, path);
let exemption = FileExemption::from(&file_directives);
let directives = NoqaDirectives::from_commented_ranges(comment_ranges, external, path, locator);
let directives = NoqaDirectives::from_commented_ranges(comment_ranges, path, locator);
let comments = find_noqa_comments(
diagnostics,
locator,
Expand Down Expand Up @@ -771,7 +771,7 @@ fn add_noqa_inner(
let directives = FileNoqaDirectives::extract(locator, comment_ranges, external, path);
let exemption = FileExemption::from(&directives);

let directives = NoqaDirectives::from_commented_ranges(comment_ranges, external, path, locator);
let directives = NoqaDirectives::from_commented_ranges(comment_ranges, path, locator);

let comments = find_noqa_comments(
diagnostics,
Expand Down Expand Up @@ -1082,7 +1082,6 @@ pub(crate) struct NoqaDirectives<'a> {
impl<'a> NoqaDirectives<'a> {
pub(crate) fn from_commented_ranges(
comment_ranges: &CommentRanges,
external: &[String],
path: &Path,
locator: &'a Locator<'a>,
) -> Self {
Expand All @@ -1106,29 +1105,6 @@ impl<'a> NoqaDirectives<'a> {
);
}
}
if let Directive::Codes(codes) = &directive {
// Warn on invalid rule codes.
for code in &codes.codes {
// Ignore externally-defined rules.
if !external
.iter()
.any(|external| code.as_str().starts_with(external))
{
if Rule::from_code(
get_redirect_target(code.as_str()).unwrap_or(code.as_str()),
)
.is_err()
{
#[expect(deprecated)]
let line = locator.compute_line_index(range.start());
let path_display = relativize_path(path);
warn!(
"Invalid rule code provided to `# noqa` at {path_display}:{line}: {code}"
);
}
}
}
}
// noqa comments are guaranteed to be single line.
let range = locator.line_range(range.start());
directives.push(NoqaDirectiveLine {
Expand Down