43081j / eslint-plugin-lit

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

replace resolveLocation with a simpler implementation #100

Closed 43081j closed 3 years ago

43081j commented 3 years ago

resolveLocation has been left alone for quite some time because its already so delicate.

though it turns out @stramel discovered many of our errors are reported with the wrong position information and tests didn't catch this as they either had no end column, or we just didn't check that the asserted column actually was the right one! 🤦‍♂️

nobody understood this function and i struggled to remember too, so i deleted it.

i've rewritten it from scratch based on offsets, with getLocFromIndex being our saviour here 🥳 this means we don't need to calculate line changes, account for multi-line expressions, quasis, etc. that was where most of the complexity lived before.

here's how we calculate it now:

cc @stramel

FYI i have commented the function a fair amount to help explain it

stramel commented 3 years ago

LGTM

Tested it out in a project:

image

43081j commented 3 years ago

ill try add some tests before we merge but that looks great, thanks a lot for checking it in an editor