solidjs-community / eslint-plugin-solid

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

reactivity: IIFEs should not warn if they are executed in a tracked scope #17

Closed otonashixav closed 2 years ago

otonashixav commented 2 years ago

Describe the bug The following examples cause reactivity to warn with the message "This function should be passed to a tracked scope (like createEffect) or an event handler because it contains reactivity."

createEffect(() => {
  (() => count())();
});
<div>{(() => count())()}</div>

It is occasionally useful to place IIFEs in JSX if one does not wish to place the function into a variable for some reason. To be clear, while not executing the function is possible, it is undesired as they are compiled differently in certain situtations e.g. passing multiple children to a component or fragment), (() => count())() turns into memo(() => count()) whereas () => count() turns into () => count(), and () => count() is a function, whereas (() => count())() is resolved to a getter when passed as the only child of a component.

Expected behavior As the functions are immediately executed within a tracked scope there should be no warning.

joshwilsonvu commented 2 years ago

Hi, thanks for the issue. I made a commit to solve this and added your examples as test cases, but I'm going to see if I can address one or both of your other issues soon before publishing a new package. I'll let you know when the fixed version is published to npm.

joshwilsonvu commented 2 years ago

This is fixed in v0.4.7!