Skip to content

Commit

Permalink
test(linter): ensure rule docs are valid markdown
Browse files Browse the repository at this point in the history
  • Loading branch information
DonIsaac committed Aug 5, 2024
1 parent 90fe51f commit 3d74cce
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
18 changes: 17 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/oxc_linter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,4 @@ schemars = { workspace = true, features = ["indexmap2"] }
static_assertions = { workspace = true }
insta = { workspace = true }
project-root = { workspace = true }
markdown = { version = "1.0.0-alpha.18" }
11 changes: 10 additions & 1 deletion crates/oxc_linter/src/rule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,12 +235,21 @@ impl RuleWithSeverity {
#[cfg(test)]
mod test {
use crate::rules::RULES;
use markdown::{to_html_with_options, Options};

#[test]
fn ensure_documentation() {
assert!(!RULES.is_empty());
let options = Options::gfm();
for rule in RULES.iter() {
assert!(rule.documentation().is_some_and(|s| !s.is_empty()), "{}", rule.name());
assert!(
rule.documentation().is_some_and(|s| !s.is_empty()),
"Rule '{}' is missing documentation.",
rule.name()
);
// will panic if provided invalid html
let html = to_html_with_options(rule.documentation().unwrap(), &options).unwrap();
assert!(!html.is_empty());
}
}
}
3 changes: 3 additions & 0 deletions tasks/website/src/linter/rules/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ fn write_rule_doc_pages(table: &RuleTable, outdir: &Path) {
let plugin_path = outdir.join(&rule.plugin);
fs::create_dir_all(&plugin_path).unwrap();
let page_path = plugin_path.join(format!("{}.md", rule.name));
if page_path.exists() {
fs::remove_file(&page_path).unwrap();
}
println!("{}", page_path.display());
let docs = render_rule_docs_page(rule).unwrap();
fs::write(&page_path, docs).unwrap();
Expand Down

0 comments on commit 3d74cce

Please sign in to comment.