From 16d2d03252bcbd777d5e0243176382e1157d0cf7 Mon Sep 17 00:00:00 2001 From: Tapan Prakash Date: Mon, 20 Jan 2025 22:04:18 +0530 Subject: [PATCH 1/3] fix(linter): Added missing $schema property to default config The $schema property was not added when the --init command was used to create the configuration. Now, $schema is added based on the availability of configuration_schema.json in the current working directory. --- apps/oxlint/src/lint.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/apps/oxlint/src/lint.rs b/apps/oxlint/src/lint.rs index 62d6fbd969d47..b58ff2884af23 100644 --- a/apps/oxlint/src/lint.rs +++ b/apps/oxlint/src/lint.rs @@ -12,6 +12,7 @@ use oxc_linter::{ LintFilter, LintOptions, LintService, LintServiceOptions, Linter, Oxlintrc, }; use oxc_span::VALID_EXTENSIONS; +use serde_json::Value; use crate::{ cli::{CliRunResult, LintCommand, LintResult, MiscOptions, Runner, WarningOptions}, @@ -132,7 +133,20 @@ impl Runner for LintRunner { if misc_options.print_config { return CliRunResult::PrintConfigResult { config_file }; } else if basic_options.init { - match fs::write(Self::DEFAULT_OXLINTRC, config_file) { + let schema_relative_path = "node_modules/oxlint/configuration_schema.json"; + let configuration = if self.cwd.join(schema_relative_path).is_file() { + let mut config_json: Value = serde_json::from_str(&config_file).unwrap(); + if let Value::Object(ref mut obj) = config_json { + let mut json_object = serde_json::Map::new(); + json_object.insert("$schema".to_string(), format!("./{}", schema_relative_path).into()); + json_object.extend(obj.clone()); + *obj = json_object; + } + serde_json::to_string_pretty(&config_json).unwrap() + } else { + config_file + }; + match fs::write(Self::DEFAULT_OXLINTRC, configuration) { Ok(()) => { return CliRunResult::ConfigFileInitResult { message: "Configuration file created".to_string(), From 9409f495b91ebffc4cec2542ed97d3a3e5d8fc77 Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Mon, 20 Jan 2025 16:35:46 +0000 Subject: [PATCH 2/3] [autofix.ci] apply automated fixes --- apps/oxlint/src/lint.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/apps/oxlint/src/lint.rs b/apps/oxlint/src/lint.rs index b58ff2884af23..124bb5f9c7826 100644 --- a/apps/oxlint/src/lint.rs +++ b/apps/oxlint/src/lint.rs @@ -138,7 +138,10 @@ impl Runner for LintRunner { let mut config_json: Value = serde_json::from_str(&config_file).unwrap(); if let Value::Object(ref mut obj) = config_json { let mut json_object = serde_json::Map::new(); - json_object.insert("$schema".to_string(), format!("./{}", schema_relative_path).into()); + json_object.insert( + "$schema".to_string(), + format!("./{}", schema_relative_path).into(), + ); json_object.extend(obj.clone()); *obj = json_object; } From d907c6de38d2ea0e3784f363bdd0f6976deb47fa Mon Sep 17 00:00:00 2001 From: Tapan Prakash Date: Mon, 20 Jan 2025 22:08:46 +0530 Subject: [PATCH 3/3] Fixed clippy issues --- apps/oxlint/src/lint.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/oxlint/src/lint.rs b/apps/oxlint/src/lint.rs index 124bb5f9c7826..8b1c29621ef07 100644 --- a/apps/oxlint/src/lint.rs +++ b/apps/oxlint/src/lint.rs @@ -140,7 +140,7 @@ impl Runner for LintRunner { let mut json_object = serde_json::Map::new(); json_object.insert( "$schema".to_string(), - format!("./{}", schema_relative_path).into(), + format!("./{schema_relative_path}").into(), ); json_object.extend(obj.clone()); *obj = json_object;