solidjs-community / eslint-plugin-solid

Solid-specific linting rules for ESLint.
MIT License
209 stars 24 forks source link

Support static props #78

Closed aminya closed 1 year ago

aminya commented 1 year ago

Describe the need

props in Solid components can be both reactive and also static. The current rules, especially, solid-js/reactivity gives warnings on the static usage of props. When I assign props to a constant or destructure it, I meant to make the property constant. However, the plugin detects that as an error.

Suggested Solution

I would like to see a static prefix to be added to the list of ignored props for this warning. The following should be ignored because of the static prefix.

const staticProp = props.staticProp

Possible Alternatives

There's no way to indicate this other than using eslint-disable or using initial/default prefixes. Both are undesirable for my intention.

Additional context

joshwilsonvu commented 1 year ago

Yes, I'd welcome a change to make solid/reactivity accept static as a prefix wherever initialand default are used. I think that's a good solution as static would be visible to the caller to help prevent accidentally passing a reactive value to these props.

In the future I could envision the rule actually warning on staticProp={signal()} in the call site. I assume you have no problem with that? But let's just do what you suggested for now.