@@ -13,8 +13,8 @@ use ignore::{gitignore::Gitignore, overrides::OverrideBuilder};
1313use oxc_allocator:: AllocatorPool ;
1414use oxc_diagnostics:: { DiagnosticService , GraphicalReportHandler , OxcDiagnostic } ;
1515use oxc_linter:: {
16- AllowWarnDeny , Config , ConfigStore , ConfigStoreBuilder , InvalidFilterKind , LintFilter ,
17- LintOptions , LintService , LintServiceOptions , Linter , Oxlintrc ,
16+ AllowWarnDeny , Config , ConfigBuilderError , ConfigStore , ConfigStoreBuilder , ExternalLinter ,
17+ InvalidFilterKind , LintFilter , LintOptions , LintService , LintServiceOptions , Linter , Oxlintrc ,
1818} ;
1919use rustc_hash:: { FxHashMap , FxHashSet } ;
2020use serde_json:: Value ;
@@ -29,16 +29,22 @@ use crate::{
2929pub struct LintRunner {
3030 options : LintCommand ,
3131 cwd : PathBuf ,
32+ external_linter : Option < ExternalLinter > ,
3233}
3334
3435impl Runner for LintRunner {
3536 type Options = LintCommand ;
3637
37- fn new ( options : Self :: Options ) -> Self {
38- Self { options, cwd : env:: current_dir ( ) . expect ( "Failed to get current working directory" ) }
38+ fn new ( options : Self :: Options , external_linter : Option < ExternalLinter > ) -> Self {
39+ Self {
40+ options,
41+ cwd : env:: current_dir ( ) . expect ( "Failed to get current working directory" ) ,
42+ external_linter,
43+ }
3944 }
4045
4146 fn run ( self , stdout : & mut dyn Write ) -> CliRunResult {
47+ println ! ( "LintRunner::run" ) ;
4248 let format_str = self . options . output_options . format ;
4349 let output_formatter = OutputFormatter :: new ( format_str) ;
4450
@@ -59,10 +65,12 @@ impl Runner for LintRunner {
5965 enable_plugins,
6066 misc_options,
6167 disable_nested_config,
62- inline_config_options,
68+ ref inline_config_options,
6369 ..
6470 } = self . options ;
6571
72+ let external_linter = self . external_linter . as_ref ( ) ;
73+
6674 let search_for_nested_configs = !disable_nested_config &&
6775 // If the `--config` option is explicitly passed, we should not search for nested config files
6876 // as the passed config file takes absolute precedence.
@@ -173,7 +181,7 @@ impl Runner for LintRunner {
173181 let handler = GraphicalReportHandler :: new ( ) ;
174182
175183 let nested_configs = if search_for_nested_configs {
176- match Self :: get_nested_configs ( stdout, & handler, & filters, & paths) {
184+ match Self :: get_nested_configs ( stdout, & handler, & filters, & paths, external_linter ) {
177185 Ok ( v) => v,
178186 Err ( v) => return v,
179187 }
@@ -192,20 +200,22 @@ impl Runner for LintRunner {
192200 } else {
193201 None
194202 } ;
195- let config_builder = match ConfigStoreBuilder :: from_oxlintrc ( false , oxlintrc) {
196- Ok ( builder) => builder,
197- Err ( e) => {
198- print_and_flush_stdout (
199- stdout,
200- & format ! (
201- "Failed to parse configuration file.\n {}\n " ,
202- render_report( & handler, & OxcDiagnostic :: error( e. to_string( ) ) )
203- ) ,
204- ) ;
205- return CliRunResult :: InvalidOptionConfig ;
203+ let config_builder =
204+ match ConfigStoreBuilder :: from_oxlintrc ( false , oxlintrc, self . external_linter . as_ref ( ) )
205+ {
206+ Ok ( builder) => builder,
207+ Err ( e) => {
208+ print_and_flush_stdout (
209+ stdout,
210+ & format ! (
211+ "Failed to parse configuration file.\n {}\n " ,
212+ render_report( & handler, & OxcDiagnostic :: error( e. to_string( ) ) )
213+ ) ,
214+ ) ;
215+ return CliRunResult :: InvalidOptionConfig ;
216+ }
206217 }
207- }
208- . with_filters ( & filters) ;
218+ . with_filters ( & filters) ;
209219
210220 if let Some ( basic_config_file) = oxlintrc_for_print {
211221 let config_file = config_builder. resolve_final_config_file ( basic_config_file) ;
@@ -387,7 +397,9 @@ impl LintRunner {
387397 handler : & GraphicalReportHandler ,
388398 filters : & Vec < LintFilter > ,
389399 paths : & Vec < Arc < OsStr > > ,
400+ external_linter : Option < & ExternalLinter > ,
390401 ) -> Result < FxHashMap < PathBuf , Config > , CliRunResult > {
402+ println ! ( "LintRunner::get_nested_configs" ) ;
391403 // TODO(perf): benchmark whether or not it is worth it to store the configurations on a
392404 // per-file or per-directory basis, to avoid calling `.parent()` on every path.
393405 let mut nested_oxlintrc = FxHashMap :: < & Path , Oxlintrc > :: default ( ) ;
@@ -417,14 +429,20 @@ impl LintRunner {
417429 // iterate over each config and build the ConfigStore
418430 for ( dir, oxlintrc) in nested_oxlintrc {
419431 // TODO(refactor): clean up all of the error handling in this function
420- let builder = match ConfigStoreBuilder :: from_oxlintrc ( false , oxlintrc) {
432+ let builder = match ConfigStoreBuilder :: from_oxlintrc ( false , oxlintrc, external_linter)
433+ {
421434 Ok ( builder) => builder,
422435 Err ( e) => {
436+ let err = if let ConfigBuilderError :: OxcDiagnostic ( e) = e {
437+ e
438+ } else {
439+ OxcDiagnostic :: error ( e. to_string ( ) )
440+ } ;
423441 print_and_flush_stdout (
424442 stdout,
425443 & format ! (
426444 "Failed to parse configuration file.\n {}\n " ,
427- render_report( handler, & OxcDiagnostic :: error ( e . to_string ( ) ) )
445+ render_report( handler, & err )
428446 ) ,
429447 ) ;
430448
@@ -538,6 +556,7 @@ fn check_for_writer_error(error: std::io::Error) -> Result<(), std::io::Error> {
538556}
539557
540558fn render_report ( handler : & GraphicalReportHandler , diagnostic : & OxcDiagnostic ) -> String {
559+ dbg ! ( diagnostic) ;
541560 let mut err = String :: new ( ) ;
542561 handler. render_report ( & mut err, diagnostic) . unwrap ( ) ;
543562 err
0 commit comments