mirror of
https://github.com/danbulant/oxc
synced 2026-05-20 12:48:38 +00:00
fix(linter): Added missing $schema property to default config (#8625)
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. --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
3e19e4e004
commit
dc912fa58e
1 changed files with 18 additions and 1 deletions
|
|
@ -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,23 @@ 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(),
|
||||
|
|
|
|||
Loading…
Reference in a new issue