11use std:: {
22 env,
33 ffi:: OsStr ,
4- fs,
54 io:: { ErrorKind , Write } ,
65 path:: { Path , PathBuf , absolute} ,
76 sync:: Arc ,
@@ -11,7 +10,6 @@ use std::{
1110use cow_utils:: CowUtils ;
1211use ignore:: { gitignore:: Gitignore , overrides:: OverrideBuilder } ;
1312use rustc_hash:: { FxHashMap , FxHashSet } ;
14- use serde_json:: Value ;
1513
1614use oxc_diagnostics:: { DiagnosticSender , DiagnosticService , GraphicalReportHandler , OxcDiagnostic } ;
1715use oxc_linter:: {
@@ -64,6 +62,10 @@ impl CliRunner {
6462 ..
6563 } = self . options ;
6664
65+ if basic_options. init {
66+ return crate :: mode:: run_init ( & self . cwd , stdout) ;
67+ }
68+
6769 let external_linter = self . external_linter . as_ref ( ) ;
6870
6971 let mut paths = paths;
@@ -215,11 +217,8 @@ impl CliRunner {
215217 oxlintrc. plugins = Some ( plugins) ;
216218 }
217219
218- let oxlintrc_for_print = if misc_options. print_config || basic_options. init {
219- Some ( oxlintrc. clone ( ) )
220- } else {
221- None
222- } ;
220+ let oxlintrc_for_print =
221+ if misc_options. print_config { Some ( oxlintrc. clone ( ) ) } else { None } ;
223222
224223 let config_builder = match ConfigStoreBuilder :: from_oxlintrc (
225224 false ,
@@ -254,32 +253,6 @@ impl CliRunner {
254253 print_and_flush_stdout ( stdout, "\n " ) ;
255254
256255 return CliRunResult :: PrintConfigResult ;
257- } else if basic_options. init {
258- let schema_relative_path = "node_modules/oxlint/configuration_schema.json" ;
259- let configuration = if self . cwd . join ( schema_relative_path) . is_file ( ) {
260- let mut config_json: Value = serde_json:: from_str ( & config_file) . unwrap ( ) ;
261- if let Value :: Object ( ref mut obj) = config_json {
262- let mut json_object = serde_json:: Map :: new ( ) ;
263- json_object. insert (
264- "$schema" . to_string ( ) ,
265- format ! ( "./{schema_relative_path}" ) . into ( ) ,
266- ) ;
267- json_object. extend ( obj. clone ( ) ) ;
268- * obj = json_object;
269- }
270- serde_json:: to_string_pretty ( & config_json) . unwrap ( )
271- } else {
272- config_file
273- } ;
274-
275- if fs:: write ( DEFAULT_OXLINTRC , configuration) . is_ok ( ) {
276- print_and_flush_stdout ( stdout, "Configuration file created\n " ) ;
277- return CliRunResult :: ConfigFileInitSucceeded ;
278- }
279-
280- // failed case
281- print_and_flush_stdout ( stdout, "Failed to create configuration file\n " ) ;
282- return CliRunResult :: ConfigFileInitFailed ;
283256 }
284257 }
285258
0 commit comments