Skip to content

Commit c0d156b

Browse files
committed
Support for all-uppercase function wrapped in forwardRef/memo (#11) [publish]
1 parent 35cfa85 commit c0d156b

File tree

4 files changed

+19
-3
lines changed

4 files changed

+19
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# Changelog
22

3-
## Unreleased
3+
## 0.4.1
44

55
- Ignore `export type *` (fixes #12)
6+
- Support for all-uppercase function wrapped in forwardRef/memo (#11)
67

78
## 0.4.0
89

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "eslint-plugin-react-refresh",
3-
"version": "0.4.0",
3+
"version": "0.4.1",
44
"license": "MIT",
55
"scripts": {
66
"build": "scripts/bundle.ts",

src/only-export-components.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ const valid = [
4141
name: "Direct export uppercase function",
4242
code: "export function CMS() {};",
4343
},
44+
{
45+
name: "Uppercase component with forwardRef",
46+
code: "export const SVG = forwardRef(() => <svg/>);",
47+
},
4448
{
4549
name: "Direct export uppercase component",
4650
code: "export const CMS = () => {};",

src/only-export-components.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ export const onlyExportComponents: TSESLint.RuleModule<
115115
for (const variable of node.declarations) {
116116
handleExportIdentifier(
117117
variable.id,
118-
variable.init?.type === "ArrowFunctionExpression",
118+
canBeReactFunctionComponent(variable.init),
119119
variable.init,
120120
);
121121
}
@@ -193,3 +193,14 @@ export const onlyExportComponents: TSESLint.RuleModule<
193193
};
194194
},
195195
};
196+
197+
const canBeReactFunctionComponent = (init: TSESTree.Expression | null) => {
198+
if (!init) return false;
199+
if (init.type === "ArrowFunctionExpression") return true;
200+
if (init.type === "CallExpression") {
201+
if (init.callee.type === "Identifier") {
202+
return ["memo", "forwardRef"].includes(init.callee.name);
203+
}
204+
}
205+
return false;
206+
};

0 commit comments

Comments
 (0)