43081j / eslint-plugin-lit

lit-html support for ESLint
120 stars 22 forks source link

Fix `no-template-arrow` false positives #189

Open jpzwarte opened 10 months ago

jpzwarte commented 10 months ago

These are currently marked as invalid:

I believe they are false positives since the arguments to the method do not match the arguments of the arrow function.

The rule should only be applicable when the arguments to the arrow function match the arguments of the called function.

43081j commented 10 months ago

this is an interesting one, really a question of the intent of this rule

the original intent of the rule wasn't necessarily to catch problems (i.e. incompatible signatures for events), it was to encourage moving listeners into methods or variables instead of inlining them.

at the time in particular, best practice seemed to be to avoid arrow funcs so we don't create a new function every time we render. but there's little overhead there now (if there ever was), since lit will just change the reference and keep the same listener.

ultimately, its turned into a stylistic rule instead - people (not everyone ofc) preferring interpolating references rather than inline functions.

in your situation, i'd just turn it off since your stylistic preference doesn't agree with it. and maybe remove it from the recommended rule set.

if we repurpose the rule to be about types (e.g. args matching), we're stepping on the toes of typescript and probably shouldn't be.

jpzwarte commented 10 months ago

in your situation, i'd just turn it off since your stylistic preference doesn't agree with it. and maybe remove it from the recommended rule set.

Right, I've already disabled it. And to avoid future confusion, I think removing it from the recommended rule set might be a good idea!

if we repurpose the rule to be about types (e.g. args matching), we're stepping on the toes of typescript and probably shouldn't be.

Right, as you explained, this would change the intention of the rule significantly.

43081j commented 10 months ago

ill open a pr when i get chance to remove it from the recommended config (unless you beat me to it!)

thanks for raising it, its a pretty old rule and doesn't have as much meaning anymore