Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.8k
Description
Before You File a Bug Report Please Confirm You Have Done The Following...
- I have tried restarting my IDE and the issue persists.
- I have updated to the latest version of the packages.
- I havesearched for related issues and found none that matched my issue.
- I haveread the FAQ and my problem is not listed.
Playground Link
Repro Code
constshouldNotFlag1=`nan:${/* important */NaN}`constshouldNotFlag2=`undefined:${/* important */undefined}`constshouldNotFlag3=`infinity:${/* important */Infinity}`
ESLint Config
module.exports={"rules":{"@typescript-eslint/no-unnecessary-template-expression":"warn"}}
tsconfig
{"compilerOptions": {"strictNullChecks":true }}Expected Result
I expected none of these lines to flag
Actual Result
These lines all flag
Additional Info
This is just a matter of the comment check should come first:
typescript-eslint/packages/eslint-plugin/src/rules/no-unnecessary-template-expression.ts
Lines 159 to 203 inb17c7f2
| constfixableExpressionsReversed=node.expressions | |
| .map((expression,index)=>({ | |
| expression, | |
| nextQuasi:node.quasis[index+1], | |
| prevQuasi:node.quasis[index], | |
| })) | |
| .filter(({ expression, nextQuasi, prevQuasi})=>{ | |
| if( | |
| isUndefinedIdentifier(expression)|| | |
| isInfinityIdentifier(expression)|| | |
| isNaNIdentifier(expression) | |
| ){ | |
| returntrue; | |
| } | |
| // allow expressions that include comments | |
| if(hasCommentsBetweenQuasi(prevQuasi,nextQuasi)){ | |
| returnfalse; | |
| } | |
| if(isLiteral(expression)){ | |
| // allow trailing whitespace literal | |
| if(startsWithNewLine(nextQuasi.value.raw)){ | |
| return!( | |
| typeofexpression.value==='string'&& | |
| isWhitespace(expression.value) | |
| ); | |
| } | |
| returntrue; | |
| } | |
| if(isTemplateLiteral(expression)){ | |
| // allow trailing whitespace literal | |
| if(startsWithNewLine(nextQuasi.value.raw)){ | |
| return!( | |
| expression.quasis.length===1&& | |
| isWhitespace(expression.quasis[0].value.raw) | |
| ); | |
| } | |
| returntrue; | |
| } | |
| returnfalse; | |
| }) | |
| .reverse(); |