ruff/scripts
Martin Fischer 4758ee6ac4 refactor: Generate Linter -> RuleSelector mapping via macro
To enable ruff_dev to automatically generate the rule Markdown tables in
the README the ruff library contained the following function:

    Linter::codes() -> Vec<RuleSelector>

which was slightly changed to `fn prefixes(&self) -> Prefixes` in
9dc66b5a65 to enable ruff_dev to split
up the Markdown tables for linters that have multiple prefixes
(pycodestyle has E & W, Pylint has PLC, PLE, PLR & PLW).

The definition of this method was however largely redundant with the
#[prefix] macro attributes in the Linter enum, which are used to
derive the Linter::parse_code function, used by the --explain command.

This commit removes the redundant Linter::prefixes by introducing a
same-named method with a different signature to the RuleNamespace trait:

     fn prefixes(&self) -> &'static [&'static str];

As well as implementing IntoIterator<Rule> for &Linter. We extend the
extisting RuleNamespace proc macro to automatically derive both
implementations from the Linter enum definition.

To support the previously mentioned Markdown table splitting we
introduce a very simple hand-written method to the Linter impl:

    fn categories(&self) -> Option<&'static [LinterCategory]>;
2023-01-22 11:51:29 -05:00
..
benchmarks Add benchmark scripts for no-IO (#1925) 2023-01-16 17:38:40 -05:00
_utils.py refactor: Rename RuleOrigin to Linter 2023-01-20 20:25:57 -05:00
add_plugin.py refactor: Generate Linter -> RuleSelector mapping via macro 2023-01-22 11:51:29 -05:00
add_rule.py feat: update scripts to new rules structure (#2078) 2023-01-21 19:19:58 -05:00
pyproject.toml fix: Update add_rule.py to account for 81996f1bc 2023-01-20 08:09:54 -05:00