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

Code before:
            if !code_is_valid(&suppression.code, &context.settings().external) {
                // InvalidRuleCode
                let entry = grouped_diagnostics
                    .entry(key)
                    .or_insert_with(|| SuppressionDiagnostic::new(suppression));
                entry.invalid_codes.push(suppression.code.as_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 entry = grouped_diagnostics
                    .entry(key)
                    .or_insert_with(|| SuppressionDiagnostic::new(suppression));

                if context.is_rule_enabled(rule) {
                    if suppression
                        .comments
                        .disable_comment()
                        .codes_as_str(locator.contents())
                        .filter(|code| *code == code_str)
                        .collect_vec()
                        .len()
                        > 1
                    {
                        entry.duplicated_codes.push(code_str);
                    } else {
                        entry.unused_codes.push(code_str);
                    }
                } else {
                    entry.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,
                    );
                }
            }
        }

        for group in grouped_diagnostics.values() {
            if group.any_invalid() {
                Suppressions::report_suppression_codes(
                    context,
                    locator,

Review comment (suggestion):
nit: could we use [`count`](https://doc.rust-lang.org/nightly/core/iter/trait.Iterator.html#method.count) here?


```suggestion
                        .filter(|code| *code == code_str)
                        .count()
```

Code after:
                && key != group_key
            {
                if group.any_invalid() {
                    Suppressions::report_suppression_codes(
                        context,
                        locator,
                        group.suppression,
                        &group.invalid_codes,
                        true,
                        InvalidRuleCode {
                            rule_code: group.invalid_codes.iter().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,
                        },
                    );
                }
                grouped_diagnostic = None;
            }