Skip to content

Commit 654ee5e

Browse files
committed
test(linter): ensure rule docs are valid markdown
1 parent 118821e commit 654ee5e

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed

Cargo.lock

+17-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/oxc_linter/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,4 @@ schemars = { workspace = true, features = ["indexmap2"] }
5757
static_assertions = { workspace = true }
5858
insta = { workspace = true }
5959
project-root = { workspace = true }
60+
markdown = { version = "1.0.0-alpha.18" }

crates/oxc_linter/src/rule.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -235,12 +235,21 @@ impl RuleWithSeverity {
235235
#[cfg(test)]
236236
mod test {
237237
use crate::rules::RULES;
238+
use markdown::{to_html_with_options, Options};
238239

239240
#[test]
240241
fn ensure_documentation() {
241242
assert!(!RULES.is_empty());
243+
let options = Options::gfm();
242244
for rule in RULES.iter() {
243-
assert!(rule.documentation().is_some_and(|s| !s.is_empty()), "{}", rule.name());
245+
assert!(
246+
rule.documentation().is_some_and(|s| !s.is_empty()),
247+
"Rule '{}' is missing documentation.",
248+
rule.name()
249+
);
250+
// will panic if provided invalid html
251+
let html = to_html_with_options(rule.documentation().unwrap(), &options).unwrap();
252+
assert!(!html.is_empty());
244253
}
245254
}
246255
}

tasks/website/src/linter/rules/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ fn write_rule_doc_pages(table: &RuleTable, outdir: &Path) {
8080
let plugin_path = outdir.join(&rule.plugin);
8181
fs::create_dir_all(&plugin_path).unwrap();
8282
let page_path = plugin_path.join(format!("{}.md", rule.name));
83+
if page_path.exists() {
84+
fs::remove_file(&page_path).unwrap();
85+
}
8386
println!("{}", page_path.display());
8487
let docs = render_rule_docs_page(rule).unwrap();
8588
fs::write(&page_path, docs).unwrap();

0 commit comments

Comments
 (0)