@@ -130,9 +130,11 @@ impl ConfigStoreBuilder {
130
130
. rules
131
131
. override_rules ( & mut builder. rules , & builder. cache . borrow ( ) ) ;
132
132
// Use `ConfigStoreBuilder` to load extended config files and then apply rules from those
133
- let extended_config_store =
133
+ let mut extended_config_store =
134
134
ConfigStoreBuilder :: from_oxlintrc ( true , extended_config) ?;
135
- builder = builder. with_rules ( extended_config_store. rules ) ;
135
+ let rules = std:: mem:: take ( & mut extended_config_store. rules ) ;
136
+ builder = builder. with_rules ( rules) ;
137
+ builder = builder. and_plugins ( extended_config_store. plugins ( ) , true ) ;
136
138
}
137
139
Err ( err) => {
138
140
return Err ( ConfigBuilderError :: InvalidConfigFile {
@@ -878,6 +880,59 @@ mod test {
878
880
}
879
881
}
880
882
883
+ #[ test]
884
+ fn test_extends_plugins ( ) {
885
+ let config = config_store_from_str (
886
+ r#"
887
+ {
888
+ "extends": [
889
+ "../../apps/oxlint/fixtures/extends_config/plugins/jest.json",
890
+ "../../apps/oxlint/fixtures/extends_config/plugins/react.json"
891
+ ]
892
+ }
893
+ "# ,
894
+ ) ;
895
+ assert ! ( config. plugins( ) . contains( LintPlugins :: default ( ) ) ) ;
896
+ assert ! ( config. plugins( ) . contains( LintPlugins :: JEST ) ) ;
897
+ assert ! ( config. plugins( ) . contains( LintPlugins :: REACT ) ) ;
898
+
899
+ // Test adding more plugins
900
+ let config = config_store_from_str (
901
+ r#"
902
+ {
903
+ "extends": [
904
+ "../../apps/oxlint/fixtures/extends_config/plugins/jest.json",
905
+ "../../apps/oxlint/fixtures/extends_config/plugins/react.json"
906
+ ],
907
+ "plugins": ["typescript"]
908
+ }
909
+ "# ,
910
+ ) ;
911
+ assert_eq ! (
912
+ config. plugins( ) ,
913
+ LintPlugins :: JEST | LintPlugins :: REACT | LintPlugins :: TYPESCRIPT
914
+ ) ;
915
+
916
+ // Test that extended a config with a plugin is the same as adding it directly
917
+ let plugin_config = config_store_from_str ( r#"{ "plugins": ["jest", "react"] }"# ) ;
918
+ let extends_plugin_config = config_store_from_str (
919
+ r#"
920
+ {
921
+ "extends": [
922
+ "../../apps/oxlint/fixtures/extends_config/plugins/jest.json",
923
+ "../../apps/oxlint/fixtures/extends_config/plugins/react.json"
924
+ ],
925
+ "plugins": []
926
+ }
927
+ "# ,
928
+ ) ;
929
+ assert_eq ! (
930
+ plugin_config. plugins( ) ,
931
+ extends_plugin_config. plugins( ) ,
932
+ "Extending a config with a plugin is the same as adding it directly"
933
+ ) ;
934
+ }
935
+
881
936
fn config_store_from_path ( path : & str ) -> ConfigStore {
882
937
ConfigStoreBuilder :: from_oxlintrc ( true , Oxlintrc :: from_file ( & PathBuf :: from ( path) ) . unwrap ( ) )
883
938
. unwrap ( )
0 commit comments