Skip to content

Commit

Permalink
Update: fix false negative of no-useless-escape in template literal t…
Browse files Browse the repository at this point in the history
…ags (#8238)
  • Loading branch information
not-an-aardvark authored Mar 16, 2017
1 parent 47c3171 commit 7d1af86
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/rules/no-useless-escape.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,13 @@ module.exports = {
function check(node) {
const isTemplateElement = node.type === "TemplateElement";

if (isTemplateElement && node.parent && node.parent.parent && node.parent.parent.type === "TaggedTemplateExpression") {
if (
isTemplateElement &&
node.parent &&
node.parent.parent &&
node.parent.parent.type === "TaggedTemplateExpression" &&
node.parent === node.parent.parent.quasi
) {

// Don't report tagged template literals, because the backslash character is accessible to the tag function.
return;
Expand Down
5 changes: 5 additions & 0 deletions tests/lib/rules/no-useless-escape.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,11 @@ ruleTester.run("no-useless-escape", rule, {
code: "`multiline template\nliteral with useless \\escape`",
parserOptions: { ecmaVersion: 6 },
errors: [{ line: 2, column: 22, message: "Unnecessary escape character: \\e.", type: "TemplateElement" }]
},
{
code: "`\\a```",
parserOptions: { ecmaVersion: 6 },
errors: [{ line: 1, column: 2, message: "Unnecessary escape character: \\a.", type: "TemplateElement" }]
}
]
});

0 comments on commit 7d1af86

Please sign in to comment.