@@ -16,50 +16,28 @@ const compat = new FlatCompat({
1616} ) ;
1717
1818const legacyConfig = require ( './.eslintrc.js' ) ;
19- const recommendedTsRulesConfig = tsEslintPlugin . configs . recommended ;
20- const recommendedTsRulesObject = Array . isArray ( recommendedTsRulesConfig )
21- ? recommendedTsRulesConfig . reduce ( ( rules , config ) => ( { ...rules , ...( config . rules || { } ) } ) , { } )
22- : recommendedTsRulesConfig ?. rules || { } ;
23- const recommendedTsRules = new Set ( Object . keys ( recommendedTsRulesObject ) ) ;
2419
25- function hasCurrentTsRule ( ruleName ) {
26- const tsRuleName = ruleName . replace ( '@typescript-eslint/' , '' ) ;
27- return Boolean ( tsEslintPlugin . rules [ tsRuleName ] ) ;
28- }
29- const localTsRules = new Set (
30- Object . keys ( legacyConfig . rules || { } ) . filter (
31- ( ruleName ) => ruleName . startsWith ( '@typescript-eslint/' ) && hasCurrentTsRule ( ruleName ) ,
32- ) ,
33- ) ;
34-
35- const noopRule = {
36- meta : { type : 'problem' , docs : { } , schema : [ ] } ,
37- create : ( ) => ( { } ) ,
38- } ;
39-
40- function normalizeConfig ( config ) {
41- const next = { ...config } ;
42-
43- if ( next . plugins ?. [ '@typescript-eslint' ] ) {
44- next . plugins = { ...next . plugins } ;
45- delete next . plugins [ '@typescript-eslint' ] ;
20+ function supportRule ( ruleName ) {
21+ if ( ruleName . startsWith ( '@babel/' ) ) {
22+ return false ;
23+ }
24+ if ( ruleName . startsWith ( '@typescript-eslint/' ) ) {
25+ return Boolean ( tsEslintPlugin . rules [ ruleName . replace ( '@typescript-eslint/' , '' ) ] ) ;
4626 }
27+ return true ;
28+ }
4729
48- if ( next . rules ) {
49- next . rules = Object . fromEntries (
50- Object . entries ( next . rules ) . filter ( ( [ ruleName ] ) => {
51- if ( ruleName . startsWith ( '@babel/' ) ) {
52- return false ;
53- }
54- if ( ! ruleName . startsWith ( '@typescript-eslint/' ) ) {
55- return true ;
56- }
57- return recommendedTsRules . has ( ruleName ) || localTsRules . has ( ruleName ) ;
58- } ) ,
59- ) ;
30+ function dropUnsupportedRules ( config ) {
31+ if ( ! config . rules ) {
32+ return config ;
6033 }
6134
62- return next ;
35+ return {
36+ ...config ,
37+ rules : Object . fromEntries (
38+ Object . entries ( config . rules ) . filter ( ( [ ruleName ] ) => supportRule ( ruleName ) ) ,
39+ ) ,
40+ } ;
6341}
6442
6543export default [
@@ -78,18 +56,7 @@ export default [
7856 'src/index.d.ts' ,
7957 ] ,
8058 } ,
81- {
82- plugins : {
83- '@typescript-eslint' : {
84- ...tsEslintPlugin ,
85- rules : {
86- ...tsEslintPlugin . rules ,
87- 'consistent-type-exports' : noopRule ,
88- } ,
89- } ,
90- } ,
91- } ,
92- ...compat . config ( legacyConfig ) . map ( normalizeConfig ) ,
59+ ...compat . config ( legacyConfig ) . map ( dropUnsupportedRules ) ,
9360 {
9461 rules : {
9562 '@typescript-eslint/no-empty-object-type' : 'off' ,
0 commit comments