mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +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,
|
_ => 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 {
|
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 struct RuleTable {
|
||||||
pub sections: Vec<RuleTableSection>,
|
pub sections: Vec<RuleTableSection>,
|
||||||
|
|
@ -12,7 +12,7 @@ pub struct RuleTable {
|
||||||
|
|
||||||
pub struct RuleTableSection {
|
pub struct RuleTableSection {
|
||||||
pub rows: Vec<RuleTableRow>,
|
pub rows: Vec<RuleTableRow>,
|
||||||
pub category: String,
|
pub category: RuleCategory,
|
||||||
pub rule_column_width: usize,
|
pub rule_column_width: usize,
|
||||||
pub plugin_column_width: usize,
|
pub plugin_column_width: usize,
|
||||||
}
|
}
|
||||||
|
|
@ -20,7 +20,7 @@ pub struct RuleTableSection {
|
||||||
pub struct RuleTableRow {
|
pub struct RuleTableRow {
|
||||||
pub name: &'static str,
|
pub name: &'static str,
|
||||||
pub plugin: String,
|
pub plugin: String,
|
||||||
pub category: String,
|
pub category: RuleCategory,
|
||||||
pub documentation: Option<&'static str>,
|
pub documentation: Option<&'static str>,
|
||||||
pub turned_on_by_default: bool,
|
pub turned_on_by_default: bool,
|
||||||
}
|
}
|
||||||
|
|
@ -47,7 +47,7 @@ impl RuleTable {
|
||||||
name,
|
name,
|
||||||
documentation: rule.documentation(),
|
documentation: rule.documentation(),
|
||||||
plugin: rule.plugin_name().to_string(),
|
plugin: rule.plugin_name().to_string(),
|
||||||
category: rule.category().to_string(),
|
category: rule.category(),
|
||||||
turned_on_by_default: default_rules.contains(name),
|
turned_on_by_default: default_rules.contains(name),
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
@ -58,26 +58,28 @@ impl RuleTable {
|
||||||
rows.sort_by_key(|row| (row.plugin.clone(), row.name));
|
rows.sort_by_key(|row| (row.plugin.clone(), row.name));
|
||||||
|
|
||||||
let mut rows_by_category = rows.into_iter().fold(
|
let mut rows_by_category = rows.into_iter().fold(
|
||||||
HashMap::default(),
|
FxHashMap::default(),
|
||||||
|mut map: HashMap<String, Vec<RuleTableRow>>, row| {
|
|mut map: FxHashMap<RuleCategory, Vec<RuleTableRow>>, row| {
|
||||||
map.entry(row.category.clone()).or_default().push(row);
|
map.entry(row.category).or_default().push(row);
|
||||||
map
|
map
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
let sections =
|
let sections = [
|
||||||
["Correctness", "Perf", "Restriction", "Suspicious", "Pedantic", "Style", "Nursery"]
|
RuleCategory::Correctness,
|
||||||
|
RuleCategory::Perf,
|
||||||
|
RuleCategory::Restriction,
|
||||||
|
RuleCategory::Suspicious,
|
||||||
|
RuleCategory::Pedantic,
|
||||||
|
RuleCategory::Style,
|
||||||
|
RuleCategory::Nursery,
|
||||||
|
]
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter_map(|category| {
|
.filter_map(|category| {
|
||||||
let rows = rows_by_category.remove(category)?;
|
let rows = rows_by_category.remove(&category)?;
|
||||||
let rule_column_width = rows.iter().map(|r| r.name.len()).max()?;
|
let rule_column_width = rows.iter().map(|r| r.name.len()).max()?;
|
||||||
let plugin_column_width = rows.iter().map(|r| r.plugin.len()).max()?;
|
let plugin_column_width = rows.iter().map(|r| r.plugin.len()).max()?;
|
||||||
Some(RuleTableSection {
|
Some(RuleTableSection { rows, category, rule_column_width, plugin_column_width })
|
||||||
rows,
|
|
||||||
category: category.to_string(),
|
|
||||||
rule_column_width,
|
|
||||||
plugin_column_width,
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
|
|
@ -94,6 +96,8 @@ impl RuleTableSection {
|
||||||
let plugin_width = self.plugin_column_width;
|
let plugin_width = self.plugin_column_width;
|
||||||
writeln!(s, "## {} ({}):", category, rows.len()).unwrap();
|
writeln!(s, "## {} ({}):", category, rows.len()).unwrap();
|
||||||
|
|
||||||
|
writeln!(s, "{}", category.description()).unwrap();
|
||||||
|
|
||||||
let x = "";
|
let x = "";
|
||||||
writeln!(s, "| {:<rule_width$} | {:<plugin_width$} | Default |", "Rule name", "Source")
|
writeln!(s, "| {:<rule_width$} | {:<plugin_width$} | Default |", "Rule name", "Source")
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue