-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Bug: [no-unnecessary-template-expression] Report squigglies should underline template syntax, not just expression inside #8597
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I think you are conflating the report location with the behavior that it removes comments. Fixers removing comments is a pervasive issue in linters because, well, comments aren't part of the AST so it's hard to re-position them after changing the AST. Many other rules suffer from the same issue, such as #4730, but I don't see a general way to help. On the other hand, we absolutely want the report location to be as specific as possible. This rule checks each embedded expression one by one, so it should definitely report those expressions, not the template as a whole. |
To be clear, I'm proposing changing `use${'less'}template${'expressions'}`
^^^^^^ ^^^^^^^^^^^^^
// to this
`use${'less'}template${'expressions'}`
^^^^^^^^^ ^^^^^^^^^^^^^^^^
// NOT this
`use${'less'}template${'expressions'}`
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ But yeah, as long as we're talking about the same thing, if you think trying to include the |
Ahh—yeah that makes sense! I like that better. Not sure if it's easy to implement, considering those are not AST nodes, but this behavior is definitely more ideal. |
Ezpz 😊 the report API can take arbitrary loc, which we have in hand anyway for the autofixes |
The tokens should be readily available to seek backwards/forwards from the expression - so shouldn't be too bad. My one concern would be this case: `use${
'less'
}template${
'expressions'
}` Which is fairly common in prettier formatted code. // before
`use${
'less'
^^^^^^
}template${
'expressions'
^^^^^^^^^^^^^
}`
// after
`use${
^^
'less'
^^^^^^^^
}template${
^ ^^
'expressions'
^^^^^^^^^^^^^^^
}`
^ |
Having played around with this in a local playground, that's actually exactly what I liked about it a lot, because the error has nothing to do with the expression 'less' itself, it has to do with how it's used in the context of the adjacent lines, and that becomes more clear IMO. But I recognize that that is purely a personal preference. |
I also think this is fine, since the fixer modifies the embedding, not the expression. I'm also not sure if |
Before You File a Bug Report Please Confirm You Have Done The Following...
Playground Link
https://typescript-eslint.io/play/#ts=5.3.3&showAST=es&fileType=.tsx&code=AYJwpgDg9iAuAEBnAjgVwJYHNMBt1kXgBIBvAKHngHor4ATKeAOygVSbrBDybHlgAW6QgGMoAW3FgmsADTwY-AX1IKmSvhHAA3dFFSEeYAHQV4AIgAqygJ5qcd9p27peS4UlghXmeQDMQCXg0Vj5YRhDYE3MzGnhrPgBDVHC-dAAPeAB3dBwcT28IBRSNRD4xSWlYQkSODWISeFq6eABfeURGAEl3JgBreHQERAF9HBbY2icuIw1xJsIssDz5cPgRRLym2CiZPXU1wT4s0Zw%2BVyiQaBxE2H34ACMwH0n6rSgHs-F5FgQjwaYvBA8DA6S0BEQ9yGZRwflMrWAQA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6Jge1tmUSWWS18iALbF4AQ2G1Gw6BPioMkRNGgdokcGAC%2BIHUA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false
Repro Code
ESLint Config
tsconfig
Expected Result
Expect error squigglies starting on the
${
and continuing all the way through the closing}
Actual Result
only the quoted string itself has squigglies
Additional Info
I was playing around with this, and it's a very easy change to make. Would be happy to toss up a PR.
The text was updated successfully, but these errors were encountered: