-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 9dc66b5 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]>;
- Loading branch information
1 parent
c3dd1b0
commit 4758ee6
Showing
6 changed files
with
77 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters