Skip to content

Commit

Permalink
Fix: Support tagged template literal generics in no-unexpected-multil…
Browse files Browse the repository at this point in the history
…ine (#11698)
  • Loading branch information
bradzacher authored and platinumazure committed Nov 27, 2019
1 parent fa6415d commit ea16de4
Show file tree
Hide file tree
Showing 6 changed files with 1,118 additions and 1 deletion.
8 changes: 8 additions & 0 deletions lib/rules/no-unexpected-multiline.js
Expand Up @@ -74,6 +74,14 @@ module.exports = {
if (node.tag.loc.end.line === node.quasi.loc.start.line) {
return;
}

// handle generics type parameters on template tags
const tokenBefore = sourceCode.getTokenBefore(node.quasi);

if (tokenBefore.loc.end.line === node.quasi.loc.start.line) {
return;
}

context.report({ node, loc: node.loc.start, messageId: "taggedTemplate" });
},

Expand Down
@@ -0,0 +1,245 @@
"use strict";

/*
* Parsed on astexplorer.net using @typescript-eslint/parser@1.4.2
*
* Source:
* tag<generic>`
* multiline
* `;
*/

exports.parse = () => ({
type: "Program",
body: [
{
type: "ExpressionStatement",
expression: {
type: "TaggedTemplateExpression",
typeParameters: {
type: "TSTypeParameterInstantiation",
range: [3, 12],
loc: {
start: {
line: 1,
column: 3
},
end: {
line: 1,
column: 12
}
},
params: [
{
type: "TSTypeReference",
typeName: {
type: "Identifier",
name: "generic",
range: [4, 11],
loc: {
start: {
line: 1,
column: 4
},
end: {
line: 1,
column: 11
}
}
},
range: [4, 11],
loc: {
start: {
line: 1,
column: 4
},
end: {
line: 1,
column: 11
}
}
}
]
},
tag: {
type: "Identifier",
name: "tag",
range: [0, 3],
loc: {
start: {
line: 1,
column: 0
},
end: {
line: 1,
column: 3
}
}
},
quasi: {
type: "TemplateLiteral",
quasis: [
{
type: "TemplateElement",
value: {
raw: "\n multiline\n",
cooked: "\n multiline\n"
},
tail: true,
range: [12, 29],
loc: {
start: {
line: 1,
column: 12
},
end: {
line: 3,
column: 1
}
}
}
],
expressions: [],
range: [12, 29],
loc: {
start: {
line: 1,
column: 12
},
end: {
line: 3,
column: 1
}
}
},
range: [0, 29],
loc: {
start: {
line: 1,
column: 0
},
end: {
line: 3,
column: 1
}
}
},
range: [0, 30],
loc: {
start: {
line: 1,
column: 0
},
end: {
line: 3,
column: 2
}
}
}
],
sourceType: "script",
range: [0, 30],
loc: {
start: {
line: 1,
column: 0
},
end: {
line: 3,
column: 2
}
},
tokens: [
{
type: "Identifier",
value: "tag",
range: [0, 3],
loc: {
start: {
line: 1,
column: 0
},
end: {
line: 1,
column: 3
}
}
},
{
type: "Punctuator",
value: "<",
range: [3, 4],
loc: {
start: {
line: 1,
column: 3
},
end: {
line: 1,
column: 4
}
}
},
{
type: "Identifier",
value: "generic",
range: [4, 11],
loc: {
start: {
line: 1,
column: 4
},
end: {
line: 1,
column: 11
}
}
},
{
type: "Punctuator",
value: ">",
range: [11, 12],
loc: {
start: {
line: 1,
column: 11
},
end: {
line: 1,
column: 12
}
}
},
{
type: "Template",
value: "`\n multiline\n`",
range: [12, 29],
loc: {
start: {
line: 1,
column: 12
},
end: {
line: 3,
column: 1
}
}
},
{
type: "Punctuator",
value: ";",
range: [29, 30],
loc: {
start: {
line: 3,
column: 1
},
end: {
line: 3,
column: 2
}
}
}
],
comments: []
});

0 comments on commit ea16de4

Please sign in to comment.