Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion apps/oxlint/src/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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(),
Expand Down
Loading