@@ -39,7 +39,7 @@ pub use crate::{
3939 external_linter:: {
4040 ExternalLinter , ExternalLinterCb , ExternalLinterLoadPluginCb , LintResult , PluginLoadResult ,
4141 } ,
42- external_plugin_store:: ExternalPluginStore ,
42+ external_plugin_store:: { ExternalPluginStore , ExternalRuleId } ,
4343 fixer:: FixKind ,
4444 frameworks:: FrameworkFlags ,
4545 loader:: LINTABLE_EXTENSIONS ,
@@ -203,44 +203,7 @@ impl Linter {
203203 }
204204
205205 if !external_rules. is_empty ( ) {
206- if let Some ( external_linter) = self . external_linter . as_ref ( ) {
207- let result = ( external_linter. run ) (
208- #[ expect( clippy:: missing_panics_doc) ]
209- path. to_str ( ) . unwrap ( ) . to_string ( ) ,
210- external_rules. iter ( ) . map ( |( rule_id, _) | rule_id. raw ( ) ) . collect ( ) ,
211- ) ;
212- match result {
213- Ok ( diagnostics) => {
214- for diagnostic in diagnostics {
215- match self . config . resolve_plugin_rule_names ( diagnostic. external_rule_id )
216- {
217- Some ( ( plugin_name, rule_name) ) => {
218- ctx_host. push_diagnostic ( Message :: new (
219- // TODO: `error` isn't right, we need to get the severity from `external_rules`
220- OxcDiagnostic :: error ( diagnostic. message )
221- . with_label ( Span :: new (
222- diagnostic. loc . start ,
223- diagnostic. loc . end ,
224- ) )
225- . with_error_code (
226- plugin_name. to_string ( ) ,
227- rule_name. to_string ( ) ,
228- ) ,
229- PossibleFixes :: None ,
230- ) ) ;
231- }
232- None => {
233- // TODO: report diagnostic, this should be unreachable
234- debug_assert ! ( false ) ;
235- }
236- }
237- }
238- }
239- Err ( _err) => {
240- // TODO: report diagnostic
241- }
242- }
243- }
206+ self . run_external_rules ( & external_rules, path, & ctx_host) ;
244207 }
245208
246209 if let Some ( severity) = self . options . report_unused_directive {
@@ -251,6 +214,60 @@ impl Linter {
251214
252215 ctx_host. take_diagnostics ( )
253216 }
217+
218+ #[ cfg( not( all( feature = "oxlint2" , not( feature = "disable_oxlint2" ) ) ) ) ]
219+ #[ expect( unused_variables, clippy:: unused_self) ]
220+ fn run_external_rules (
221+ & self ,
222+ external_rules : & [ ( ExternalRuleId , AllowWarnDeny ) ] ,
223+ path : & Path ,
224+ ctx_host : & ContextHost ,
225+ ) {
226+ unreachable ! ( ) ;
227+ }
228+
229+ #[ cfg( all( feature = "oxlint2" , not( feature = "disable_oxlint2" ) ) ) ]
230+ fn run_external_rules (
231+ & self ,
232+ external_rules : & [ ( ExternalRuleId , AllowWarnDeny ) ] ,
233+ path : & Path ,
234+ ctx_host : & ContextHost ,
235+ ) {
236+ // TODO: Error or `unwrap` instead of `return`?
237+ let Some ( external_linter) = & self . external_linter else { return } ;
238+
239+ let result = ( external_linter. run ) (
240+ path. to_str ( ) . unwrap ( ) . to_string ( ) ,
241+ external_rules. iter ( ) . map ( |( rule_id, _) | rule_id. raw ( ) ) . collect ( ) ,
242+ ) ;
243+ match result {
244+ Ok ( diagnostics) => {
245+ for diagnostic in diagnostics {
246+ match self . config . resolve_plugin_rule_names ( diagnostic. external_rule_id ) {
247+ Some ( ( plugin_name, rule_name) ) => {
248+ ctx_host. push_diagnostic ( Message :: new (
249+ // TODO: `error` isn't right, we need to get the severity from `external_rules`
250+ OxcDiagnostic :: error ( diagnostic. message )
251+ . with_label ( Span :: new ( diagnostic. loc . start , diagnostic. loc . end ) )
252+ . with_error_code (
253+ plugin_name. to_string ( ) ,
254+ rule_name. to_string ( ) ,
255+ ) ,
256+ PossibleFixes :: None ,
257+ ) ) ;
258+ }
259+ None => {
260+ // TODO: report diagnostic, this should be unreachable
261+ debug_assert ! ( false ) ;
262+ }
263+ }
264+ }
265+ }
266+ Err ( _err) => {
267+ // TODO: report diagnostic
268+ }
269+ }
270+ }
254271}
255272
256273#[ cfg( test) ]
0 commit comments