@@ -86,7 +86,12 @@ impl Runner for LintRunner {
86
86
87
87
let filter = match Self :: get_filters ( filter) {
88
88
Ok ( filter) => filter,
89
- Err ( e) => return e,
89
+ Err ( ( result, message) ) => {
90
+ stdout. write_all ( message. as_bytes ( ) ) . or_else ( Self :: check_for_writer_error) . unwrap ( ) ;
91
+ stdout. flush ( ) . unwrap ( ) ;
92
+
93
+ return result;
94
+ }
90
95
} ;
91
96
92
97
let extensions = VALID_EXTENSIONS
@@ -99,7 +104,13 @@ impl Runner for LintRunner {
99
104
Self :: find_oxlint_config ( & self . cwd , basic_options. config . as_ref ( ) ) ;
100
105
101
106
if let Err ( err) = config_search_result {
102
- return err;
107
+ stdout
108
+ . write_all ( format ! ( "Failed to parse configuration file.\n {err}\n " ) . as_bytes ( ) )
109
+ . or_else ( Self :: check_for_writer_error)
110
+ . unwrap ( ) ;
111
+ stdout. flush ( ) . unwrap ( ) ;
112
+
113
+ return CliRunResult :: InvalidOptionConfig ;
103
114
}
104
115
105
116
let mut oxlintrc = config_search_result. unwrap ( ) ;
@@ -178,9 +189,13 @@ impl Runner for LintRunner {
178
189
let handler = GraphicalReportHandler :: new ( ) ;
179
190
let mut err = String :: new ( ) ;
180
191
handler. render_report ( & mut err, & diagnostic) . unwrap ( ) ;
181
- return CliRunResult :: InvalidOptions {
182
- message : format ! ( "Failed to parse configuration file.\n {err}" ) ,
183
- } ;
192
+ stdout
193
+ . write_all ( format ! ( "Failed to parse configuration file.\n {err}\n " ) . as_bytes ( ) )
194
+ . or_else ( Self :: check_for_writer_error)
195
+ . unwrap ( ) ;
196
+ stdout. flush ( ) . unwrap ( ) ;
197
+
198
+ return CliRunResult :: InvalidOptionConfig ;
184
199
}
185
200
} ;
186
201
@@ -193,11 +208,12 @@ impl Runner for LintRunner {
193
208
options = options. with_tsconfig ( path) ;
194
209
} else {
195
210
let path = if path. is_relative ( ) { options. cwd ( ) . join ( path) } else { path. clone ( ) } ;
196
- return CliRunResult :: InvalidOptions {
197
- message : format ! (
198
- "The tsconfig file {path:?} does not exist, Please provide a valid tsconfig file." ,
199
- ) ,
200
- } ;
211
+ stdout. write_all ( format ! (
212
+ "The tsconfig file {path:?} does not exist, Please provide a valid tsconfig file.\n " ,
213
+ ) . as_bytes ( ) ) . or_else ( Self :: check_for_writer_error) . unwrap ( ) ;
214
+ stdout. flush ( ) . unwrap ( ) ;
215
+
216
+ return CliRunResult :: InvalidOptionTsConfig ;
201
217
}
202
218
}
203
219
@@ -262,7 +278,7 @@ impl LintRunner {
262
278
// in one place.
263
279
fn get_filters (
264
280
filters_arg : Vec < ( AllowWarnDeny , String ) > ,
265
- ) -> Result < Vec < LintFilter > , CliRunResult > {
281
+ ) -> Result < Vec < LintFilter > , ( CliRunResult , String ) > {
266
282
let mut filters = Vec :: with_capacity ( filters_arg. len ( ) ) ;
267
283
268
284
for ( severity, filter_arg) in filters_arg {
@@ -271,23 +287,22 @@ impl LintRunner {
271
287
filters. push ( filter) ;
272
288
}
273
289
Err ( InvalidFilterKind :: Empty ) => {
274
- return Err ( CliRunResult :: InvalidOptions {
275
- message : format ! ( "Cannot {severity} an empty filter." ) ,
276
- } ) ;
290
+ return Err ( (
291
+ CliRunResult :: InvalidOptionSeverityWithoutFilter ,
292
+ format ! ( "Cannot {severity} an empty filter.\n " ) ,
293
+ ) ) ;
277
294
}
278
295
Err ( InvalidFilterKind :: PluginMissing ( filter) ) => {
279
- return Err ( CliRunResult :: InvalidOptions {
280
- message : format ! (
281
- "Failed to {severity} filter {filter}: Plugin name is missing. Expected <plugin>/<rule>"
296
+ return Err ( ( CliRunResult :: InvalidOptionSeverityWithoutPluginName , format ! (
297
+ "Failed to {severity} filter {filter}: Plugin name is missing. Expected <plugin>/<rule>\n "
282
298
) ,
283
- } ) ;
299
+ ) ) ;
284
300
}
285
301
Err ( InvalidFilterKind :: RuleMissing ( filter) ) => {
286
- return Err ( CliRunResult :: InvalidOptions {
287
- message : format ! (
288
- "Failed to {severity} filter {filter}: Rule name is missing. Expected <plugin>/<rule>"
302
+ return Err ( ( CliRunResult :: InvalidOptionSeverityWithoutRuleName , format ! (
303
+ "Failed to {severity} filter {filter}: Rule name is missing. Expected <plugin>/<rule>\n "
289
304
) ,
290
- } ) ;
305
+ ) ) ;
291
306
}
292
307
}
293
308
}
@@ -296,10 +311,10 @@ impl LintRunner {
296
311
}
297
312
298
313
// finds the oxlint config
299
- // when config is provided, but not found, an CliRunResult is returned, else the oxlintrc config file is returned
314
+ // when config is provided, but not found, an String with the formatted error is returned, else the oxlintrc config file is returned
300
315
// when no config is provided, it will search for the default file names in the current working directory
301
316
// when no file is found, the default configuration is returned
302
- fn find_oxlint_config ( cwd : & Path , config : Option < & PathBuf > ) -> Result < Oxlintrc , CliRunResult > {
317
+ fn find_oxlint_config ( cwd : & Path , config : Option < & PathBuf > ) -> Result < Oxlintrc , String > {
303
318
if let Some ( config_path) = config {
304
319
let full_path = cwd. join ( config_path) ;
305
320
return match Oxlintrc :: from_file ( & full_path) {
@@ -308,9 +323,7 @@ impl LintRunner {
308
323
let handler = GraphicalReportHandler :: new ( ) ;
309
324
let mut err = String :: new ( ) ;
310
325
handler. render_report ( & mut err, & diagnostic) . unwrap ( ) ;
311
- return Err ( CliRunResult :: InvalidOptions {
312
- message : format ! ( "Failed to parse configuration file.\n {err}" ) ,
313
- } ) ;
326
+ return Err ( err) ;
314
327
}
315
328
} ;
316
329
}
@@ -568,9 +581,7 @@ mod test {
568
581
Tester :: new ( ) . test ( & [ "--tsconfig" , "fixtures/tsconfig/tsconfig.json" ] ) ;
569
582
570
583
// failed
571
- assert ! ( Tester :: new( )
572
- . get_invalid_option_result( & [ "--tsconfig" , "oxc/tsconfig.json" ] )
573
- . contains( "oxc/tsconfig.json\" does not exist, Please provide a valid tsconfig file." ) ) ;
584
+ Tester :: new ( ) . test_and_snapshot ( & [ "--tsconfig" , "oxc/tsconfig.json" ] ) ;
574
585
}
575
586
576
587
#[ test]
0 commit comments