Skip to content

Commit ea16de4

Browse files
bradzacherplatinumazure
authored andcommitted
Fix: Support tagged template literal generics in no-unexpected-multiline (#11698)
1 parent fa6415d commit ea16de4

6 files changed

Lines changed: 1118 additions & 1 deletion

File tree

lib/rules/no-unexpected-multiline.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,14 @@ module.exports = {
7474
if (node.tag.loc.end.line === node.quasi.loc.start.line) {
7575
return;
7676
}
77+
78+
// handle generics type parameters on template tags
79+
const tokenBefore = sourceCode.getTokenBefore(node.quasi);
80+
81+
if (tokenBefore.loc.end.line === node.quasi.loc.start.line) {
82+
return;
83+
}
84+
7785
context.report({ node, loc: node.loc.start, messageId: "taggedTemplate" });
7886
},
7987

Lines changed: 245 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,245 @@
1+
"use strict";
2+
3+
/*
4+
* Parsed on astexplorer.net using @typescript-eslint/[email protected]
5+
*
6+
* Source:
7+
* tag<generic>`
8+
* multiline
9+
* `;
10+
*/
11+
12+
exports.parse = () => ({
13+
type: "Program",
14+
body: [
15+
{
16+
type: "ExpressionStatement",
17+
expression: {
18+
type: "TaggedTemplateExpression",
19+
typeParameters: {
20+
type: "TSTypeParameterInstantiation",
21+
range: [3, 12],
22+
loc: {
23+
start: {
24+
line: 1,
25+
column: 3
26+
},
27+
end: {
28+
line: 1,
29+
column: 12
30+
}
31+
},
32+
params: [
33+
{
34+
type: "TSTypeReference",
35+
typeName: {
36+
type: "Identifier",
37+
name: "generic",
38+
range: [4, 11],
39+
loc: {
40+
start: {
41+
line: 1,
42+
column: 4
43+
},
44+
end: {
45+
line: 1,
46+
column: 11
47+
}
48+
}
49+
},
50+
range: [4, 11],
51+
loc: {
52+
start: {
53+
line: 1,
54+
column: 4
55+
},
56+
end: {
57+
line: 1,
58+
column: 11
59+
}
60+
}
61+
}
62+
]
63+
},
64+
tag: {
65+
type: "Identifier",
66+
name: "tag",
67+
range: [0, 3],
68+
loc: {
69+
start: {
70+
line: 1,
71+
column: 0
72+
},
73+
end: {
74+
line: 1,
75+
column: 3
76+
}
77+
}
78+
},
79+
quasi: {
80+
type: "TemplateLiteral",
81+
quasis: [
82+
{
83+
type: "TemplateElement",
84+
value: {
85+
raw: "\n multiline\n",
86+
cooked: "\n multiline\n"
87+
},
88+
tail: true,
89+
range: [12, 29],
90+
loc: {
91+
start: {
92+
line: 1,
93+
column: 12
94+
},
95+
end: {
96+
line: 3,
97+
column: 1
98+
}
99+
}
100+
}
101+
],
102+
expressions: [],
103+
range: [12, 29],
104+
loc: {
105+
start: {
106+
line: 1,
107+
column: 12
108+
},
109+
end: {
110+
line: 3,
111+
column: 1
112+
}
113+
}
114+
},
115+
range: [0, 29],
116+
loc: {
117+
start: {
118+
line: 1,
119+
column: 0
120+
},
121+
end: {
122+
line: 3,
123+
column: 1
124+
}
125+
}
126+
},
127+
range: [0, 30],
128+
loc: {
129+
start: {
130+
line: 1,
131+
column: 0
132+
},
133+
end: {
134+
line: 3,
135+
column: 2
136+
}
137+
}
138+
}
139+
],
140+
sourceType: "script",
141+
range: [0, 30],
142+
loc: {
143+
start: {
144+
line: 1,
145+
column: 0
146+
},
147+
end: {
148+
line: 3,
149+
column: 2
150+
}
151+
},
152+
tokens: [
153+
{
154+
type: "Identifier",
155+
value: "tag",
156+
range: [0, 3],
157+
loc: {
158+
start: {
159+
line: 1,
160+
column: 0
161+
},
162+
end: {
163+
line: 1,
164+
column: 3
165+
}
166+
}
167+
},
168+
{
169+
type: "Punctuator",
170+
value: "<",
171+
range: [3, 4],
172+
loc: {
173+
start: {
174+
line: 1,
175+
column: 3
176+
},
177+
end: {
178+
line: 1,
179+
column: 4
180+
}
181+
}
182+
},
183+
{
184+
type: "Identifier",
185+
value: "generic",
186+
range: [4, 11],
187+
loc: {
188+
start: {
189+
line: 1,
190+
column: 4
191+
},
192+
end: {
193+
line: 1,
194+
column: 11
195+
}
196+
}
197+
},
198+
{
199+
type: "Punctuator",
200+
value: ">",
201+
range: [11, 12],
202+
loc: {
203+
start: {
204+
line: 1,
205+
column: 11
206+
},
207+
end: {
208+
line: 1,
209+
column: 12
210+
}
211+
}
212+
},
213+
{
214+
type: "Template",
215+
value: "`\n multiline\n`",
216+
range: [12, 29],
217+
loc: {
218+
start: {
219+
line: 1,
220+
column: 12
221+
},
222+
end: {
223+
line: 3,
224+
column: 1
225+
}
226+
}
227+
},
228+
{
229+
type: "Punctuator",
230+
value: ";",
231+
range: [29, 30],
232+
loc: {
233+
start: {
234+
line: 3,
235+
column: 1
236+
},
237+
end: {
238+
line: 3,
239+
column: 2
240+
}
241+
}
242+
}
243+
],
244+
comments: []
245+
});

0 commit comments

Comments
 (0)