mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-03 18:28:24 +00:00
Remove rule tables from README
This commit is contained in:
parent
bf8108469f
commit
8195873cdf
5 changed files with 11 additions and 835 deletions
|
@ -2,9 +2,7 @@
|
|||
|
||||
use anyhow::Result;
|
||||
|
||||
use crate::{
|
||||
generate_cli_help, generate_docs, generate_json_schema, generate_options, generate_rules_table,
|
||||
};
|
||||
use crate::{generate_cli_help, generate_docs, generate_json_schema, generate_options};
|
||||
|
||||
#[derive(clap::Args)]
|
||||
pub struct Args {
|
||||
|
@ -20,9 +18,6 @@ pub fn main(args: &Args) -> Result<()> {
|
|||
generate_json_schema::main(&generate_json_schema::Args {
|
||||
dry_run: args.dry_run,
|
||||
})?;
|
||||
generate_rules_table::main(&generate_rules_table::Args {
|
||||
dry_run: args.dry_run,
|
||||
})?;
|
||||
generate_options::main(&generate_options::Args {
|
||||
dry_run: args.dry_run,
|
||||
})?;
|
||||
|
|
|
@ -1,26 +1,12 @@
|
|||
//! Generate a Markdown-compatible table of supported lint rules.
|
||||
#![allow(clippy::print_stdout, clippy::print_stderr)]
|
||||
|
||||
use anyhow::Result;
|
||||
use itertools::Itertools;
|
||||
use ruff::registry::{Linter, Rule, RuleNamespace, UpstreamCategory};
|
||||
use strum::IntoEnumIterator;
|
||||
|
||||
use crate::utils::replace_readme_section;
|
||||
|
||||
const TABLE_BEGIN_PRAGMA: &str = "<!-- Begin auto-generated sections. -->\n";
|
||||
const TABLE_END_PRAGMA: &str = "<!-- End auto-generated sections. -->";
|
||||
|
||||
const FIX_SYMBOL: &str = "🛠";
|
||||
const URL_PREFIX: &str = "https://beta.ruff.rs/docs/rules";
|
||||
|
||||
#[derive(clap::Args)]
|
||||
pub struct Args {
|
||||
/// Write the generated table to stdout (rather than to `README.md`).
|
||||
#[arg(long)]
|
||||
pub(crate) dry_run: bool,
|
||||
}
|
||||
|
||||
fn generate_table(table_out: &mut String, rules: impl IntoIterator<Item = Rule>, linter: &Linter) {
|
||||
table_out.push_str("| Code | Name | Message | Fix |");
|
||||
table_out.push('\n');
|
||||
|
@ -51,7 +37,7 @@ fn generate_table(table_out: &mut String, rules: impl IntoIterator<Item = Rule>,
|
|||
table_out.push('\n');
|
||||
}
|
||||
|
||||
pub fn main(args: &Args) -> Result<()> {
|
||||
pub fn generate() -> String {
|
||||
// Generate the table string.
|
||||
let mut table_out = format!("The {FIX_SYMBOL} emoji indicates that a rule is automatically fixable by the `--fix` command-line option.\n\n");
|
||||
for linter in Linter::iter() {
|
||||
|
@ -108,11 +94,5 @@ pub fn main(args: &Args) -> Result<()> {
|
|||
}
|
||||
}
|
||||
|
||||
if args.dry_run {
|
||||
print!("Rules Tables: {table_out}");
|
||||
} else {
|
||||
replace_readme_section(&table_out, TABLE_BEGIN_PRAGMA, TABLE_END_PRAGMA)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
table_out
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ enum Command {
|
|||
/// Generate JSON schema for the TOML configuration file.
|
||||
GenerateJSONSchema(generate_json_schema::Args),
|
||||
/// Generate a Markdown-compatible table of supported lint rules.
|
||||
GenerateRulesTable(generate_rules_table::Args),
|
||||
GenerateRulesTable,
|
||||
/// Generate a Markdown-compatible listing of configuration options.
|
||||
GenerateOptions(generate_options::Args),
|
||||
/// Generate CLI help.
|
||||
|
@ -53,10 +53,11 @@ enum Command {
|
|||
|
||||
fn main() -> Result<()> {
|
||||
let args = Args::parse();
|
||||
#[allow(clippy::print_stdout)]
|
||||
match &args.command {
|
||||
Command::GenerateAll(args) => generate_all::main(args)?,
|
||||
Command::GenerateJSONSchema(args) => generate_json_schema::main(args)?,
|
||||
Command::GenerateRulesTable(args) => generate_rules_table::main(args)?,
|
||||
Command::GenerateRulesTable => println!("{}", generate_rules_table::generate()),
|
||||
Command::GenerateOptions(args) => generate_options::main(args)?,
|
||||
Command::GenerateCliHelp(args) => generate_cli_help::main(args)?,
|
||||
Command::GenerateDocs(args) => generate_docs::main(args)?,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue