From bb12fe9d0c71fcb36a5000260f62dbf8411b74b4 Mon Sep 17 00:00:00 2001 From: Simon Brugman Date: Mon, 16 Sep 2024 18:21:26 +0200 Subject: [PATCH] DOCS: navigate back to rule overview linter (#13368) --- crates/ruff_dev/src/generate_docs.rs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/crates/ruff_dev/src/generate_docs.rs b/crates/ruff_dev/src/generate_docs.rs index 90c88cda5c2be..c86814031c1d1 100644 --- a/crates/ruff_dev/src/generate_docs.rs +++ b/crates/ruff_dev/src/generate_docs.rs @@ -6,6 +6,7 @@ use std::fs; use std::path::PathBuf; use anyhow::Result; +use itertools::Itertools; use regex::{Captures, Regex}; use strum::IntoEnumIterator; @@ -33,7 +34,26 @@ pub(crate) fn main(args: &Args) -> Result<()> { let (linter, _) = Linter::parse_code(&rule.noqa_code().to_string()).unwrap(); if linter.url().is_some() { - output.push_str(&format!("Derived from the **{}** linter.", linter.name())); + let common_prefix: String = match linter.common_prefix() { + "" => linter + .upstream_categories() + .unwrap() + .iter() + .map(|c| c.prefix) + .join("-"), + prefix => prefix.to_string(), + }; + let anchor = format!( + "{}-{}", + linter.name().to_lowercase(), + common_prefix.to_lowercase() + ); + + output.push_str(&format!( + "Derived from the **[{}](../rules.md#{})** linter.", + linter.name(), + anchor + )); output.push('\n'); output.push('\n'); }