File tree Expand file tree Collapse file tree 3 files changed +25
-2
lines changed Expand file tree Collapse file tree 3 files changed +25
-2
lines changed Original file line number Diff line number Diff line change 1
1
# Changelog
2
2
3
+ ## Unreleased
4
+
5
+ - Support memo default export function components (fixes #27 )
6
+
3
7
## 0.4.3
4
8
5
9
- Add warning for TS enums exports
Original file line number Diff line number Diff line change @@ -81,6 +81,10 @@ const valid = [
81
81
name : "Direct export default AF" ,
82
82
code : "export default function foo () {};" ,
83
83
} ,
84
+ {
85
+ name : "export default memo function" ,
86
+ code : "export default memo(function Foo () {});" ,
87
+ } ,
84
88
{
85
89
name : "export type *" ,
86
90
code : "export type * from './module';" ,
@@ -146,6 +150,11 @@ const invalid = [
146
150
code : "export default () => {};" ,
147
151
errorId : "anonymousExport" ,
148
152
} ,
153
+ {
154
+ name : "export default anonymous memo AF" ,
155
+ code : "export default memo(() => {});" ,
156
+ errorId : "anonymousExport" ,
157
+ } ,
149
158
{
150
159
name : "Export default anonymous function" ,
151
160
code : "export default function () {};" ,
Original file line number Diff line number Diff line change @@ -126,7 +126,16 @@ export const onlyExportComponents: TSESLint.RuleModule<
126
126
handleExportIdentifier ( node . id , true ) ;
127
127
}
128
128
} else if ( node . type === "CallExpression" ) {
129
- context . report ( { messageId : "anonymousExport" , node } ) ;
129
+ if (
130
+ node . callee . type === "Identifier" &&
131
+ reactHOCs . includes ( node . callee . name ) &&
132
+ node . arguments [ 0 ] ?. type === "FunctionExpression" &&
133
+ node . arguments [ 0 ] . id
134
+ ) {
135
+ handleExportIdentifier ( node . arguments [ 0 ] . id , true ) ;
136
+ } else {
137
+ context . report ( { messageId : "anonymousExport" , node } ) ;
138
+ }
130
139
} else if ( node . type === "TSEnumDeclaration" ) {
131
140
nonComponentExports . push ( node . id ) ;
132
141
}
@@ -196,12 +205,13 @@ export const onlyExportComponents: TSESLint.RuleModule<
196
205
} ,
197
206
} ;
198
207
208
+ const reactHOCs = [ "memo" , "forwardRef" ] ;
199
209
const canBeReactFunctionComponent = ( init : TSESTree . Expression | null ) => {
200
210
if ( ! init ) return false ;
201
211
if ( init . type === "ArrowFunctionExpression" ) return true ;
202
212
if ( init . type === "CallExpression" ) {
203
213
if ( init . callee . type === "Identifier" ) {
204
- return [ "memo" , "forwardRef" ] . includes ( init . callee . name ) ;
214
+ return reactHOCs . includes ( init . callee . name ) ;
205
215
}
206
216
}
207
217
return false ;
You can’t perform that action at this time.
0 commit comments