mirror of
https://github.com/astral-sh/ruff.git
synced 2025-12-02 00:49:59 +00:00
Create per-rule pages and link from README (#2644)
This commit is contained in:
parent
f1cdd108e6
commit
271e4fda8c
17 changed files with 156 additions and 40 deletions
|
|
@ -1 +1,32 @@
|
|||
//! Generate Markdown documentation for applicable rules.
|
||||
#![allow(clippy::print_stdout, clippy::print_stderr)]
|
||||
|
||||
use std::fs;
|
||||
|
||||
use anyhow::Result;
|
||||
use strum::IntoEnumIterator;
|
||||
|
||||
use ruff::registry::Rule;
|
||||
|
||||
#[derive(clap::Args)]
|
||||
pub struct Args {
|
||||
/// Write the generated docs to stdout (rather than to the filesystem).
|
||||
#[arg(long)]
|
||||
pub(crate) dry_run: bool,
|
||||
}
|
||||
|
||||
pub fn main(args: &Args) -> Result<()> {
|
||||
for rule in Rule::iter() {
|
||||
if let Some(explanation) = rule.explanation() {
|
||||
let explanation = format!("# {} ({})\n\n{}", rule.as_ref(), rule.code(), explanation);
|
||||
|
||||
if args.dry_run {
|
||||
println!("{}", explanation);
|
||||
} else {
|
||||
fs::create_dir_all("docs/rules")?;
|
||||
fs::write(format!("docs/rules/{}.md", rule.as_ref()), explanation)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue