1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-24 08:09:08 -05:00

feat(lint): --rules print all rules (#20256)

The motivation is If I'm using deno lint --rules, I want to see all the
rules especially the one that have no tags, since the recommend ones are
already active

This change also prints the tags associated with the rule inline.
This commit is contained in:
sigmaSd 2023-08-27 10:17:41 +01:00 committed by GitHub
parent e1fe31508c
commit 916ddcef6d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -204,11 +204,11 @@ fn collect_lint_files(files: &FilesConfig) -> Result<Vec<PathBuf>, AnyError> {
}
pub fn print_rules_list(json: bool, maybe_rules_tags: Option<Vec<String>>) {
let lint_rules = get_configured_rules(LintRulesConfig {
exclude: None,
include: None,
tags: maybe_rules_tags,
});
let lint_rules = if maybe_rules_tags.is_none() {
rules::get_all_rules()
} else {
rules::get_filtered_rules(maybe_rules_tags, None, None)
};
if json {
let json_rules: Vec<serde_json::Value> = lint_rules
@ -228,8 +228,19 @@ pub fn print_rules_list(json: bool, maybe_rules_tags: Option<Vec<String>>) {
// so use `println!` here instead of `info!`.
println!("Available rules:");
for rule in lint_rules.iter() {
println!(" - {}", rule.code());
println!(" help: https://lint.deno.land/#{}", rule.code());
print!(" - {}", colors::cyan(rule.code()));
if rule.tags().is_empty() {
println!();
} else {
println!(" [{}]", colors::gray(rule.tags().join(", ")))
}
println!(
"{}",
colors::gray(format!(
" help: https://lint.deno.land/#{}",
rule.code()
))
);
println!();
}
}