Skip to content

Commit

Permalink
Support for all-uppercase function wrapped in forwardRef/memo (#11) […
Browse files Browse the repository at this point in the history
…publish]
  • Loading branch information
ArnaudBarre committed May 2, 2023
1 parent 35cfa85 commit c0d156b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
@@ -1,8 +1,9 @@
# Changelog

## Unreleased
## 0.4.1

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

## 0.4.0

Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "eslint-plugin-react-refresh",
"version": "0.4.0",
"version": "0.4.1",
"license": "MIT",
"scripts": {
"build": "scripts/bundle.ts",
Expand Down
4 changes: 4 additions & 0 deletions src/only-export-components.test.ts
Expand Up @@ -41,6 +41,10 @@ const valid = [
name: "Direct export uppercase function",
code: "export function CMS() {};",
},
{
name: "Uppercase component with forwardRef",
code: "export const SVG = forwardRef(() => <svg/>);",
},
{
name: "Direct export uppercase component",
code: "export const CMS = () => {};",
Expand Down
13 changes: 12 additions & 1 deletion src/only-export-components.ts
Expand Up @@ -115,7 +115,7 @@ export const onlyExportComponents: TSESLint.RuleModule<
for (const variable of node.declarations) {
handleExportIdentifier(
variable.id,
variable.init?.type === "ArrowFunctionExpression",
canBeReactFunctionComponent(variable.init),
variable.init,
);
}
Expand Down Expand Up @@ -193,3 +193,14 @@ export const onlyExportComponents: TSESLint.RuleModule<
};
},
};

const canBeReactFunctionComponent = (init: TSESTree.Expression | null) => {
if (!init) return false;
if (init.type === "ArrowFunctionExpression") return true;
if (init.type === "CallExpression") {
if (init.callee.type === "Identifier") {
return ["memo", "forwardRef"].includes(init.callee.name);
}
}
return false;
};

0 comments on commit c0d156b

Please sign in to comment.