ruff/scripts
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
..
benchmarks Bump 0.11.11 (#18259) 2025-05-22 13:09:44 -05:00
release Update release script to match uv (#11496) 2024-07-03 07:35:28 -05:00
ty_benchmark Rename Red Knot (#17820) 2025-05-03 19:49:15 +02:00
_utils.py Use __future__ imports in scripts (#5301) 2023-06-22 11:40:16 -04:00
add_plugin.py [pydoclint] Implement docstring-missing-exception and docstring-extraneous-exception (DOC501, DOC502) (#11471) 2024-07-20 19:41:51 +00:00
add_rule.py Add a ViolationMetadata::rule method (#18234) 2025-05-28 09:27:09 -04:00
check_docs_formatted.py Check for backtick-quoted shortcut links in CI (#16114) 2025-02-14 08:37:46 +01:00
check_ecosystem.py Standardise ruff config (#15558) 2025-01-21 12:09:11 +01:00
Dockerfile.ecosystem Remove outdated feature flag from Dockerfile.ecosystem (#4620) 2023-05-24 08:19:08 +00:00
ecosystem_all_check.py Update pre-commit dependencies (#10698) 2024-04-06 23:00:41 +00:00
ecosystem_all_check.sh Rename Autofix to Fix (#7657) 2023-09-28 10:53:05 +00:00
ecosystem_all_check_entrypoint.sh Make ecosystem all check more generic (#4629) 2023-05-24 16:26:23 +02:00
formatter_ecosystem_checks.sh Improve the performance of the formatter instability check job (#14471) 2024-11-20 08:55:10 -06:00
generate_builtin_modules.py Use #[expect(lint)] over #[allow(lint)] where possible (#17822) 2025-05-03 21:20:31 +02:00
generate_known_standard_library.py python_stdlib: update for 3.14 (#18014) 2025-05-11 11:25:54 -05:00
generate_mkdocs.py Update editor integrations link in README (#17977) 2025-05-26 09:50:09 +01:00
pyproject.toml Standardise ruff config (#15558) 2025-01-21 12:09:11 +01:00
release.sh Update release script to match uv (#11496) 2024-07-03 07:35:28 -05:00
transform_readme.py Update pre-commit dependencies (#10698) 2024-04-06 23:00:41 +00:00
update_ambiguous_characters.py Update pre-commit dependencies (#10698) 2024-04-06 23:00:41 +00:00
update_schemastore.py Update the schemastore script to match changes in ty (#17952) 2025-05-08 09:31:52 -05:00