solidjs-community / eslint-plugin-solid

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

reassigning props with `mergeProps` reactivity eslint error #132

Closed Tronikelis closed 3 months ago

Tronikelis commented 3 months ago

Your Question

Hello, I have a question about this specific use-case

function C(props) {
// The reactive variable 'props' should not be reassigned or altered directly
 props = mergeProps({d: 1}, props)
}

solid plugin catches this behavior as an error, but it works as you can see in this playground https://playground.solidjs.com/anonymous/20849471-1697-4f58-9f6a-c27e1924e31f

should this be allowed?

joshwilsonvu commented 3 months ago

This case technically works fine, but reassigning a reactive variable is very difficult for a plugin to analyze. In accordance with many of Solid's examples, we push users towards declaring any reactive variables with const. Your component can take a parameter called _props and assign the merged props to a constant called props--that's what the no-destructure rule does.

The behavior won't change here, but the error message could be improved if you have any suggestions.