@@ -10,7 +10,9 @@ use oxc_span::{CompactStr, format_compact_str};
1010
1111use crate :: {
1212 AllowWarnDeny , LintConfig , LintFilter , LintFilterKind , Oxlintrc , RuleCategory , RuleEnum ,
13- config:: { ESLintRule , LintPlugins , OxlintOverrides , OxlintRules , overrides:: OxlintOverride } ,
13+ config:: {
14+ BuiltinLintPlugins , ESLintRule , OxlintOverrides , OxlintRules , overrides:: OxlintOverride ,
15+ } ,
1416 external_linter:: ExternalLinter ,
1517 rules:: RULES ,
1618} ;
@@ -31,7 +33,7 @@ pub struct ConfigStoreBuilder {
3133
3234impl Default for ConfigStoreBuilder {
3335 fn default ( ) -> Self {
34- Self { rules : Self :: warn_correctness ( LintPlugins :: default ( ) ) , ..Self :: empty ( ) }
36+ Self { rules : Self :: warn_correctness ( BuiltinLintPlugins :: default ( ) ) , ..Self :: empty ( ) }
3537 }
3638}
3739
@@ -55,7 +57,7 @@ impl ConfigStoreBuilder {
5557 ///
5658 /// You can think of this as `oxlint -W all -W nursery`.
5759 pub fn all ( ) -> Self {
58- let config = LintConfig { plugins : LintPlugins :: all ( ) , ..LintConfig :: default ( ) } ;
60+ let config = LintConfig { plugins : BuiltinLintPlugins :: all ( ) , ..LintConfig :: default ( ) } ;
5961 let overrides = OxlintOverrides :: default ( ) ;
6062 let categories: OxlintCategories = OxlintCategories :: default ( ) ;
6163 let rules = RULES . iter ( ) . map ( |rule| ( rule. clone ( ) , AllowWarnDeny :: Warn ) ) . collect ( ) ;
@@ -183,7 +185,7 @@ impl ConfigStoreBuilder {
183185 /// [`with_filters`]: ConfigStoreBuilder::with_filters
184186 /// [`and_plugins`]: ConfigStoreBuilder::and_plugins
185187 #[ inline]
186- pub fn with_plugins ( mut self , plugins : LintPlugins ) -> Self {
188+ pub fn with_plugins ( mut self , plugins : BuiltinLintPlugins ) -> Self {
187189 self . config . plugins = plugins;
188190 self
189191 }
@@ -198,13 +200,13 @@ impl ConfigStoreBuilder {
198200 /// See [`ConfigStoreBuilder::with_plugins`] for details on how plugin configuration affects your
199201 /// rules.
200202 #[ inline]
201- pub fn and_plugins ( mut self , plugins : LintPlugins , enabled : bool ) -> Self {
203+ pub fn and_plugins ( mut self , plugins : BuiltinLintPlugins , enabled : bool ) -> Self {
202204 self . config . plugins . set ( plugins, enabled) ;
203205 self
204206 }
205207
206208 #[ inline]
207- pub fn plugins ( & self ) -> LintPlugins {
209+ pub fn plugins ( & self ) -> BuiltinLintPlugins {
208210 self . config . plugins
209211 }
210212
@@ -268,13 +270,13 @@ impl ConfigStoreBuilder {
268270 let mut plugins = self . config . plugins ;
269271
270272 // we need to include some jest rules when vitest is enabled, see [`VITEST_COMPATIBLE_JEST_RULES`]
271- if plugins. contains ( LintPlugins :: VITEST ) {
272- plugins = plugins. union ( LintPlugins :: JEST ) ;
273+ if plugins. contains ( BuiltinLintPlugins :: VITEST ) {
274+ plugins = plugins. union ( BuiltinLintPlugins :: JEST ) ;
273275 }
274276
275277 RULES
276278 . iter ( )
277- . filter ( |rule| plugins. contains ( LintPlugins :: from ( rule. plugin_name ( ) ) ) )
279+ . filter ( |rule| plugins. contains ( BuiltinLintPlugins :: from ( rule. plugin_name ( ) ) ) )
278280 . cloned ( )
279281 . collect ( )
280282 }
@@ -306,8 +308,8 @@ impl ConfigStoreBuilder {
306308 let mut plugins = self . plugins ( ) ;
307309
308310 // Apply the same Vitest->Jest logic as in get_all_rules()
309- if plugins. contains ( LintPlugins :: VITEST ) {
310- plugins = plugins. union ( LintPlugins :: JEST ) ;
311+ if plugins. contains ( BuiltinLintPlugins :: VITEST ) {
312+ plugins = plugins. union ( BuiltinLintPlugins :: JEST ) ;
311313 }
312314
313315 let mut rules: Vec < _ > = self
@@ -320,14 +322,14 @@ impl ConfigStoreBuilder {
320322 }
321323
322324 /// Warn for all correctness rules in the given set of plugins.
323- fn warn_correctness ( plugins : LintPlugins ) -> FxHashMap < RuleEnum , AllowWarnDeny > {
325+ fn warn_correctness ( plugins : BuiltinLintPlugins ) -> FxHashMap < RuleEnum , AllowWarnDeny > {
324326 RULES
325327 . iter ( )
326328 . filter ( |rule| {
327329 // NOTE: this logic means there's no way to disable ESLint
328330 // correctness rules. I think that's fine for now.
329331 rule. category ( ) == RuleCategory :: Correctness
330- && plugins. contains ( LintPlugins :: from ( rule. plugin_name ( ) ) )
332+ && plugins. contains ( BuiltinLintPlugins :: from ( rule. plugin_name ( ) ) )
331333 } )
332334 . map ( |rule| ( rule. clone ( ) , AllowWarnDeny :: Warn ) )
333335 . collect ( )
@@ -431,7 +433,7 @@ mod test {
431433 #[ test]
432434 fn test_builder_default ( ) {
433435 let builder = ConfigStoreBuilder :: default ( ) ;
434- assert_eq ! ( builder. plugins( ) , LintPlugins :: default ( ) ) ;
436+ assert_eq ! ( builder. plugins( ) , BuiltinLintPlugins :: default ( ) ) ;
435437
436438 // populated with all correctness-level ESLint rules at a "warn" severity
437439 assert ! ( !builder. rules. is_empty( ) ) ;
@@ -450,7 +452,7 @@ mod test {
450452 #[ test]
451453 fn test_builder_empty ( ) {
452454 let builder = ConfigStoreBuilder :: empty ( ) ;
453- assert_eq ! ( builder. plugins( ) , LintPlugins :: default ( ) ) ;
455+ assert_eq ! ( builder. plugins( ) , BuiltinLintPlugins :: default ( ) ) ;
454456 assert ! ( builder. rules. is_empty( ) ) ;
455457 }
456458
@@ -555,7 +557,7 @@ mod test {
555557 let builder = ConfigStoreBuilder :: default ( ) ;
556558 let initial_rule_count = builder. rules . len ( ) ;
557559
558- let builder = builder. and_plugins ( LintPlugins :: IMPORT , true ) ;
560+ let builder = builder. and_plugins ( BuiltinLintPlugins :: IMPORT , true ) ;
559561 assert_eq ! (
560562 initial_rule_count,
561563 builder. rules. len( ) ,
@@ -566,18 +568,18 @@ mod test {
566568 #[ test]
567569 fn test_rules_after_plugin_removal ( ) {
568570 // sanity check: the plugin we're removing is, in fact, enabled by default.
569- assert ! ( LintPlugins :: default ( ) . contains( LintPlugins :: TYPESCRIPT ) ) ;
571+ assert ! ( BuiltinLintPlugins :: default ( ) . contains( BuiltinLintPlugins :: TYPESCRIPT ) ) ;
570572
571- let mut desired_plugins = LintPlugins :: default ( ) ;
572- desired_plugins. set ( LintPlugins :: TYPESCRIPT , false ) ;
573+ let mut desired_plugins = BuiltinLintPlugins :: default ( ) ;
574+ desired_plugins. set ( BuiltinLintPlugins :: TYPESCRIPT , false ) ;
573575
574576 let linter = ConfigStoreBuilder :: default ( ) . with_plugins ( desired_plugins) . build ( ) ;
575577 for ( rule, _) in linter. base . rules . iter ( ) {
576578 let name = rule. name ( ) ;
577579 let plugin = rule. plugin_name ( ) ;
578580 assert_ne ! (
579- LintPlugins :: from( plugin) ,
580- LintPlugins :: TYPESCRIPT ,
581+ BuiltinLintPlugins :: from( plugin) ,
582+ BuiltinLintPlugins :: TYPESCRIPT ,
581583 "{plugin}/{name} is in the rules list after typescript plugin has been disabled"
582584 ) ;
583585 }
@@ -593,35 +595,39 @@ mod test {
593595 // ==========================================================================================
594596
595597 // Enable eslint plugin. Since it's already enabled, this does nothing.
596- assert ! ( initial_plugins. contains( LintPlugins :: ESLINT ) ) ; // sanity check that eslint is
598+ assert ! ( initial_plugins. contains( BuiltinLintPlugins :: ESLINT ) ) ; // sanity check that eslint is
597599 // enabled
598- let builder = builder. and_plugins ( LintPlugins :: ESLINT , true ) ;
600+ let builder = builder. and_plugins ( BuiltinLintPlugins :: ESLINT , true ) ;
599601 assert_eq ! ( initial_plugins, builder. plugins( ) ) ;
600602
601603 // Disable import plugin. Since it's not already enabled, this is also a no-op.
602- assert ! ( !builder. plugins( ) . contains( LintPlugins :: IMPORT ) ) ; // sanity check that it's not
604+ assert ! ( !builder. plugins( ) . contains( BuiltinLintPlugins :: IMPORT ) ) ; // sanity check that it's not
603605 // already enabled
604- let builder = builder. and_plugins ( LintPlugins :: IMPORT , false ) ;
606+ let builder = builder. and_plugins ( BuiltinLintPlugins :: IMPORT , false ) ;
605607 assert_eq ! ( initial_plugins, builder. plugins( ) ) ;
606608
607609 // Enable import plugin. Since it's not already enabled, this turns it on.
608- let builder = builder. and_plugins ( LintPlugins :: IMPORT , true ) ;
609- assert_eq ! ( LintPlugins :: default ( ) . union ( LintPlugins :: IMPORT ) , builder. plugins( ) ) ;
610+ let builder = builder. and_plugins ( BuiltinLintPlugins :: IMPORT , true ) ;
611+ assert_eq ! (
612+ BuiltinLintPlugins :: default ( ) . union ( BuiltinLintPlugins :: IMPORT ) ,
613+ builder. plugins( )
614+ ) ;
610615 assert_ne ! ( initial_plugins, builder. plugins( ) ) ;
611616
612617 // Turn import back off, resetting plugins to the initial state
613- let builder = builder. and_plugins ( LintPlugins :: IMPORT , false ) ;
618+ let builder = builder. and_plugins ( BuiltinLintPlugins :: IMPORT , false ) ;
614619 assert_eq ! ( initial_plugins, builder. plugins( ) ) ;
615620
616621 // ==========================================================================================
617622 // Test ConfigStoreBuilder::with_plugins, which _does_ override plugins
618623 // ==========================================================================================
619624
620- let builder = builder. with_plugins ( LintPlugins :: ESLINT ) ;
621- assert_eq ! ( LintPlugins :: ESLINT , builder. plugins( ) ) ;
625+ let builder = builder. with_plugins ( BuiltinLintPlugins :: ESLINT ) ;
626+ assert_eq ! ( BuiltinLintPlugins :: ESLINT , builder. plugins( ) ) ;
622627
623- let expected_plugins =
624- LintPlugins :: ESLINT . union ( LintPlugins :: TYPESCRIPT ) . union ( LintPlugins :: NEXTJS ) ;
628+ let expected_plugins = BuiltinLintPlugins :: ESLINT
629+ . union ( BuiltinLintPlugins :: TYPESCRIPT )
630+ . union ( BuiltinLintPlugins :: NEXTJS ) ;
625631 let builder = builder. with_plugins ( expected_plugins) ;
626632 assert_eq ! ( expected_plugins, builder. plugins( ) ) ;
627633 }
@@ -838,7 +844,7 @@ mod test {
838844 "# ,
839845 ) ;
840846 // Check that default plugins are correctly set
841- assert_eq ! ( default_config. plugins( ) , LintPlugins :: default ( ) ) ;
847+ assert_eq ! ( default_config. plugins( ) , BuiltinLintPlugins :: default ( ) ) ;
842848
843849 // Test 2: Parent config with explicitly specified plugins
844850 let parent_config = config_store_from_str (
@@ -848,21 +854,27 @@ mod test {
848854 }
849855 "# ,
850856 ) ;
851- assert_eq ! ( parent_config. plugins( ) , LintPlugins :: REACT | LintPlugins :: TYPESCRIPT ) ;
857+ assert_eq ! (
858+ parent_config. plugins( ) ,
859+ BuiltinLintPlugins :: REACT | BuiltinLintPlugins :: TYPESCRIPT
860+ ) ;
852861
853862 // Test 3: Child config that extends parent without specifying plugins
854863 // Should inherit parent's plugins
855864 let child_no_plugins_config =
856865 config_store_from_path ( "fixtures/extends_config/plugins/child_no_plugins.json" ) ;
857- assert_eq ! ( child_no_plugins_config. plugins( ) , LintPlugins :: REACT | LintPlugins :: TYPESCRIPT ) ;
866+ assert_eq ! (
867+ child_no_plugins_config. plugins( ) ,
868+ BuiltinLintPlugins :: REACT | BuiltinLintPlugins :: TYPESCRIPT
869+ ) ;
858870
859871 // Test 4: Child config that extends parent and specifies additional plugins
860872 // Should have parent's plugins plus its own
861873 let child_with_plugins_config =
862874 config_store_from_path ( "fixtures/extends_config/plugins/child_with_plugins.json" ) ;
863875 assert_eq ! (
864876 child_with_plugins_config. plugins( ) ,
865- LintPlugins :: REACT | LintPlugins :: TYPESCRIPT | LintPlugins :: JEST
877+ BuiltinLintPlugins :: REACT | BuiltinLintPlugins :: TYPESCRIPT | BuiltinLintPlugins :: JEST
866878 ) ;
867879
868880 // Test 5: Empty plugins array should result in empty plugins
@@ -873,7 +885,7 @@ mod test {
873885 }
874886 "# ,
875887 ) ;
876- assert_eq ! ( empty_plugins_config. plugins( ) , LintPlugins :: empty( ) ) ;
888+ assert_eq ! ( empty_plugins_config. plugins( ) , BuiltinLintPlugins :: empty( ) ) ;
877889
878890 // Test 6: Extending multiple config files with plugins
879891 let config = config_store_from_str (
@@ -886,8 +898,8 @@ mod test {
886898 }
887899 "# ,
888900 ) ;
889- assert ! ( config. plugins( ) . contains( LintPlugins :: JEST ) ) ;
890- assert ! ( config. plugins( ) . contains( LintPlugins :: REACT ) ) ;
901+ assert ! ( config. plugins( ) . contains( BuiltinLintPlugins :: JEST ) ) ;
902+ assert ! ( config. plugins( ) . contains( BuiltinLintPlugins :: REACT ) ) ;
891903
892904 // Test 7: Adding more plugins to extended configs
893905 let config = config_store_from_str (
@@ -903,7 +915,7 @@ mod test {
903915 ) ;
904916 assert_eq ! (
905917 config. plugins( ) ,
906- LintPlugins :: JEST | LintPlugins :: REACT | LintPlugins :: TYPESCRIPT
918+ BuiltinLintPlugins :: JEST | BuiltinLintPlugins :: REACT | BuiltinLintPlugins :: TYPESCRIPT
907919 ) ;
908920
909921 // Test 8: Extending a config with a plugin is the same as adding it directly
@@ -941,7 +953,7 @@ mod test {
941953 }
942954 "# ,
943955 ) ;
944- assert_eq ! ( config. plugins( ) , LintPlugins :: default ( ) ) ;
956+ assert_eq ! ( config. plugins( ) , BuiltinLintPlugins :: default ( ) ) ;
945957 assert ! ( config. rules( ) . is_empty( ) ) ;
946958 }
947959
0 commit comments