mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-15 23:05:40 +00:00
Rework upstream categories so we can all_rules()
(#5591)
## Summary This PR reworks the `upstream_categories` mechanism that is only used for documentation purposes to make it easier to generate docs using `all_rules()`. The new implementation also relies on "tribal knowledge" about rule codes, so it's not the best implementation, but gets us forward. Another option would be to change the rule-defining proc macros to allow configuring an optional `RuleCategory`, but that seems more heavy-handed and possibly unnecessary in the long run... Draft since this builds on #5439. cc @charliermarsh :)
This commit is contained in:
parent
089a671adb
commit
24bcbb85a1
5 changed files with 101 additions and 40 deletions
|
@ -7,7 +7,7 @@ use itertools::Itertools;
|
|||
use serde::Serialize;
|
||||
use strum::IntoEnumIterator;
|
||||
|
||||
use ruff::registry::{Linter, RuleNamespace, UpstreamCategory};
|
||||
use ruff::registry::{Linter, RuleNamespace};
|
||||
|
||||
use crate::args::HelpFormat;
|
||||
|
||||
|
@ -37,7 +37,7 @@ pub(crate) fn linter(format: HelpFormat) -> Result<()> {
|
|||
.upstream_categories()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.map(|UpstreamCategory(prefix, ..)| prefix.short_code())
|
||||
.map(|c| c.prefix)
|
||||
.join("/"),
|
||||
prefix => prefix.to_string(),
|
||||
};
|
||||
|
@ -52,9 +52,9 @@ pub(crate) fn linter(format: HelpFormat) -> Result<()> {
|
|||
name: linter_info.name(),
|
||||
categories: linter_info.upstream_categories().map(|cats| {
|
||||
cats.iter()
|
||||
.map(|UpstreamCategory(prefix, name)| LinterCategoryInfo {
|
||||
prefix: prefix.short_code(),
|
||||
name,
|
||||
.map(|c| LinterCategoryInfo {
|
||||
prefix: c.prefix,
|
||||
name: c.category,
|
||||
})
|
||||
.collect()
|
||||
}),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue