Skip to content

Commit c534014

Browse files
jaskpCopilot
andcommitted
Support curried HOCs in customHOCs option
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: jaskp <35872026+jaskp@users.noreply.github.com>
1 parent 95c02ba commit c534014

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

src/only-export-components.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,21 @@ const valid = [
201201
code: "const MyComponent = () => {}; export default observer(MyComponent);",
202202
options: [{ customHOCs: ["observer"] }],
203203
},
204+
{
205+
name: "Curried HOC with styled (object form)",
206+
code: "export const Flex = styled('div')({display: 'flex'});",
207+
options: [{ customHOCs: ["styled"] }],
208+
},
209+
{
210+
name: "Curried HOC with styled (template literal form)",
211+
code: "export const Flex = styled('div')`display: flex;`;",
212+
options: [{ customHOCs: ["styled"] }],
213+
},
214+
{
215+
name: "Curried HOC only first call",
216+
code: "export const Flex = styled('div');",
217+
options: [{ customHOCs: ["styled"] }],
218+
},
204219
{
205220
name: "Local constant with component casing and non component function",
206221
code: "const SomeConstant = 42; export function someUtility() { return SomeConstant }",

src/only-export-components.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,18 @@ export const onlyExportComponents: TSESLint.RuleModule<
8282
if (!init) return false;
8383
const jsInit = skipTSWrapper(init);
8484
if (jsInit.type === "ArrowFunctionExpression") return true;
85-
if (
86-
jsInit.type === "CallExpression"
87-
&& jsInit.callee.type === "Identifier"
88-
) {
89-
return reactHOCs.includes(jsInit.callee.name);
85+
if (jsInit.type === "CallExpression") {
86+
// memo(...)
87+
if (jsInit.callee.type === "Identifier") {
88+
return reactHOCs.includes(jsInit.callee.name);
89+
}
90+
// Curried HOC: styled('div')({...})
91+
if (
92+
jsInit.callee.type === "CallExpression"
93+
&& jsInit.callee.callee.type === "Identifier"
94+
) {
95+
return reactHOCs.includes(jsInit.callee.callee.name);
96+
}
9097
}
9198
return false;
9299
};

0 commit comments

Comments
 (0)