Skip to content

Commit f5b61be

Browse files
authored
Remove invalid inline noqa warning (#23270)
Summary -- This PR partially addresses #23267. This warning is now implemented as the RUF102 lint rule, so we can get rid of the warning. There's actually a second instance of this warning (the only variant with tests) for file-level `noqa`s. As I noted on the issue, these aren't actually covered by RUF102, but I think we should make that change and remove that warning separately. Test Plan -- Manual testing: ```console ❯ ruff check --select RUF102 --output-format=concise --no-cache - <<EOF 1 # noqa: X111 EOF warning: Invalid rule code provided to `# noqa` at -:1: X111 -:1:3: RUF102 [*] Invalid rule code in `# noqa`: X111 Found 1 error. [*] 1 fixable with the `--fix` option. ❯ cargo run -p ruff -- check --select RUF102 --output-format=concise --no-cache - <<EOF 1 # noqa: X111 EOF -:1:3: RUF102 [*] Invalid rule code in `# noqa`: X111 Found 1 error. [*] 1 fixable with the `--fix` option. ```
1 parent 496559e commit f5b61be

2 files changed

Lines changed: 3 additions & 28 deletions

File tree

crates/ruff_linter/src/checkers/noqa.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ pub(crate) fn check_noqa(
4040
FileNoqaDirectives::extract(locator, comment_ranges, &settings.external, path);
4141

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

4645
if file_noqa_directives.is_empty() && noqa_directives.is_empty() && suppressions.is_empty() {
4746
return Vec::new();

crates/ruff_linter/src/noqa.rs

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub fn generate_noqa_edits(
4040
) -> Vec<Option<Edit>> {
4141
let file_directives = FileNoqaDirectives::extract(locator, comment_ranges, external, path);
4242
let exemption = FileExemption::from(&file_directives);
43-
let directives = NoqaDirectives::from_commented_ranges(comment_ranges, external, path, locator);
43+
let directives = NoqaDirectives::from_commented_ranges(comment_ranges, path, locator);
4444
let comments = find_noqa_comments(
4545
diagnostics,
4646
locator,
@@ -771,7 +771,7 @@ fn add_noqa_inner(
771771
let directives = FileNoqaDirectives::extract(locator, comment_ranges, external, path);
772772
let exemption = FileExemption::from(&directives);
773773

774-
let directives = NoqaDirectives::from_commented_ranges(comment_ranges, external, path, locator);
774+
let directives = NoqaDirectives::from_commented_ranges(comment_ranges, path, locator);
775775

776776
let comments = find_noqa_comments(
777777
diagnostics,
@@ -1082,7 +1082,6 @@ pub(crate) struct NoqaDirectives<'a> {
10821082
impl<'a> NoqaDirectives<'a> {
10831083
pub(crate) fn from_commented_ranges(
10841084
comment_ranges: &CommentRanges,
1085-
external: &[String],
10861085
path: &Path,
10871086
locator: &'a Locator<'a>,
10881087
) -> Self {
@@ -1106,29 +1105,6 @@ impl<'a> NoqaDirectives<'a> {
11061105
);
11071106
}
11081107
}
1109-
if let Directive::Codes(codes) = &directive {
1110-
// Warn on invalid rule codes.
1111-
for code in &codes.codes {
1112-
// Ignore externally-defined rules.
1113-
if !external
1114-
.iter()
1115-
.any(|external| code.as_str().starts_with(external))
1116-
{
1117-
if Rule::from_code(
1118-
get_redirect_target(code.as_str()).unwrap_or(code.as_str()),
1119-
)
1120-
.is_err()
1121-
{
1122-
#[expect(deprecated)]
1123-
let line = locator.compute_line_index(range.start());
1124-
let path_display = relativize_path(path);
1125-
warn!(
1126-
"Invalid rule code provided to `# noqa` at {path_display}:{line}: {code}"
1127-
);
1128-
}
1129-
}
1130-
}
1131-
}
11321108
// noqa comments are guaranteed to be single line.
11331109
let range = locator.line_range(range.start());
11341110
directives.push(NoqaDirectiveLine {

0 commit comments

Comments
 (0)