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

Code before:
                        rule_code: group
                            .invalid_codes
                            .iter()
                            .map(ToString::to_string)
                            .join(", "),
                        kind: InvalidRuleCodeKind::Suppression,
                        whole_comment: group.suppression.codes().len() == group.invalid_codes.len(),
                    },
                );
            }
            if group.any_unused() {
                let mut codes = group.disabled_codes.clone();
                codes.extend(group.unused_codes.clone());
                Suppressions::report_suppression_codes(
                    context,
                    locator,
                    group.suppression,
                    &codes,
                    false,
                    UnusedNOQA {
                        codes: Some(UnusedCodes {
                            disabled: group
                                .disabled_codes
                                .iter()
                                .map(ToString::to_string)
                                .collect_vec(),
                            duplicated: group
                                .duplicated_codes
                                .iter()
                                .map(ToString::to_string)
                                .collect_vec(),
                            unmatched: group
                                .unused_codes
                                .iter()
                                .map(ToString::to_string)
                                .collect_vec(),
                            ..Default::default()
                        }),
                        kind: UnusedNOQAKind::Suppression,
                    },
                );
            }
        }

        if context.is_rule_enabled(Rule::InvalidSuppressionComment) {
            for error in &self.errors {
                context
                    .report_diagnostic(
                        InvalidSuppressionComment {
                            kind: InvalidSuppressionCommentKind::Error(error.kind),
                        },

Review comment (suggestion):
This is probably better suited for a follow-up, and I thought I saw some previous discussion of this, but do these need to be `String`s? I tried making `UnusedCodes::disabled` a `Vec<&'a str>` and it seems to be working locally. Combining that with `into_values` makes this a little nicer:


```suggestion
                            disabled: group.disabled_codes
```

Code after:
                // InvalidRuleCode
                let (_key, group) = grouped_diagnostic
                    .get_or_insert_with(|| (key, SuppressionDiagnostic::new(suppression)));
                group.invalid_codes.push(code_str);
            } else if !suppression.used.get() {
                // UnusedNOQA
                let Ok(rule) = Rule::from_code(
                    get_redirect_target(&suppression.code).unwrap_or(&suppression.code),
                ) else {
                    continue; // "external" lint code, don't treat it as unused
                };

                let (_key, group) = grouped_diagnostic
                    .get_or_insert_with(|| (key, SuppressionDiagnostic::new(suppression)));

                if context.is_rule_enabled(rule) {
                    if suppression
                        .comments
                        .disable_comment()
                        .codes_as_str(locator.contents())
                        .filter(|code| *code == code_str)
                        .count()
                        > 1
                    {
                        group.duplicated_codes.push(code_str);
                    } else {
                        group.unused_codes.push(code_str);
                    }
                } else {
                    group.disabled_codes.push(code_str);
                }
            } else if let DisableEnableComments::Disable(comment) = &suppression.comments {
                // UnmatchedSuppressionComment
                if unmatched_ranges.insert(comment.range) {
                    context.report_diagnostic_if_enabled(
                        UnmatchedSuppressionComment {},
                        comment.range,
                    );
                }
            }
        }

        if context.is_rule_enabled(Rule::InvalidSuppressionComment) {
            for error in &self.errors {
                context
                    .report_diagnostic(
                        InvalidSuppressionComment {
                            kind: InvalidSuppressionCommentKind::Error(error.kind),
                        },
                        error.range,
                    )