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:
Aarni Koskela 2023-07-10 16:41:26 +03:00 committed by GitHub
parent 089a671adb
commit 24bcbb85a1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 101 additions and 40 deletions

View file

@ -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()
}),