43081j / eslint-plugin-lit

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

Add rule to disallow of side-effects inside the `render` method #90

Closed stramel closed 1 year ago

stramel commented 3 years ago

Potential Rule Name: no-render-side-effects

Disallows the use of "side-effects" inside the render method.

@bennypowers shows a simple case in this tweet: https://twitter.com/PowersBenny/status/1387330749217611776

This could a bit trickier of a rule to implement but would be a good rule to have.

bennypowers commented 3 years ago

indeed, could be tricky to check for any side effects. could we start with a no-this-assign-in-render or only-local-assign-in-render or something?

stramel commented 3 years ago

indeed, could be tricky to check for any side effects. could we start with a no-this-assign-in-render or only-local-assign-in-render or something?

Yeah, I was thinking along the same lines. Perhaps, also, adding a check for conditional assignments inside the render? I'm unsure what all we would want to consider warnings in a first round pass

bennypowers commented 3 years ago

given the nature of the problem we might want to take a narrow approach: local assignments in render are fine any other assignments, be they to this, window, or higher-scoped variables, are forbidden.

docs link to reasoning, users can turn the rule off if they want

later iterations might add acceptable cases or ignore regexp if there's demand