43081j / eslint-plugin-lit

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

fix no-useless-template-literals node position resolution #97

Closed 43081j closed 3 years ago

43081j commented 3 years ago

We were getting the expression after the position, rather than immediately after the position.

@stramel if you get chance could you double check this logic:

old behaviour

Given the position of an attribute, find the quasi (string) which satisfies one of:

Then return the expression after that quasi.

Confusing logic, basically though it meant that all attributes in the quasi would return the expression i think...

<x-foo
  attr="abc"
  .prop=${v}>

Both would return an expression using this logic. Even though only prop should.

new behaviour

Because the previous logic made my brain melt a bit, i removed it and wrote it from scratch.

Now we just look for an expression which:

43081j commented 3 years ago

@stramel i think its impossible to have an expression end on a different line to the attribute, so there is no test for it. but ill leave it there just as a safety net in case we somehow get some weird AST from the parser one day (or people using transforms etc)

i did add a fix and a test for quoted attributes though

stramel commented 3 years ago

LGTM!