Skip to content

Commit 7d1af86

Browse files
Update: fix false negative of no-useless-escape in template literal tags (#8238)
1 parent 47c3171 commit 7d1af86

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

lib/rules/no-useless-escape.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,13 @@ module.exports = {
147147
function check(node) {
148148
const isTemplateElement = node.type === "TemplateElement";
149149

150-
if (isTemplateElement && node.parent && node.parent.parent && node.parent.parent.type === "TaggedTemplateExpression") {
150+
if (
151+
isTemplateElement &&
152+
node.parent &&
153+
node.parent.parent &&
154+
node.parent.parent.type === "TaggedTemplateExpression" &&
155+
node.parent === node.parent.parent.quasi
156+
) {
151157

152158
// Don't report tagged template literals, because the backslash character is accessible to the tag function.
153159
return;

tests/lib/rules/no-useless-escape.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,11 @@ ruleTester.run("no-useless-escape", rule, {
269269
code: "`multiline template\nliteral with useless \\escape`",
270270
parserOptions: { ecmaVersion: 6 },
271271
errors: [{ line: 2, column: 22, message: "Unnecessary escape character: \\e.", type: "TemplateElement" }]
272+
},
273+
{
274+
code: "`\\a```",
275+
parserOptions: { ecmaVersion: 6 },
276+
errors: [{ line: 1, column: 2, message: "Unnecessary escape character: \\a.", type: "TemplateElement" }]
272277
}
273278
]
274279
});

0 commit comments

Comments
 (0)