eslint-plugin-lit icon indicating copy to clipboard operation
eslint-plugin-lit copied to clipboard

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

Open stramel opened this issue 3 years ago • 3 comments

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.

stramel avatar May 10 '21 16:05 stramel

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?

bennypowers avatar May 10 '21 17:05 bennypowers

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

stramel avatar May 10 '21 17:05 stramel

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

bennypowers avatar May 10 '21 17:05 bennypowers