ruff/crates/ruff_macros/src
Brent Westbrook 02ae8e1210
Apply fix availability and applicability when adding to DiagnosticGuard and remove NoqaCode::rule (#18834)
## Summary

This PR removes the last two places we were using `NoqaCode::rule` in
`linter.rs` (see
https://github.com/astral-sh/ruff/pull/18391#discussion_r2154637329 and
https://github.com/astral-sh/ruff/pull/18391#discussion_r2154649726) by
checking whether fixes are actually desired before adding them to a
`DiagnosticGuard`. I implemented this by storing a `Violation`'s `Rule`
on the `DiagnosticGuard` so that we could check if it was enabled in the
embedded `LinterSettings` when trying to set a fix.

All of the corresponding `set_fix` methods on `OldDiagnostic` were now
unused (except in tests where I just set `.fix` directly), so I moved
these to the guard instead of keeping both sets.

The very last place where we were using `NoqaCode::rule` was in the
cache. I just reverted this to parsing the `Rule` from the name. I had
forgotten to update the comment there anyway. Hopefully this doesn't
cause too much of a perf hit.

In terms of binary size, we're back down almost to where `main` was two
days ago
(https://github.com/astral-sh/ruff/pull/18391#discussion_r2155034320):

```
41,559,344 bytes for main 2 days ago
41,669,840 bytes for #18391
41,653,760 bytes for main now (after #18391 merged)
41,602,224 bytes for this branch
```

Only 43 kb up, but that shouldn't all be me this time :)

## Test Plan

Existing tests and benchmarks on this PR
2025-06-24 10:08:36 -04:00
..
cache_key.rs Switch to Rust 2024 edition (#18129) 2025-05-16 13:25:28 +02:00
combine.rs [ty] Rename src.root setting to environment.root (#18760) 2025-06-24 14:40:44 +02:00
combine_options.rs Use #[expect(lint)] over #[allow(lint)] where possible (#17822) 2025-05-03 21:20:31 +02:00
config.rs Switch to Rust 2024 edition (#18129) 2025-05-16 13:25:28 +02:00
derive_message_formats.rs Switch to Rust 2024 edition (#18129) 2025-05-16 13:25:28 +02:00
kebab_case.rs Inline DiagnosticKind into other diagnostic types (#18074) 2025-05-15 10:27:21 -04:00
lib.rs [ty] Allow overriding rules for specific files (#18648) 2025-06-15 14:27:39 +01:00
map_codes.rs Apply fix availability and applicability when adding to DiagnosticGuard and remove NoqaCode::rule (#18834) 2025-06-24 10:08:36 -04:00
newtype_index.rs Use #[expect(lint)] over #[allow(lint)] where possible (#17822) 2025-05-03 21:20:31 +02:00
rule_code_prefix.rs Upgrade to Rust 1.82 (#13816) 2024-10-19 16:05:50 +02:00
rule_namespace.rs Apply fix availability and applicability when adding to DiagnosticGuard and remove NoqaCode::rule (#18834) 2025-06-24 10:08:36 -04:00
rust_doc.rs [ty] Allow overriding rules for specific files (#18648) 2025-06-15 14:27:39 +01:00
violation_metadata.rs Add a ViolationMetadata::rule method (#18234) 2025-05-28 09:27:09 -04:00