solidjs-community / eslint-plugin-solid

Solid-specific linting rules for ESLint.
MIT License
216 stars 26 forks source link

Reactivity rule shouldn't warn when using `props.initial*` to initialize something else #12

Closed joshwilsonvu closed 2 years ago

joshwilsonvu commented 2 years ago

Describe the bug

It's a somewhat common pattern in React and Solid to initialize a signal/state with the value of a prop. Given that props change over time, making this normally unsafe, a pseudo-standard has emerged to communicate that certain props are intended to be used for this purpose: prefixing them with "initial".

The reactivity rule should catch these cases and suppress the usual "The reactive variable 'props' should be used in a tracked scope" message.

To Reproduce To reproduce the behavior:

function Component(props) {
  const [count, setCount] = useSignal(props.initialCount);
  return <div>{count()}</div>;
}

Expected behavior The above snippet shouldn't warn.

Desktop (please complete the following information):