@@ -21,6 +21,7 @@ export const onlyExportComponents: TSESLint.RuleModule<
21
21
allowConstantExport ?: boolean ;
22
22
checkJS ?: boolean ;
23
23
allowExportNames ?: string [ ] ;
24
+ customHOCs ?: string [ ] ;
24
25
} ,
25
26
]
26
27
> = {
@@ -47,6 +48,7 @@ export const onlyExportComponents: TSESLint.RuleModule<
47
48
allowConstantExport : { type : "boolean" } ,
48
49
checkJS : { type : "boolean" } ,
49
50
allowExportNames : { type : "array" , items : { type : "string" } } ,
51
+ customHOCs : { type : "array" , items : { type : "string" } } ,
50
52
} ,
51
53
additionalProperties : false ,
52
54
} ,
@@ -58,6 +60,7 @@ export const onlyExportComponents: TSESLint.RuleModule<
58
60
allowConstantExport = false ,
59
61
checkJS = false ,
60
62
allowExportNames,
63
+ customHOCs = [ ] ,
61
64
} = context . options [ 0 ] ?? { } ;
62
65
const filename = context . filename ;
63
66
// Skip tests & stories files
@@ -79,6 +82,16 @@ export const onlyExportComponents: TSESLint.RuleModule<
79
82
? new Set ( allowExportNames )
80
83
: undefined ;
81
84
85
+ const reactHOCs = new Set ( [ "memo" , "forwardRef" , ...customHOCs ] ) ;
86
+ const canBeReactFunctionComponent = ( init : TSESTree . Expression | null ) => {
87
+ if ( ! init ) return false ;
88
+ if ( init . type === "ArrowFunctionExpression" ) return true ;
89
+ if ( init . type === "CallExpression" && init . callee . type === "Identifier" ) {
90
+ return reactHOCs . has ( init . callee . name ) ;
91
+ }
92
+ return false ;
93
+ } ;
94
+
82
95
return {
83
96
Program ( program ) {
84
97
let hasExports = false ;
@@ -298,16 +311,6 @@ export const onlyExportComponents: TSESLint.RuleModule<
298
311
} ,
299
312
} ;
300
313
301
- const reactHOCs = new Set ( [ "memo" , "forwardRef" ] ) ;
302
- const canBeReactFunctionComponent = ( init : TSESTree . Expression | null ) => {
303
- if ( ! init ) return false ;
304
- if ( init . type === "ArrowFunctionExpression" ) return true ;
305
- if ( init . type === "CallExpression" && init . callee . type === "Identifier" ) {
306
- return reactHOCs . has ( init . callee . name ) ;
307
- }
308
- return false ;
309
- } ;
310
-
311
314
type ToString < T > = T extends `${infer V } ` ? V : never ;
312
315
const notReactComponentExpression = new Set <
313
316
ToString < TSESTree . Expression [ "type" ] >
0 commit comments