]>
Commit | Line | Data |
---|---|---|
eb39fafa DC |
1 | /** |
2 | * @fileoverview Tests for no-warning-comments rule. | |
3 | * @author Alexander Schmidt <https://github.com/lxanders> | |
4 | */ | |
5 | ||
6 | "use strict"; | |
7 | ||
8 | //------------------------------------------------------------------------------ | |
9 | // Requirements | |
10 | //------------------------------------------------------------------------------ | |
11 | ||
12 | const rule = require("../../../lib/rules/no-warning-comments"), | |
13 | { RuleTester } = require("../../../lib/rule-tester"); | |
14 | ||
15 | //------------------------------------------------------------------------------ | |
16 | // Tests | |
17 | //------------------------------------------------------------------------------ | |
18 | ||
19 | const ruleTester = new RuleTester(); | |
20 | ||
21 | ruleTester.run("no-warning-comments", rule, { | |
22 | valid: [ | |
23 | { code: "// any comment", options: [{ terms: ["fixme"] }] }, | |
24 | { code: "// any comment", options: [{ terms: ["fixme", "todo"] }] }, | |
25 | "// any comment", | |
26 | { code: "// any comment", options: [{ location: "anywhere" }] }, | |
27 | { code: "// any comment with TODO, FIXME or XXX", options: [{ location: "start" }] }, | |
28 | "// any comment with TODO, FIXME or XXX", | |
29 | { code: "/* any block comment */", options: [{ terms: ["fixme"] }] }, | |
30 | { code: "/* any block comment */", options: [{ terms: ["fixme", "todo"] }] }, | |
31 | "/* any block comment */", | |
32 | { code: "/* any block comment */", options: [{ location: "anywhere" }] }, | |
33 | { code: "/* any block comment with TODO, FIXME or XXX */", options: [{ location: "start" }] }, | |
34 | "/* any block comment with TODO, FIXME or XXX */", | |
35 | "/* any block comment with (TODO, FIXME's or XXX!) */", | |
36 | { code: "// comments containing terms as substrings like TodoMVC", options: [{ terms: ["todo"], location: "anywhere" }] }, | |
8f9d1d4d | 37 | { code: "// special regex characters don't cause a problem", options: [{ terms: ["[aeiou]"], location: "anywhere" }] }, |
eb39fafa DC |
38 | "/*eslint no-warning-comments: [2, { \"terms\": [\"todo\", \"fixme\", \"any other term\"], \"location\": \"anywhere\" }]*/\n\nvar x = 10;\n", |
39 | { code: "/*eslint no-warning-comments: [2, { \"terms\": [\"todo\", \"fixme\", \"any other term\"], \"location\": \"anywhere\" }]*/\n\nvar x = 10;\n", options: [{ location: "anywhere" }] }, | |
8f9d1d4d DC |
40 | { code: "// foo", options: [{ terms: ["foo-bar"] }] }, |
41 | "/** multi-line block comment with lines starting with\nTODO\nFIXME or\nXXX\n*/", | |
42 | { code: "//!TODO ", options: [{ decoration: ["*"] }] } | |
eb39fafa DC |
43 | ], |
44 | invalid: [ | |
45 | { | |
46 | code: "// fixme", | |
47 | errors: [ | |
6f036462 | 48 | { messageId: "unexpectedComment", data: { matchedTerm: "fixme", comment: "fixme" } } |
eb39fafa DC |
49 | ] |
50 | }, | |
51 | { | |
52 | code: "// any fixme", | |
53 | options: [{ location: "anywhere" }], | |
54 | errors: [ | |
6f036462 | 55 | { messageId: "unexpectedComment", data: { matchedTerm: "fixme", comment: "any fixme" } } |
eb39fafa DC |
56 | ] |
57 | }, | |
58 | { | |
59 | code: "// any fixme", | |
60 | options: [{ terms: ["fixme"], location: "anywhere" }], | |
61 | errors: [ | |
6f036462 | 62 | { messageId: "unexpectedComment", data: { matchedTerm: "fixme", comment: "any fixme" } } |
eb39fafa DC |
63 | ] |
64 | }, | |
65 | { | |
66 | code: "// any FIXME", | |
67 | options: [{ terms: ["fixme"], location: "anywhere" }], | |
68 | errors: [ | |
6f036462 | 69 | { messageId: "unexpectedComment", data: { matchedTerm: "fixme", comment: "any FIXME" } } |
eb39fafa DC |
70 | ] |
71 | }, | |
72 | { | |
73 | code: "// any fIxMe", | |
74 | options: [{ terms: ["fixme"], location: "anywhere" }], | |
75 | errors: [ | |
6f036462 | 76 | { messageId: "unexpectedComment", data: { matchedTerm: "fixme", comment: "any fIxMe" } } |
eb39fafa DC |
77 | ] |
78 | }, | |
79 | { | |
80 | code: "/* any fixme */", | |
81 | options: [{ terms: ["FIXME"], location: "anywhere" }], | |
82 | errors: [ | |
6f036462 | 83 | { messageId: "unexpectedComment", data: { matchedTerm: "FIXME", comment: "any fixme" } } |
eb39fafa DC |
84 | ] |
85 | }, | |
86 | { | |
87 | code: "/* any FIXME */", | |
88 | options: [{ terms: ["FIXME"], location: "anywhere" }], | |
89 | errors: [ | |
6f036462 | 90 | { messageId: "unexpectedComment", data: { matchedTerm: "FIXME", comment: "any FIXME" } } |
eb39fafa DC |
91 | ] |
92 | }, | |
93 | { | |
94 | code: "/* any fIxMe */", | |
95 | options: [{ terms: ["FIXME"], location: "anywhere" }], | |
96 | errors: [ | |
6f036462 | 97 | { messageId: "unexpectedComment", data: { matchedTerm: "FIXME", comment: "any fIxMe" } } |
eb39fafa DC |
98 | ] |
99 | }, | |
100 | { | |
101 | code: "// any fixme or todo", | |
102 | options: [{ terms: ["fixme", "todo"], location: "anywhere" }], | |
103 | errors: [ | |
6f036462 TL |
104 | { messageId: "unexpectedComment", data: { matchedTerm: "fixme", comment: "any fixme or todo" } }, |
105 | { messageId: "unexpectedComment", data: { matchedTerm: "todo", comment: "any fixme or todo" } } | |
eb39fafa DC |
106 | ] |
107 | }, | |
108 | { | |
109 | code: "/* any fixme or todo */", | |
110 | options: [{ terms: ["fixme", "todo"], location: "anywhere" }], | |
111 | errors: [ | |
6f036462 TL |
112 | { messageId: "unexpectedComment", data: { matchedTerm: "fixme", comment: "any fixme or todo" } }, |
113 | { messageId: "unexpectedComment", data: { matchedTerm: "todo", comment: "any fixme or todo" } } | |
eb39fafa DC |
114 | ] |
115 | }, | |
116 | { | |
117 | code: "/* any fixme or todo */", | |
118 | options: [{ location: "anywhere" }], | |
119 | errors: [ | |
6f036462 TL |
120 | { messageId: "unexpectedComment", data: { matchedTerm: "todo", comment: "any fixme or todo" } }, |
121 | { messageId: "unexpectedComment", data: { matchedTerm: "fixme", comment: "any fixme or todo" } } | |
eb39fafa DC |
122 | ] |
123 | }, | |
124 | { | |
125 | code: "/* fixme and todo */", | |
126 | errors: [ | |
6f036462 | 127 | { messageId: "unexpectedComment", data: { matchedTerm: "fixme", comment: "fixme and todo" } } |
eb39fafa DC |
128 | ] |
129 | }, | |
130 | { | |
131 | code: "/* fixme and todo */", | |
132 | options: [{ location: "anywhere" }], | |
133 | errors: [ | |
6f036462 TL |
134 | { messageId: "unexpectedComment", data: { matchedTerm: "todo", comment: "fixme and todo" } }, |
135 | { messageId: "unexpectedComment", data: { matchedTerm: "fixme", comment: "fixme and todo" } } | |
eb39fafa DC |
136 | ] |
137 | }, | |
138 | { | |
139 | code: "/* any fixme */", | |
140 | options: [{ location: "anywhere" }], | |
141 | errors: [ | |
6f036462 | 142 | { messageId: "unexpectedComment", data: { matchedTerm: "fixme", comment: "any fixme" } } |
eb39fafa DC |
143 | ] |
144 | }, | |
145 | { | |
146 | code: "/* fixme! */", | |
147 | options: [{ terms: ["fixme"] }], | |
148 | errors: [ | |
6f036462 | 149 | { messageId: "unexpectedComment", data: { matchedTerm: "fixme", comment: "fixme!" } } |
eb39fafa DC |
150 | ] |
151 | }, | |
152 | { | |
153 | code: "// regex [litera|$]", | |
154 | options: [{ terms: ["[litera|$]"], location: "anywhere" }], | |
155 | errors: [ | |
6f036462 | 156 | { messageId: "unexpectedComment", data: { matchedTerm: "[litera|$]", comment: "regex [litera|$]" } } |
eb39fafa DC |
157 | ] |
158 | }, | |
159 | { | |
160 | code: "/* eslint one-var: 2 */", | |
161 | options: [{ terms: ["eslint"] }], | |
162 | errors: [ | |
6f036462 | 163 | { messageId: "unexpectedComment", data: { matchedTerm: "eslint", comment: "eslint one-var: 2" } } |
eb39fafa DC |
164 | ] |
165 | }, | |
166 | { | |
167 | code: "/* eslint one-var: 2 */", | |
168 | options: [{ terms: ["one"], location: "anywhere" }], | |
169 | errors: [ | |
6f036462 | 170 | { messageId: "unexpectedComment", data: { matchedTerm: "one", comment: "eslint one-var: 2" } } |
eb39fafa DC |
171 | ] |
172 | }, | |
173 | { | |
174 | code: "/* any block comment with TODO, FIXME or XXX */", | |
175 | options: [{ location: "anywhere" }], | |
176 | errors: [ | |
6f036462 TL |
177 | { messageId: "unexpectedComment", data: { matchedTerm: "todo", comment: "any block comment with TODO, FIXME or..." } }, |
178 | { messageId: "unexpectedComment", data: { matchedTerm: "fixme", comment: "any block comment with TODO, FIXME or..." } }, | |
179 | { messageId: "unexpectedComment", data: { matchedTerm: "xxx", comment: "any block comment with TODO, FIXME or..." } } | |
eb39fafa DC |
180 | ] |
181 | }, | |
182 | { | |
183 | code: "/* any block comment with (TODO, FIXME's or XXX!) */", | |
184 | options: [{ location: "anywhere" }], | |
185 | errors: [ | |
6f036462 TL |
186 | { messageId: "unexpectedComment", data: { matchedTerm: "todo", comment: "any block comment with (TODO, FIXME's or..." } }, |
187 | { messageId: "unexpectedComment", data: { matchedTerm: "fixme", comment: "any block comment with (TODO, FIXME's or..." } }, | |
188 | { messageId: "unexpectedComment", data: { matchedTerm: "xxx", comment: "any block comment with (TODO, FIXME's or..." } } | |
eb39fafa DC |
189 | ] |
190 | }, | |
191 | { | |
192 | code: "/** \n *any block comment \n*with (TODO, FIXME's or XXX!) **/", | |
193 | options: [{ location: "anywhere" }], | |
194 | errors: [ | |
6f036462 TL |
195 | { messageId: "unexpectedComment", data: { matchedTerm: "todo", comment: "* *any block comment *with (TODO,..." } }, |
196 | { messageId: "unexpectedComment", data: { matchedTerm: "fixme", comment: "* *any block comment *with (TODO,..." } }, | |
197 | { messageId: "unexpectedComment", data: { matchedTerm: "xxx", comment: "* *any block comment *with (TODO,..." } } | |
eb39fafa DC |
198 | ] |
199 | }, | |
200 | { | |
201 | code: "// any comment with TODO, FIXME or XXX", | |
202 | options: [{ location: "anywhere" }], | |
203 | errors: [ | |
6f036462 TL |
204 | { messageId: "unexpectedComment", data: { matchedTerm: "todo", comment: "any comment with TODO, FIXME or XXX" } }, |
205 | { messageId: "unexpectedComment", data: { matchedTerm: "fixme", comment: "any comment with TODO, FIXME or XXX" } }, | |
206 | { messageId: "unexpectedComment", data: { matchedTerm: "xxx", comment: "any comment with TODO, FIXME or XXX" } } | |
207 | ] | |
208 | }, | |
209 | { | |
210 | code: "// TODO: something small", | |
211 | options: [{ location: "anywhere" }], | |
212 | errors: [ | |
213 | { messageId: "unexpectedComment", data: { matchedTerm: "todo", comment: "TODO: something small" } } | |
214 | ] | |
215 | }, | |
216 | { | |
217 | code: "// TODO: something really longer than 40 characters", | |
218 | options: [{ location: "anywhere" }], | |
219 | errors: [ | |
220 | { messageId: "unexpectedComment", data: { matchedTerm: "todo", comment: "TODO: something really longer than 40..." } } | |
221 | ] | |
222 | }, | |
223 | { | |
224 | code: | |
225 | "/* TODO: something \n really longer than 40 characters \n and also a new line */", | |
226 | options: [{ location: "anywhere" }], | |
227 | errors: [ | |
228 | { | |
229 | messageId: "unexpectedComment", | |
230 | data: { | |
231 | matchedTerm: "todo", | |
232 | comment: "TODO: something really longer than 40..." | |
233 | } | |
234 | } | |
235 | ] | |
236 | }, | |
237 | { | |
238 | code: "// TODO: small", | |
239 | options: [{ location: "anywhere" }], | |
240 | errors: [ | |
241 | { | |
242 | messageId: "unexpectedComment", | |
243 | data: { | |
244 | matchedTerm: "todo", | |
245 | comment: "TODO: small" | |
246 | } | |
247 | } | |
248 | ] | |
249 | }, | |
250 | { | |
251 | code: "// https://github.com/eslint/eslint/pull/13522#discussion_r470293411 TODO", | |
252 | options: [{ location: "anywhere" }], | |
253 | errors: [ | |
254 | { | |
255 | messageId: "unexpectedComment", | |
256 | data: { | |
257 | matchedTerm: "todo", | |
258 | comment: "..." | |
259 | } | |
260 | } | |
eb39fafa | 261 | ] |
8f9d1d4d DC |
262 | }, |
263 | { | |
264 | code: "// Comment ending with term followed by punctuation TODO!", | |
265 | options: [{ terms: ["todo"], location: "anywhere" }], | |
266 | errors: [ | |
267 | { | |
268 | messageId: "unexpectedComment", | |
269 | data: { | |
270 | matchedTerm: "todo", | |
271 | comment: "Comment ending with term followed by..." | |
272 | } | |
273 | } | |
274 | ] | |
275 | }, | |
276 | { | |
277 | code: "// Comment ending with term including punctuation TODO!", | |
278 | options: [{ terms: ["todo!"], location: "anywhere" }], | |
279 | errors: [ | |
280 | { | |
281 | messageId: "unexpectedComment", | |
282 | data: { | |
283 | matchedTerm: "todo!", | |
284 | comment: "Comment ending with term including..." | |
285 | } | |
286 | } | |
287 | ] | |
288 | }, | |
289 | { | |
290 | code: "// Comment ending with term including punctuation followed by more TODO!!!", | |
291 | options: [{ terms: ["todo!"], location: "anywhere" }], | |
292 | errors: [ | |
293 | { | |
294 | messageId: "unexpectedComment", | |
295 | data: { | |
296 | matchedTerm: "todo!", | |
297 | comment: "Comment ending with term including..." | |
298 | } | |
299 | } | |
300 | ] | |
301 | }, | |
302 | { | |
303 | code: "// !TODO comment starting with term preceded by punctuation", | |
304 | options: [{ terms: ["todo"], location: "anywhere" }], | |
305 | errors: [ | |
306 | { | |
307 | messageId: "unexpectedComment", | |
308 | data: { | |
309 | matchedTerm: "todo", | |
310 | comment: "!TODO comment starting with term..." | |
311 | } | |
312 | } | |
313 | ] | |
314 | }, | |
315 | { | |
316 | code: "// !TODO comment starting with term including punctuation", | |
317 | options: [{ terms: ["!todo"], location: "anywhere" }], | |
318 | errors: [ | |
319 | { | |
320 | messageId: "unexpectedComment", | |
321 | data: { | |
322 | matchedTerm: "!todo", | |
323 | comment: "!TODO comment starting with term..." | |
324 | } | |
325 | } | |
326 | ] | |
327 | }, | |
328 | { | |
329 | code: "// !!!TODO comment starting with term including punctuation preceded by more", | |
330 | options: [{ terms: ["!todo"], location: "anywhere" }], | |
331 | errors: [ | |
332 | { | |
333 | messageId: "unexpectedComment", | |
334 | data: { | |
335 | matchedTerm: "!todo", | |
336 | comment: "!!!TODO comment starting with term..." | |
337 | } | |
338 | } | |
339 | ] | |
340 | }, | |
341 | { | |
342 | code: "// FIX!term ending with punctuation followed word character", | |
343 | options: [{ terms: ["FIX!"], location: "anywhere" }], | |
344 | errors: [ | |
345 | { | |
346 | messageId: "unexpectedComment", | |
347 | data: { | |
348 | matchedTerm: "FIX!", | |
349 | comment: "FIX!term ending with punctuation..." | |
350 | } | |
351 | } | |
352 | ] | |
353 | }, | |
354 | { | |
355 | code: "// Term starting with punctuation preceded word character!FIX", | |
356 | options: [{ terms: ["!FIX"], location: "anywhere" }], | |
357 | errors: [ | |
358 | { | |
359 | messageId: "unexpectedComment", | |
360 | data: { | |
361 | matchedTerm: "!FIX", | |
362 | comment: "Term starting with punctuation preceded..." | |
363 | } | |
364 | } | |
365 | ] | |
366 | }, | |
367 | { | |
368 | code: "//!XXX comment starting with no spaces (anywhere)", | |
369 | options: [{ terms: ["!xxx"], location: "anywhere" }], | |
370 | errors: [ | |
371 | { | |
372 | messageId: "unexpectedComment", | |
373 | data: { | |
374 | matchedTerm: "!xxx", | |
375 | comment: "!XXX comment starting with no spaces..." | |
376 | } | |
377 | } | |
378 | ] | |
379 | }, | |
380 | { | |
381 | code: "//!XXX comment starting with no spaces (start)", | |
382 | options: [{ terms: ["!xxx"], location: "start" }], | |
383 | errors: [ | |
384 | { | |
385 | messageId: "unexpectedComment", | |
386 | data: { | |
387 | matchedTerm: "!xxx", | |
388 | comment: "!XXX comment starting with no spaces..." | |
389 | } | |
390 | } | |
391 | ] | |
392 | }, | |
393 | { | |
394 | code: "/*\nTODO undecorated multi-line block comment (start)\n*/", | |
395 | options: [{ terms: ["todo"], location: "start" }], | |
396 | errors: [ | |
397 | { | |
398 | messageId: "unexpectedComment", | |
399 | data: { | |
400 | matchedTerm: "todo", | |
401 | comment: "TODO undecorated multi-line block..." | |
402 | } | |
403 | } | |
404 | ] | |
405 | }, | |
406 | { | |
407 | code: "///// TODO decorated single-line comment with decoration array \n /////", | |
408 | options: [{ terms: ["todo"], location: "start", decoration: ["*", "/"] }], | |
409 | errors: [ | |
410 | { | |
411 | messageId: "unexpectedComment", | |
412 | data: { | |
413 | matchedTerm: "todo", | |
414 | comment: "/// TODO decorated single-line comment..." | |
415 | } | |
416 | } | |
417 | ] | |
418 | }, | |
419 | { | |
420 | code: "///*/*/ TODO decorated single-line comment with multiple decoration characters (start) \n /////", | |
421 | options: [{ terms: ["todo"], location: "start", decoration: ["*", "/"] }], | |
422 | errors: [ | |
423 | { | |
424 | messageId: "unexpectedComment", | |
425 | data: { | |
426 | matchedTerm: "todo", | |
427 | comment: "/*/*/ TODO decorated single-line comment..." | |
428 | } | |
429 | } | |
430 | ] | |
431 | }, | |
432 | { | |
433 | code: "//**TODO term starts with a decoration character", | |
434 | options: [{ terms: ["*todo"], location: "start", decoration: ["*"] }], | |
435 | errors: [ | |
436 | { | |
437 | messageId: "unexpectedComment", | |
438 | data: { | |
439 | matchedTerm: "*todo", | |
440 | comment: "**TODO term starts with a decoration..." | |
441 | } | |
442 | } | |
443 | ] | |
eb39fafa DC |
444 | } |
445 | ] | |
446 | }); |