solidjs-community / eslint-plugin-solid

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

solid/reactivity for observable #89

Closed voliva closed 1 year ago

voliva commented 1 year ago

Describe the bug inline functions passed into observable from solid-js are maked as invalid as per solid/reactivity

To Reproduce

import { observable } from 'solid-js';

const Component = props => {
  const count$ = observable(() => props.count);

  ...
}

In this case the function is marked as invalid with This function should be passed to a tracked scope (like createEffect) or an event handler because it contains reactivity, or else changes will be ignored., but it is one of the intended ways of using observable if I'm not wrong (please correct me if it is wrong, I'm still new at SolidJS!)

I saw the upcoming refactor at #87, along with the note on the docs which say that maintaining the current version is hard to do. I have some experience writing eslint plugins so I'd like to give it a try, but if you think it's not worth it I might just wait until the refactor is done.

joshwilsonvu commented 1 year ago

Hi, thanks for offering to help! You’re right that there’s currently not support for observable and adding support would be great.

Sorry if those notes give the impression that the current rule is totally unmaintainable—it’s not hard to make changes like this so now is a good time. It’s talking more about complex control flow analysis and handling things like curried functions.

It looks like observable is to be treated by the rule in the same way as createEffect, so search in the rule where it marks the createEffect argument as a tracked scope and just add observable there. Should be a small change.

Thanks again!

voliva commented 1 year ago

Yes, that was trivial :D

The notes did sound as it was hard to change anything so I got scared about it.