diff options
author | Kamil Ogórek <kamil.ogorek@gmail.com> | 2024-09-05 10:51:40 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-05 08:51:40 +0000 |
commit | 2c4d99a4586a8aa143feb8614e3b0d4de09dd190 (patch) | |
tree | 0c07ee12254da10d9710616be8cc98a32c0f35c7 /cli/tools/lint/mod.rs | |
parent | 49340b96f6b3603186e03f0102b99bc4a34a1b63 (diff) |
feat: include version number in all --json based outputs (#25335)
Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
Diffstat (limited to 'cli/tools/lint/mod.rs')
-rw-r--r-- | cli/tools/lint/mod.rs | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/cli/tools/lint/mod.rs b/cli/tools/lint/mod.rs index 5b51b2b40..d5d174bf7 100644 --- a/cli/tools/lint/mod.rs +++ b/cli/tools/lint/mod.rs @@ -45,6 +45,7 @@ use crate::colors; use crate::factory::CliFactory; use crate::graph_util::ModuleGraphCreator; use crate::tools::fmt::run_parallelized; +use crate::util::display; use crate::util::file_watcher; use crate::util::fs::canonicalize_path; use crate::util::path::is_script_ext; @@ -60,6 +61,8 @@ pub use rules::collect_no_slow_type_diagnostics; pub use rules::ConfiguredRules; pub use rules::LintRuleProvider; +const JSON_SCHEMA_VERSION: u8 = 1; + static STDIN_FILE_NAME: &str = "$deno$stdin.ts"; pub async fn lint( @@ -440,18 +443,20 @@ pub fn print_rules_list(json: bool, maybe_rules_tags: Option<Vec<String>>) { .rules; if json { - let json_rules: Vec<serde_json::Value> = lint_rules - .iter() - .map(|rule| { - serde_json::json!({ - "code": rule.code(), - "tags": rule.tags(), - "docs": rule.docs(), + let json_output = serde_json::json!({ + "version": JSON_SCHEMA_VERSION, + "rules": lint_rules + .iter() + .map(|rule| { + serde_json::json!({ + "code": rule.code(), + "tags": rule.tags(), + "docs": rule.docs(), + }) }) - }) - .collect(); - let json_str = serde_json::to_string_pretty(&json_rules).unwrap(); - println!("{json_str}"); + .collect::<Vec<serde_json::Value>>(), + }); + display::write_json_to_stdout(&json_output).unwrap(); } else { // The rules should still be printed even if `--quiet` option is enabled, // so use `println!` here instead of `info!`. |