-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Closed
Copy link
Labels
accepting prsGo ahead, send a pull request that resolves this issueGo ahead, send a pull request that resolves this issuebugSomething isn't workingSomething isn't workinglocked due to agePlease open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.package: eslint-pluginIssues related to @typescript-eslint/eslint-pluginIssues related to @typescript-eslint/eslint-plugin
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 have searched for related issues and found none that matched my issue.
- I have read the FAQ and my problem is not listed.
Playground Link
Repro Code
const shouldNotFlag1 = `nan: ${/* important */ NaN}`
const shouldNotFlag2 = `undefined: ${/* important */ undefined}`
const shouldNotFlag3 = `infinity: ${/* important */ Infinity}`
ESLint Config
module.exports = {
"rules": {
"@typescript-eslint/no-unnecessary-template-expression": "warn"
}
}
tsconfig
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 in b17c7f2
const fixableExpressionsReversed = 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) | |
) { | |
return true; | |
} | |
// allow expressions that include comments | |
if (hasCommentsBetweenQuasi(prevQuasi, nextQuasi)) { | |
return false; | |
} | |
if (isLiteral(expression)) { | |
// allow trailing whitespace literal | |
if (startsWithNewLine(nextQuasi.value.raw)) { | |
return !( | |
typeof expression.value === 'string' && | |
isWhitespace(expression.value) | |
); | |
} | |
return true; | |
} | |
if (isTemplateLiteral(expression)) { | |
// allow trailing whitespace literal | |
if (startsWithNewLine(nextQuasi.value.raw)) { | |
return !( | |
expression.quasis.length === 1 && | |
isWhitespace(expression.quasis[0].value.raw) | |
); | |
} | |
return true; | |
} | |
return false; | |
}) | |
.reverse(); |
Metadata
Metadata
Assignees
Labels
accepting prsGo ahead, send a pull request that resolves this issueGo ahead, send a pull request that resolves this issuebugSomething isn't workingSomething isn't workinglocked due to agePlease open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.package: eslint-pluginIssues related to @typescript-eslint/eslint-pluginIssues related to @typescript-eslint/eslint-plugin