Skip to content

Commit ed57638

Browse files
committed
Don't warn when using props starting with 'initial'.
1 parent fd4f3f9 commit ed57638

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/rules/reactivity.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,8 @@ const rule: TSESLint.RuleModule<MessageIds, []> = {
445445
identifier.parent?.type === "MemberExpression" &&
446446
identifier.parent.object === identifier
447447
) {
448-
if (identifier.parent.parent?.type === "AssignmentExpression") {
448+
const { parent } = identifier;
449+
if (parent.parent?.type === "AssignmentExpression") {
449450
// don't allow writing to props or stores directly
450451
context.report({
451452
node: identifier,
@@ -454,6 +455,15 @@ const rule: TSESLint.RuleModule<MessageIds, []> = {
454455
name: identifier.name,
455456
},
456457
});
458+
} else if (
459+
parent.property.type === "Identifier" &&
460+
/^initial[A-Z]/.test(parent.property.name)
461+
) {
462+
// We're using a prop with a name that starts with `initial`, like
463+
// `props.initialCount`. We'll refrain from warning about untracked usages
464+
// of these props, because the user has shown that they understand
465+
// the consequences of using a reactive variable to initialize
466+
// something else. Do nothing.
457467
} else {
458468
// The props are the object in a property read access, which
459469
// should be under a tracked scope.

test/rules/reactivity.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,11 @@ export const cases = run("reactivity", rule, {
152152
const [signal, setSignal] = createSignal(1);
153153
return <div on:click={() => console.log(signal())} />;
154154
}`,
155+
// Don't warn on using props.initial* for initialization
156+
`function Component(props) {
157+
const [count, setCount] = useSignal(props.initialCount);
158+
return <div>{count()}</div>;
159+
}`,
155160
],
156161
invalid: [
157162
// Untracked signals

0 commit comments

Comments
 (0)