Skip to content

Commit 4dcb1a4

Browse files
committed
Don't always treat lowercase function with JSX as taking props
1 parent 30d6da5 commit 4dcb1a4

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/rules/reactivity.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,11 @@ const rule: TSESLint.RuleModule<MessageIds, []> = {
379379
const paramsNode = currentScopeNode.params[0];
380380
if (
381381
paramsNode?.type === "Identifier" &&
382-
(currentScope().hasJSX || isPropsByName(paramsNode.name)) &&
382+
((currentScope().hasJSX &&
383+
(currentScopeNode.type !== "FunctionDeclaration" ||
384+
!currentScopeNode.id?.name?.match(/^[a-z]/))) ||
385+
// begins with lowercase === not component
386+
isPropsByName(paramsNode.name)) &&
383387
currentScopeNode.parent?.type !== "JSXExpressionContainer" // "render props" aren't components
384388
) {
385389
// This function is a component, consider its parameter a props

test/rules/reactivity.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,11 @@ export const cases = run("reactivity", rule, {
185185
untrack(() => {
186186
console.log(signal());
187187
});`,
188+
// has JSX, but lowercase function and not named props => don't treat first parameter as props
189+
`function notAComponent(something) {
190+
console.log(something.a);
191+
return <div />;
192+
}`,
188193
],
189194
invalid: [
190195
// Untracked signals
@@ -241,6 +246,15 @@ export const cases = run("reactivity", rule, {
241246
},
242247
],
243248
},
249+
// treat first parameter of uppercase function with JSX as a props
250+
{
251+
code: `
252+
function Component(something) {
253+
console.log(something.a);
254+
return <div />;
255+
}`,
256+
errors: [{ messageId: "untrackedReactive", type: T.MemberExpression }],
257+
},
244258
// Derived signals
245259
{
246260
code: `

0 commit comments

Comments
 (0)