@@ -7,7 +7,7 @@ use std::{
7
7
8
8
use cow_utils:: CowUtils ;
9
9
use ignore:: { gitignore:: Gitignore , overrides:: OverrideBuilder } ;
10
- use oxc_diagnostics:: { DiagnosticService , GraphicalReportHandler } ;
10
+ use oxc_diagnostics:: { DiagnosticService , GraphicalReportHandler , OxcDiagnostic } ;
11
11
use oxc_linter:: {
12
12
AllowWarnDeny , ConfigStore , ConfigStoreBuilder , InvalidFilterKind , LintFilter , LintOptions ,
13
13
LintService , LintServiceOptions , Linter , Oxlintrc , loader:: LINT_PARTIAL_LOADER_EXT ,
@@ -200,9 +200,28 @@ impl Runner for LintRunner {
200
200
201
201
// iterate over each config and build the ConfigStore
202
202
for ( dir, oxlintrc) in nested_oxlintrc {
203
+ // TODO(refactor): clean up all of the error handling in this function
204
+ let builder = match ConfigStoreBuilder :: from_oxlintrc ( false , oxlintrc) {
205
+ Ok ( builder) => builder,
206
+ Err ( e) => {
207
+ let handler = GraphicalReportHandler :: new ( ) ;
208
+ let mut err = String :: new ( ) ;
209
+ handler
210
+ . render_report ( & mut err, & OxcDiagnostic :: error ( e. to_string ( ) ) )
211
+ . unwrap ( ) ;
212
+ stdout
213
+ . write_all (
214
+ format ! ( "Failed to parse configuration file.\n {err}\n " ) . as_bytes ( ) ,
215
+ )
216
+ . or_else ( Self :: check_for_writer_error)
217
+ . unwrap ( ) ;
218
+ stdout. flush ( ) . unwrap ( ) ;
219
+
220
+ return CliRunResult :: InvalidOptionConfig ;
221
+ }
222
+ }
203
223
// TODO(perf): figure out if we can avoid cloning `filter`
204
- let builder =
205
- ConfigStoreBuilder :: from_oxlintrc ( false , oxlintrc) . with_filters ( filter. clone ( ) ) ;
224
+ . with_filters ( filter. clone ( ) ) ;
206
225
match builder. build ( ) {
207
226
Ok ( config) => nested_configs. insert ( dir. to_path_buf ( ) , config) ,
208
227
Err ( diagnostic) => {
@@ -230,8 +249,22 @@ impl Runner for LintRunner {
230
249
} else {
231
250
None
232
251
} ;
233
- let config_builder =
234
- ConfigStoreBuilder :: from_oxlintrc ( false , oxlintrc) . with_filters ( filter) ;
252
+ let config_builder = match ConfigStoreBuilder :: from_oxlintrc ( false , oxlintrc) {
253
+ Ok ( builder) => builder,
254
+ Err ( e) => {
255
+ let handler = GraphicalReportHandler :: new ( ) ;
256
+ let mut err = String :: new ( ) ;
257
+ handler. render_report ( & mut err, & OxcDiagnostic :: error ( e. to_string ( ) ) ) . unwrap ( ) ;
258
+ stdout
259
+ . write_all ( format ! ( "Failed to parse configuration file.\n {err}\n " ) . as_bytes ( ) )
260
+ . or_else ( Self :: check_for_writer_error)
261
+ . unwrap ( ) ;
262
+ stdout. flush ( ) . unwrap ( ) ;
263
+
264
+ return CliRunResult :: InvalidOptionConfig ;
265
+ }
266
+ }
267
+ . with_filters ( filter) ;
235
268
236
269
if let Some ( basic_config_file) = oxlintrc_for_print {
237
270
let config_file = config_builder. resolve_final_config_file ( basic_config_file) ;
@@ -982,4 +1015,11 @@ mod test {
982
1015
] ;
983
1016
Tester :: new ( ) . with_cwd ( "fixtures/nested_config" . into ( ) ) . test_and_snapshot ( args) ;
984
1017
}
1018
+
1019
+ #[ test]
1020
+ fn test_extends_explicit_config ( ) {
1021
+ // Check that referencing a config file that extends other config files works as expected
1022
+ let args = & [ "--config" , "extends_rules_config.json" , "console.js" ] ;
1023
+ Tester :: new ( ) . with_cwd ( "fixtures/extends_config" . into ( ) ) . test_and_snapshot ( args) ;
1024
+ }
985
1025
}
0 commit comments