Skip to content

Commit

Permalink
Supports React.forwardRef and React.memo [publish] (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
SukkaW authored Aug 20, 2024
1 parent 897a11d commit 7101b09
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 8 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: CI
on:
pull_request:
branches:
- main
jobs:
ci:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v2
- run: bun install
- run: bun ci
4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ jobs:
runs-on: ubuntu-latest
if: ${{ contains(github.event.head_commit.message, '[publish]') }}
steps:
- uses: actions/checkout@v3
- uses: oven-sh/setup-bun@v1
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v2
- run: bun install
- run: bun ci
- uses: ArnaudBarre/npm-publish@v1
Expand Down
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# Changelog

## 0.4.10

- Support `function Foo() {}; export default React.memo(Foo)` (#46) (thanks @SukkaW!)

## 0.4.9

- Support `function Foo() {}; export default memo(Foo)` (fixes #44)
- Support `function Foo() {}; export default memo(Foo)` (fixes #44) (thanks @SukkaW!)

## 0.4.8

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eslint-plugin-react-refresh",
"version": "0.4.9",
"version": "0.4.10",
"type": "module",
"license": "MIT",
"scripts": {
Expand Down
12 changes: 12 additions & 0 deletions src/only-export-components.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,26 @@ const valid = [
name: "export default memo function",
code: "export default memo(function Foo () {});",
},
{
name: "export default React.memo function",
code: "export default React.memo(function Foo () {});",
},
{
name: "export default memo function assignment",
code: "const Foo = () => {}; export default memo(Foo);",
},
{
name: "export default React.memo function assignment",
code: "const Foo = () => {}; export default React.memo(Foo);",
},
{
name: "export default memo function declaration",
code: "function Foo() {}; export default memo(Foo);",
},
{
name: "export default React.memo function declaration",
code: "function Foo() {}; export default React.memo(Foo);",
},
{
name: "export type *",
code: "export type * from './module';",
Expand Down
18 changes: 14 additions & 4 deletions src/only-export-components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,20 @@ export const onlyExportComponents: TSESLint.RuleModule<
handleExportIdentifier(node.id, true);
}
} else if (node.type === "CallExpression") {
if (
node.callee.type !== "Identifier" ||
!reactHOCs.has(node.callee.name)
) {
// we rule out non HoC first
if (node.callee.type !== "Identifier") {
// export default React.memo(function Foo() {})
// export default Preact.memo(function Foo() {})
if (
node.callee.type === "MemberExpression" &&
node.callee.property.type === "Identifier" &&
reactHOCs.has(node.callee.property.name)
) {
mayHaveReactExport = true;
} else {
context.report({ messageId: "anonymousExport", node });
}
} else if (!reactHOCs.has(node.callee.name)) {
// we rule out non HoC first
context.report({ messageId: "anonymousExport", node });
} else if (
Expand Down

0 comments on commit 7101b09

Please sign in to comment.