ruff/crates
Brent Westbrook 9925910a29
Add a ViolationMetadata::rule method (#18234)
Summary
--

This PR adds a macro-generated method to retrieve the `Rule` associated
with a given `Violation` struct, which makes it substantially cheaper
than parsing from the rule name. The rule is then converted to a
`NoqaCode` for storage on the `Message` (and eventually on the new
diagnostic type). The `ViolationMetadata::rule_name` method was now
unused, so the `rule` method replaces it.

Several types had to be moved from the `ruff_diagnostics` crate to the
`ruff_linter` crate to make this work, namely the `Violation` traits and
the old `Diagnostic` type, which had a constructor generic over a
`Violation`.

It's actually a fairly small PR, minus the hundreds of import changes.
The main changes are in these files:

-
[crates/ruff_linter/src/message/mod.rs](https://github.com/astral-sh/ruff/pull/18234/files#diff-139754ea310d75f28307008d21c771a190038bd106efe3b9267cc2d6c0fa0921)
-
[crates/ruff_diagnostics/src/lib.rs](https://github.com/astral-sh/ruff/pull/18234/files#diff-8e8ea5c586935bf21ea439f24253fcfd5955d2cb130f5377c2fa7bfee3ea3a81)
-
[crates/ruff_linter/src/diagnostic.rs](https://github.com/astral-sh/ruff/pull/18234/files#diff-1d0c9aad90d8f9446079c5be5f284150d97797158715bd9729e6f1f70246297a)
-
[crates/ruff_linter/src/lib.rs](https://github.com/astral-sh/ruff/pull/18234/files#diff-eb93ef7e78a612f5fa9145412c75cf6b1a5cefba1c2233e4a11a880a1ce1fbcc)

Test Plan
--

Existing tests
2025-05-28 09:27:09 -04:00
..
ruff Add a ViolationMetadata::rule method (#18234) 2025-05-28 09:27:09 -04:00
ruff_annotate_snippets Switch to Rust 2024 edition (#18129) 2025-05-16 13:25:28 +02:00
ruff_benchmark [ty] Add --config-file CLI arg (#18083) 2025-05-27 08:00:38 +02:00
ruff_cache Switch to Rust 2024 edition (#18129) 2025-05-16 13:25:28 +02:00
ruff_db [ty] Gracefully handle salsa cancellations and panics in background request handlers (#18254) 2025-05-26 13:37:49 +01:00
ruff_dev Add a ViolationMetadata::rule method (#18234) 2025-05-28 09:27:09 -04:00
ruff_diagnostics Add a ViolationMetadata::rule method (#18234) 2025-05-28 09:27:09 -04:00
ruff_formatter Switch to Rust 2024 edition (#18129) 2025-05-16 13:25:28 +02:00
ruff_graph [ty] Tell the user why we inferred the Python version we inferred (#18082) 2025-05-21 11:06:27 -04:00
ruff_index Switch to Rust 2024 edition (#18129) 2025-05-16 13:25:28 +02:00
ruff_linter Add a ViolationMetadata::rule method (#18234) 2025-05-28 09:27:09 -04:00
ruff_macros Add a ViolationMetadata::rule method (#18234) 2025-05-28 09:27:09 -04:00
ruff_notebook Switch to Rust 2024 edition (#18129) 2025-05-16 13:25:28 +02:00
ruff_options_metadata [ty] Document configuration schema (#17950) 2025-05-09 10:47:45 +02:00
ruff_python_ast Switch to Rust 2024 edition (#18129) 2025-05-16 13:25:28 +02:00
ruff_python_ast_integration_tests Switch to Rust 2024 edition (#18129) 2025-05-16 13:25:28 +02:00
ruff_python_codegen Switch to Rust 2024 edition (#18129) 2025-05-16 13:25:28 +02:00
ruff_python_formatter Preserve tuple parentheses in case patterns (#18147) 2025-05-22 07:52:21 +02:00
ruff_python_index Switch to Rust 2024 edition (#18129) 2025-05-16 13:25:28 +02:00
ruff_python_literal Switch to Rust 2024 edition (#18129) 2025-05-16 13:25:28 +02:00
ruff_python_parser [ty] Don't warn yield not in function when yield is in function (#18008) 2025-05-21 18:16:25 +02:00
ruff_python_resolver Switch to Rust 2024 edition (#18129) 2025-05-16 13:25:28 +02:00
ruff_python_semantic Switch to Rust 2024 edition (#18129) 2025-05-16 13:25:28 +02:00
ruff_python_stdlib Switch to Rust 2024 edition (#18129) 2025-05-16 13:25:28 +02:00
ruff_python_trivia Switch to Rust 2024 edition (#18129) 2025-05-16 13:25:28 +02:00
ruff_python_trivia_integration_tests Switch to Rust 2024 edition (#18129) 2025-05-16 13:25:28 +02:00
ruff_server Add a ViolationMetadata::rule method (#18234) 2025-05-28 09:27:09 -04:00
ruff_source_file Switch to Rust 2024 edition (#18129) 2025-05-16 13:25:28 +02:00
ruff_text_size Add rustfmt.toml file (#18197) 2025-05-19 11:40:58 -04:00
ruff_wasm Only enable js feature of uuid crate for wasm crates (#18152) 2025-05-26 10:33:51 +01:00
ruff_workspace Switch to Rust 2024 edition (#18129) 2025-05-16 13:25:28 +02:00
ty [ty] Add --config-file CLI arg (#18083) 2025-05-27 08:00:38 +02:00
ty_ide [ty] Tell the user why we inferred the Python version we inferred (#18082) 2025-05-21 11:06:27 -04:00
ty_project [ty] Support publishing diagnostics in the server (#18309) 2025-05-28 13:15:11 +05:30
ty_python_semantic [ty] Synthetic function-like callables (#18242) 2025-05-28 10:00:56 +02:00
ty_server [ty] Support cancellation and retry in the server (#18273) 2025-05-28 10:59:29 +02:00
ty_test [ty] Tell the user why we inferred the Python version we inferred (#18082) 2025-05-21 11:06:27 -04:00
ty_vendored [ty] Type compendium (#18263) 2025-05-23 11:41:31 +02:00
ty_wasm [ty] Gracefully handle salsa cancellations and panics in background request handlers (#18254) 2025-05-26 13:37:49 +01:00