43081j / eslint-plugin-lit

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

rule: quoted-expressions #79

Closed 43081j closed 3 years ago

43081j commented 3 years ago

Disallows:

<foo attr="${val}"></foo>

Allows:

<foo attr="foo ${val} bar"></foo>

@stramel if you get chance can you let me know if this makes sense as a rule, especially the way i've done it.

i went with the 'dumb' approach - just check if an expression is surrounded by quotes so i dont need to re-traverse the template. this means it will also disallow <foo @event="${handler}"> but i think thats fine

bennypowers commented 3 years ago

Could this be

"quoted-expressions": ["error", { "quotes": "always|never" }]
43081j commented 3 years ago

i did consider that, but was wondering what the use case ever would be for quoting them

only reason i didn't do it that way..

if there's good reason to have the choice then i will

bennypowers commented 3 years ago

since it's a linting rule there's room for project preference

in any event I usually quote always, so it would be better for me to not have to make that lint commit on an existing project

43081j commented 3 years ago

no worries, you are correct 👍 i have already reworked it to have an always and never option, and am adding a fixer for it so --fix will work

43081j commented 3 years ago

ok i've added a fixer and reworked the rule to have an always/never option (default: never).