Skip to content

Commit cb7cecd

Browse files
committed
Support for react-redux connect (fixes #51)
1 parent 762c15c commit cb7cecd

File tree

5 files changed

+19
-3
lines changed

5 files changed

+19
-3
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
- Support for `react-redux` connect (`export default connect(mapStateToProps, mapDispatchToProps)(MyComponent)`) (fixes #51)
6+
37
## 0.4.12
48

59
- Support type assertion on default export (fixes #48)

bun.lockb

0 Bytes
Binary file not shown.

src/only-export-components.test.ts

+4
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,10 @@ const valid = [
179179
name: "Export as default",
180180
code: "export { App as default }; const App = () => <>Test</>;",
181181
},
182+
{
183+
name: "Allow connect from react-redux",
184+
code: "const MyComponent = () => {}; export default connect(() => ({}))(MyComponent);",
185+
},
182186
];
183187

184188
const invalid = [

src/only-export-components.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,16 @@ export const onlyExportComponents: TSESLint.RuleModule<
157157
handleExportIdentifier(node.id, true);
158158
}
159159
} else if (node.type === "CallExpression") {
160-
// we rule out non HoC first
161-
if (node.callee.type !== "Identifier") {
160+
if (
161+
node.callee.type === "CallExpression" &&
162+
node.callee.callee.type === "Identifier" &&
163+
node.callee.callee.name === "connect"
164+
) {
165+
// support for react-redux
166+
// export default connect(mapStateToProps, mapDispatchToProps)(Comp)
167+
mayHaveReactExport = true;
168+
} else if (node.callee.type !== "Identifier") {
169+
// we rule out non HoC first
162170
// export default React.memo(function Foo() {})
163171
// export default Preact.memo(function Foo() {})
164172
if (

yarn.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ builtin-modules@^3.3.0:
458458
resolved "https://registry.npmjs.org/builtin-modules/-/builtin-modules-3.3.0.tgz"
459459
integrity sha512-zhaCDicdLuWN5UbN5IMnFqNMhNfo919sH85y2/ea+5Yg9TsTkeZxpL+JLbp6cgYFS4sRLp3YV4S6yDuqVWHYOw==
460460

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

0 commit comments

Comments
 (0)