mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 17:34:47 -05:00
feat(lint): support --rules --json (#8384)
This commit adds support for "--json" flag in combination with "--rules". List of rules is serialized to JSON and printed.
This commit is contained in:
parent
9029003046
commit
2cbf5c26ac
2 changed files with 22 additions and 7 deletions
27
cli/lint.rs
27
cli/lint.rs
|
@ -96,14 +96,29 @@ pub async fn lint_files(
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn print_rules_list() {
|
fn rule_to_json(rule: Box<dyn LintRule>) -> serde_json::Value {
|
||||||
|
serde_json::json!({
|
||||||
|
"code": rule.code(),
|
||||||
|
"tags": rule.tags(),
|
||||||
|
"docs": rule.docs(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn print_rules_list(json: bool) {
|
||||||
let lint_rules = rules::get_recommended_rules();
|
let lint_rules = rules::get_recommended_rules();
|
||||||
|
|
||||||
// The rules should still be printed even if `--quiet` option is enabled,
|
if json {
|
||||||
// so use `println!` here instead of `info!`.
|
let json_rules: Vec<serde_json::Value> =
|
||||||
println!("Available rules:");
|
lint_rules.into_iter().map(rule_to_json).collect();
|
||||||
for rule in lint_rules {
|
let json_str = serde_json::to_string_pretty(&json_rules).unwrap();
|
||||||
println!(" - {}", rule.code());
|
println!("{}", json_str);
|
||||||
|
} else {
|
||||||
|
// The rules should still be printed even if `--quiet` option is enabled,
|
||||||
|
// so use `println!` here instead of `info!`.
|
||||||
|
println!("Available rules:");
|
||||||
|
for rule in lint_rules {
|
||||||
|
println!(" - {}", rule.code());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -229,7 +229,7 @@ async fn lint_command(
|
||||||
}
|
}
|
||||||
|
|
||||||
if list_rules {
|
if list_rules {
|
||||||
lint::print_rules_list();
|
lint::print_rules_list(json);
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue