Skip to content

Commit

Permalink
Support for react-redux connect (fixes #51)
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnaudBarre committed Oct 19, 2024
1 parent 762c15c commit cb7cecd
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## Unreleased

- Support for `react-redux` connect (`export default connect(mapStateToProps, mapDispatchToProps)(MyComponent)`) (fixes #51)

## 0.4.12

- Support type assertion on default export (fixes #48)
Expand Down
Binary file modified bun.lockb
Binary file not shown.
4 changes: 4 additions & 0 deletions src/only-export-components.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ const valid = [
name: "Export as default",
code: "export { App as default }; const App = () => <>Test</>;",
},
{
name: "Allow connect from react-redux",
code: "const MyComponent = () => {}; export default connect(() => ({}))(MyComponent);",
},
];

const invalid = [
Expand Down
12 changes: 10 additions & 2 deletions src/only-export-components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,16 @@ export const onlyExportComponents: TSESLint.RuleModule<
handleExportIdentifier(node.id, true);
}
} else if (node.type === "CallExpression") {
// we rule out non HoC first
if (node.callee.type !== "Identifier") {
if (
node.callee.type === "CallExpression" &&
node.callee.callee.type === "Identifier" &&
node.callee.callee.name === "connect"
) {
// support for react-redux
// export default connect(mapStateToProps, mapDispatchToProps)(Comp)
mayHaveReactExport = true;
} else if (node.callee.type !== "Identifier") {
// we rule out non HoC first
// export default React.memo(function Foo() {})
// export default Preact.memo(function Foo() {})
if (
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ builtin-modules@^3.3.0:
resolved "https://registry.npmjs.org/builtin-modules/-/builtin-modules-3.3.0.tgz"
integrity sha512-zhaCDicdLuWN5UbN5IMnFqNMhNfo919sH85y2/ea+5Yg9TsTkeZxpL+JLbp6cgYFS4sRLp3YV4S6yDuqVWHYOw==

bun-types@^1.0.15:
bun-types@^1.1.27:
version "1.1.27"
resolved "https://registry.npmjs.org/bun-types/-/bun-types-1.1.27.tgz"
integrity sha512-rHXAiIDefeMS/fleNM1rRDYqolJGNRdch3+AuCRwcZWaqTa1vjGBNsahH/HVV7Y82frllYhJomCVSEiHzLzkgg==
Expand Down

0 comments on commit cb7cecd

Please sign in to comment.