mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 04:08:41 +00:00
chore(linter): add description to website rules generator (#3670)
This commit is contained in:
parent
2173f23d9c
commit
67e0d3077a
2 changed files with 40 additions and 24 deletions
|
|
@ -70,6 +70,18 @@ impl RuleCategory {
|
|||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn description(self) -> &'static str {
|
||||
match self {
|
||||
Self::Correctness => "Code that is outright wrong or useless.",
|
||||
Self::Suspicious => "code that is most likely wrong or useless.",
|
||||
Self::Pedantic => "Lints which are rather strict or have occasional false positives.",
|
||||
Self::Perf => "Code that can be written to run faster.",
|
||||
Self::Style => "Code that should be written in a more idiomatic way.",
|
||||
Self::Restriction => "Lints which prevent the use of language and library features. Must not be enabled as a whole, should be considered on a case-by-case basis before enabling.",
|
||||
Self::Nursery => "New lints that are still under development.",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for RuleCategory {
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
use std::{collections::HashMap, fmt::Write};
|
||||
use std::fmt::Write;
|
||||
|
||||
use rustc_hash::FxHashSet;
|
||||
use rustc_hash::{FxHashMap, FxHashSet};
|
||||
|
||||
use crate::{rules::RULES, Linter};
|
||||
use crate::{rules::RULES, Linter, RuleCategory};
|
||||
|
||||
pub struct RuleTable {
|
||||
pub sections: Vec<RuleTableSection>,
|
||||
|
|
@ -12,7 +12,7 @@ pub struct RuleTable {
|
|||
|
||||
pub struct RuleTableSection {
|
||||
pub rows: Vec<RuleTableRow>,
|
||||
pub category: String,
|
||||
pub category: RuleCategory,
|
||||
pub rule_column_width: usize,
|
||||
pub plugin_column_width: usize,
|
||||
}
|
||||
|
|
@ -20,7 +20,7 @@ pub struct RuleTableSection {
|
|||
pub struct RuleTableRow {
|
||||
pub name: &'static str,
|
||||
pub plugin: String,
|
||||
pub category: String,
|
||||
pub category: RuleCategory,
|
||||
pub documentation: Option<&'static str>,
|
||||
pub turned_on_by_default: bool,
|
||||
}
|
||||
|
|
@ -47,7 +47,7 @@ impl RuleTable {
|
|||
name,
|
||||
documentation: rule.documentation(),
|
||||
plugin: rule.plugin_name().to_string(),
|
||||
category: rule.category().to_string(),
|
||||
category: rule.category(),
|
||||
turned_on_by_default: default_rules.contains(name),
|
||||
}
|
||||
})
|
||||
|
|
@ -58,28 +58,30 @@ impl RuleTable {
|
|||
rows.sort_by_key(|row| (row.plugin.clone(), row.name));
|
||||
|
||||
let mut rows_by_category = rows.into_iter().fold(
|
||||
HashMap::default(),
|
||||
|mut map: HashMap<String, Vec<RuleTableRow>>, row| {
|
||||
map.entry(row.category.clone()).or_default().push(row);
|
||||
FxHashMap::default(),
|
||||
|mut map: FxHashMap<RuleCategory, Vec<RuleTableRow>>, row| {
|
||||
map.entry(row.category).or_default().push(row);
|
||||
map
|
||||
},
|
||||
);
|
||||
|
||||
let sections =
|
||||
["Correctness", "Perf", "Restriction", "Suspicious", "Pedantic", "Style", "Nursery"]
|
||||
.into_iter()
|
||||
.filter_map(|category| {
|
||||
let rows = rows_by_category.remove(category)?;
|
||||
let rule_column_width = rows.iter().map(|r| r.name.len()).max()?;
|
||||
let plugin_column_width = rows.iter().map(|r| r.plugin.len()).max()?;
|
||||
Some(RuleTableSection {
|
||||
rows,
|
||||
category: category.to_string(),
|
||||
rule_column_width,
|
||||
plugin_column_width,
|
||||
})
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
let sections = [
|
||||
RuleCategory::Correctness,
|
||||
RuleCategory::Perf,
|
||||
RuleCategory::Restriction,
|
||||
RuleCategory::Suspicious,
|
||||
RuleCategory::Pedantic,
|
||||
RuleCategory::Style,
|
||||
RuleCategory::Nursery,
|
||||
]
|
||||
.into_iter()
|
||||
.filter_map(|category| {
|
||||
let rows = rows_by_category.remove(&category)?;
|
||||
let rule_column_width = rows.iter().map(|r| r.name.len()).max()?;
|
||||
let plugin_column_width = rows.iter().map(|r| r.plugin.len()).max()?;
|
||||
Some(RuleTableSection { rows, category, rule_column_width, plugin_column_width })
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
RuleTable { total, sections, turned_on_by_default_count: default_rules.len() }
|
||||
}
|
||||
|
|
@ -94,6 +96,8 @@ impl RuleTableSection {
|
|||
let plugin_width = self.plugin_column_width;
|
||||
writeln!(s, "## {} ({}):", category, rows.len()).unwrap();
|
||||
|
||||
writeln!(s, "{}", category.description()).unwrap();
|
||||
|
||||
let x = "";
|
||||
writeln!(s, "| {:<rule_width$} | {:<plugin_width$} | Default |", "Rule name", "Source")
|
||||
.unwrap();
|
||||
|
|
|
|||
Loading…
Reference in a new issue