Repository: astral-sh/ruff
File: crates/ruff_linter/src/rules/ruff/rules/invalid_rule_code.rs (Rust)

Code before:

pub(crate) fn code_is_valid(code: &str, external: &[String]) -> bool {
    Rule::from_code(get_redirect_target(code).unwrap_or(code)).is_ok()
        || external.iter().any(|ext| code.starts_with(ext))
}

fn all_codes_invalid_diagnostic(
    directive: &Codes<'_>,
    invalid_codes: Vec<&Code<'_>>,
    context: &LintContext,
) {
    let mut diagnostic = context.report_custom_diagnostic(
        InvalidRuleCode {
            rule_code: invalid_codes
                .into_iter()
                .map(Code::as_str)
                .collect::<Vec<_>>()
                .join(", "),
            kind: InvalidRuleCodeKind::Noqa,
            whole_comment: true,
        },
        directive.range(),
    );
    diagnostic.set_fix(Fix::safe_edit(Edit::range_deletion(directive.range())));
    diagnostic.help(
        "If this is a non-Ruff rule code, consider using the `lint.external` configuration option",
    );
}

fn some_codes_are_invalid_diagnostic(
    codes: &Codes,
    invalid_code: &Code,
    locator: &Locator,
    context: &LintContext,
) {
    let mut diagnostic = context.report_custom_diagnostic(
        InvalidRuleCode {
            rule_code: invalid_code.to_string(),
            kind: InvalidRuleCodeKind::Noqa,
            whole_comment: false,
        },
        invalid_code.range(),
    );
    diagnostic.set_fix(Fix::safe_edit(remove_invalid_noqa(
        codes,
        invalid_code,
        locator,
    )));
    diagnostic.help(
        "If this is a non-Ruff rule code, consider using the `lint.external` configuration option",
    );

Review comment (suggestion):
"Using" sounds a bit strange here... but I can't actually think of a better wording though. Something like...?

```suggestion
        "If this is a non-Ruff rule code, consider using the `lint.external` configuration option",
        "Allow non-Ruff noqa codes by adding their prefix to the  `lint.external` configuration option,"
```

But that's longer.

What you have is probably fine 😄 

Code after:
}

pub(crate) fn code_is_valid(code: &str, external: &[String]) -> bool {
    Rule::from_code(get_redirect_target(code).unwrap_or(code)).is_ok()
        || external.iter().any(|ext| code.starts_with(ext))
}

fn all_codes_invalid_diagnostic(
    directive: &Codes<'_>,
    invalid_codes: Vec<&Code<'_>>,
    locator: &Locator,
    context: &LintContext,
) {
    let mut diagnostic = context.report_custom_diagnostic(
        InvalidRuleCode {
            rule_code: invalid_codes
                .into_iter()
                .map(Code::as_str)
                .collect::<Vec<_>>()
                .join(", "),
            kind: InvalidRuleCodeKind::Noqa,
            whole_comment: true,
        },
        directive.range(),
    );
    diagnostic.set_fix(Fix::safe_edit(delete_comment(directive.range(), locator)));
    diagnostic.help("Add non-Ruff rule codes to the `lint.external` configuration option");
}

fn some_codes_are_invalid_diagnostic(
    codes: &Codes,
    invalid_code: &Code,
    locator: &Locator,
    context: &LintContext,
) {
    let mut diagnostic = context.report_custom_diagnostic(
        InvalidRuleCode {
            rule_code: invalid_code.to_string(),
            kind: InvalidRuleCodeKind::Noqa,
            whole_comment: false,
        },
        invalid_code.range(),
    );
    diagnostic.set_fix(Fix::safe_edit(remove_invalid_noqa(
        codes,
        invalid_code,
        locator,
    )));
    diagnostic.help("Add non-Ruff rule codes to the `lint.external` configuration option");
}