]> git.proxmox.com Git - pve-eslint.git/blame - eslint/tests/lib/rules/max-len.js
import 7.12.1 upstream release
[pve-eslint.git] / eslint / tests / lib / rules / max-len.js
CommitLineData
eb39fafa
DC
1/**
2 * @fileoverview Tests for max-len rule.
3 * @author Matt DuVall <http://www.mattduvall.com>
4 */
5
6"use strict";
7
8//------------------------------------------------------------------------------
9// Requirements
10//------------------------------------------------------------------------------
11const rule = require("../../../lib/rules/max-len"),
12 { RuleTester } = require("../../../lib/rule-tester");
13
14//------------------------------------------------------------------------------
15// Tests
16//------------------------------------------------------------------------------
17
18const parserOptions = { ecmaVersion: 6 };
19
20const ruleTester = new RuleTester();
21
22ruleTester.run("max-len", rule, {
23 valid: [
24 "var x = 5;\nvar x = 2;",
25 {
26 code: "var x = 5;\nvar x = 2;",
27 options: [80, 4]
28 }, {
29 code: "\t\t\tvar i = 1;\n\t\t\tvar j = 1;",
30 options: [15, 1]
31 }, {
32 code: "var one\t\t= 1;\nvar three\t= 3;",
33 options: [16, 4]
34 }, {
35 code: "\tvar one\t\t= 1;\n\tvar three\t= 3;",
36 options: [20, 4]
37 }, {
38 code: "var i = 1;\r\nvar i = 1;\n",
39 options: [10, 4]
40 }, {
41 code: "\n// Blank line on top\nvar foo = module.exports = {};\n",
42 options: [80, 4]
43 },
44 "\n// Blank line on top\nvar foo = module.exports = {};\n",
45 {
46 code: "var foo = module.exports = {}; // really long trailing comment",
47 options: [40, 4, { ignoreComments: true }]
48 }, {
49 code: "foo(); \t// strips entire comment *and* trailing whitespace",
50 options: [6, 4, { ignoreComments: true }]
51 }, {
52 code: "// really long comment on its own line sitting here",
53 options: [40, 4, { ignoreComments: true }]
54 }, {
55 code: "var foo = module.exports = {}; /* inline some other comments */ //more",
56 options: [40, 4, { ignoreComments: true }]
57 },
58 "var /*inline-comment*/ i = 1;",
59 {
60 code: "var /*inline-comment*/ i = 1; // with really long trailing comment",
61 options: [40, 4, { ignoreComments: true }]
62 }, {
63 code: "foo('http://example.com/this/is/?a=longish&url=in#here');",
64 options: [40, 4, { ignoreUrls: true }]
65 }, {
66 code: "foo(bar(bazz('this is a long'), 'line of'), 'stuff');",
67 options: [40, 4, { ignorePattern: "foo.+bazz\\(" }]
68 }, {
69 code:
70 "/* hey there! this is a multiline\n" +
71 " comment with longish lines in various places\n" +
72 " but\n" +
73 " with a short line-length */",
74 options: [10, 4, { ignoreComments: true }]
75 }, {
76 code:
77 "// I like short comments\n" +
78 "function butLongSourceLines() { weird(eh()) }",
79 options: [80, { tabWidth: 4, comments: 30 }]
80 }, {
81 code:
82 "// I like longer comments and shorter code\n" +
83 "function see() { odd(eh()) }",
84 options: [30, { tabWidth: 4, comments: 80 }]
85 }, {
86 code:
87 "// Full line comment\n" +
88 "someCode(); // With a long trailing comment.",
89 options: [{ code: 30, tabWidth: 4, comments: 20, ignoreTrailingComments: true }]
90 }, {
91 code: "var foo = module.exports = {}; // really long trailing comment",
92 options: [40, 4, { ignoreTrailingComments: true }]
93 }, {
94 code: "var foo = module.exports = {}; /* inline some other comments */ //more",
95 options: [40, 4, { ignoreTrailingComments: true }]
96 }, {
97 code: "var foo = module.exports = {}; // really long trailing comment",
98 options: [40, 4, { ignoreComments: true, ignoreTrailingComments: false }]
99 },
100
101 // ignoreStrings, ignoreTemplateLiterals and ignoreRegExpLiterals options
102 {
103 code: "var foo = veryLongIdentifier;\nvar bar = 'this is a very long string';",
104 options: [29, 4, { ignoreStrings: true }]
105 },
106 {
107 code: "var foo = veryLongIdentifier;\nvar bar = \"this is a very long string\";",
108 options: [29, 4, { ignoreStrings: true }]
109 },
110 {
111 code: "var str = \"this is a very long string\\\nwith continuation\";",
112 options: [29, 4, { ignoreStrings: true }]
113 },
114 {
115 code: "var str = \"this is a very long string\\\nwith continuation\\\nand with another very very long continuation\\\nand ending\";",
116 options: [29, 4, { ignoreStrings: true }]
117 },
118 {
119 code: "var foo = <div className=\"this is a very long string\"></div>;",
120 options: [29, 4, { ignoreStrings: true }],
121 parserOptions: { ecmaFeatures: { jsx: true } }
122 },
123 {
124 code: "var foo = veryLongIdentifier;\nvar bar = `this is a very long string`;",
125 options: [29, 4, { ignoreTemplateLiterals: true }],
126 parserOptions
127 },
128 {
129 code: "var foo = veryLongIdentifier;\nvar bar = `this is a very long string\nand this is another line that is very long`;",
130 options: [29, 4, { ignoreTemplateLiterals: true }],
131 parserOptions
132 },
133 {
134 code: "var foo = veryLongIdentifier;\nvar bar = `this is a very long string\nand this is another line that is very long\nand here is another\n and another!`;",
135 options: [29, 4, { ignoreTemplateLiterals: true }],
136 parserOptions
137 },
138 {
139 code: "var foo = /this is a very long pattern/;",
140 options: [29, 4, { ignoreRegExpLiterals: true }]
141 },
142
143 // check indented comment lines - https://github.com/eslint/eslint/issues/6322
144 {
145 code: "function foo() {\n" +
146 "//this line has 29 characters\n" +
147 "}",
148 options: [40, 4, { comments: 29 }]
149 }, {
150 code: "function foo() {\n" +
151 " //this line has 33 characters\n" +
152 "}",
153 options: [40, 4, { comments: 33 }]
154 }, {
155 code: "function foo() {\n" +
156 "/*this line has 29 characters\n" +
157 "and this one has 21*/\n" +
158 "}",
159 options: [40, 4, { comments: 29 }]
160 }, {
161 code: "function foo() {\n" +
162 " /*this line has 33 characters\n" +
163 " and this one has 25*/\n" +
164 "}",
165 options: [40, 4, { comments: 33 }]
166 }, {
167 code: "function foo() {\n" +
168 " var a; /*this line has 40 characters\n" +
169 " and this one has 36 characters*/\n" +
170 "}",
171 options: [40, 4, { comments: 36 }]
172 }, {
173 code: "function foo() {\n" +
174 " /*this line has 33 characters\n" +
175 " and this one has 43 characters*/ var a;\n" +
176 "}",
177 options: [43, 4, { comments: 33 }]
178 },
179
180 // blank line
181 "",
182
183 // Multi-code-point unicode glyphs
184 {
185 code: "'🙂😀😆😎😊😜😉👍'",
186 options: [10]
187 },
188
189 // Astral symbols in pattern (only matched by unicode regexes)
190 {
191 code: "var longNameLongName = '𝌆𝌆'",
192 options: [5, { ignorePattern: "𝌆{2}" }]
193 },
194
195 {
196 code: "\tfoo",
197 options: [4, { tabWidth: 0 }]
198 },
199
200 // https://github.com/eslint/eslint/issues/12213
201 {
202 code: "var jsx = (<>\n" +
203 " { /* this line has 38 characters */}\n" +
204 "</>)",
205 options: [15, { comments: 38 }],
206 parserOptions: { ecmaFeatures: { jsx: true } }
207 },
208 {
209 code: "var jsx = (<>\n" +
210 "\t\t{ /* this line has 40 characters */}\n" +
211 "</>)",
212 options: [15, 4, { comments: 44 }],
213 parserOptions: { ecmaFeatures: { jsx: true } }
214 },
215 {
216 code: "var jsx = (<>\n" +
217 " <> text </>{ /* this line has 49 characters */}\n" +
218 "</>)",
219 options: [13, { ignoreComments: true }],
220 parserOptions: { ecmaFeatures: { jsx: true } }
221 },
222 {
223 code: "var jsx = (<>\n" +
224 " {/* this line has 37 characters */}\n" +
225 " <> </> {/* this line has 44 characters */}\n" +
226 "</>)",
227 options: [44, { comments: 37 }],
228 parserOptions: { ecmaFeatures: { jsx: true } }
229 },
230 {
231 code: "var jsx = (<>\n" +
232 " {/* this line has 37 characters */}\n" +
233 " <> </> {/* this line has 44 characters */}\n" +
234 "</>)",
235 options: [37, { ignoreTrailingComments: true }],
236 parserOptions: { ecmaFeatures: { jsx: true } }
237 },
238 {
239 code: "var jsx = <Foo\n" +
240 " attr = {a && b/* this line has 57 characters */}\n" +
241 "></Foo>;",
242 options: [57],
243 parserOptions: { ecmaFeatures: { jsx: true } }
244 },
245 {
246 code: "var jsx = <Foo\n" +
247 " attr = {/* this line has 57 characters */a && b}\n" +
248 "></Foo>;",
249 options: [57],
250 parserOptions: { ecmaFeatures: { jsx: true } }
251 },
252 {
253 code: "var jsx = <Foo\n" +
254 " attr = \n" +
255 " {a & b/* this line has 50 characters */}\n" +
256 "></Foo>;",
257 options: [50],
258 parserOptions: { ecmaFeatures: { jsx: true } }
259 },
260 {
261 code: "var jsx = (<>\n" +
262 " <> </> {/* this line with two separate comments */} {/* have 80 characters */}\n" +
263 "</>)",
264 options: [80],
265 parserOptions: { ecmaFeatures: { jsx: true } }
266 },
267 {
268 code: "var jsx = (<>\n" +
269 " {/* this line has 37 characters */}\n" +
270 " <> </> {/* this line with two separate comments */} {/* have 80 characters */}\n" +
271 "</>)",
272 options: [37, { ignoreTrailingComments: true }],
273 parserOptions: { ecmaFeatures: { jsx: true } }
274 },
275 {
276 code: "var jsx = (<>\n" +
277 " {/* this line has 37 characters */}\n" +
278 " <> </> {/* this line with two separate comments */} {/* have 80 characters */}\n" +
279 "</>)",
280 options: [37, { ignoreComments: true }],
281 parserOptions: { ecmaFeatures: { jsx: true } }
282 },
283 {
284 code: "var jsx = (<>\n" +
285 " {/* this line has 37 characters */}\n" +
286 " <> </> {/* this line with two separate comments */} {/* have > 80 characters */ /* another comment in same braces */}\n" +
287 "</>)",
288 options: [37, { ignoreTrailingComments: true }],
289 parserOptions: { ecmaFeatures: { jsx: true } }
290 },
291 {
292 code: "var jsx = (<>\n" +
293 " {/* this line has 37 characters */}\n" +
294 " <> </> {/* this line with two separate comments */} {/* have > 80 characters */ /* another comment in same braces */}\n" +
295 "</>)",
296 options: [37, { ignoreComments: true }],
297 parserOptions: { ecmaFeatures: { jsx: true } }
298 },
299 {
300 code: "var jsx = (<>\n" +
301 " {/*\n" +
302 " this line has 34 characters\n" +
303 " */}\n" +
304 "</>)",
305 options: [33, { comments: 34 }],
306 parserOptions: { ecmaFeatures: { jsx: true } }
307 },
308 {
309 code: "var jsx = (<>\n" +
310 " {/*\n" +
311 " this line has 34 characters\n" +
312 " */}\n" +
313 "</>)",
314 options: [33, { ignoreComments: true }],
315 parserOptions: { ecmaFeatures: { jsx: true } }
316 },
317 {
318 code: "var jsx = (<>\n" +
319 " {a & b /* this line has 34 characters\n" +
320 " */}\n" +
321 "</>)",
322 options: [33, { ignoreTrailingComments: true }],
323 parserOptions: { ecmaFeatures: { jsx: true } }
324 },
325 {
326 code: "var jsx = (<>\n" +
327 " {a & b /* this line has 34 characters\n" +
328 " */}\n" +
329 "</>)",
330 options: [33, { ignoreComments: true }],
331 parserOptions: { ecmaFeatures: { jsx: true } }
332 }
333 ],
334
335 invalid: [
336 {
337 code: "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tvar i = 1;",
338 errors: [
339 {
340 messageId: "max",
341 data: { lineLength: 86, maxLength: 80 },
342 type: "Program",
343 line: 1,
6f036462
TL
344 column: 1,
345 endLine: 1,
346 endColumn: 30
eb39fafa
DC
347 }
348 ]
349 },
350 {
351 code: "var x = 5, y = 2, z = 5;",
352 options: [10, 4],
353 errors: [
354 {
355 messageId: "max",
356 data: { lineLength: 24, maxLength: 10 },
357 type: "Program",
358 line: 1,
6f036462
TL
359 column: 1,
360 endLine: 1,
361 endColumn: 25
eb39fafa
DC
362 }
363 ]
364 },
365 {
366 code: "\t\t\tvar i = 1;",
367 options: [15, 4],
368 errors: [
369 {
370 messageId: "max",
371 data: { lineLength: 22, maxLength: 15 },
372 type: "Program",
373 line: 1,
6f036462
TL
374 column: 1,
375 endLine: 1,
376 endColumn: 14
eb39fafa
DC
377 }
378 ]
379 },
380 {
381 code: "\t\t\tvar i = 1;\n\t\t\tvar j = 1;",
382 options: [15, 4],
383 errors: [
384 {
385 messageId: "max",
386 data: { lineLength: 22, maxLength: 15 },
387 type: "Program",
388 line: 1,
6f036462
TL
389 column: 1,
390 endLine: 1,
391 endColumn: 14
eb39fafa
DC
392 },
393 {
394 messageId: "max",
395 data: { lineLength: 22, maxLength: 15 },
396 type: "Program",
397 line: 2,
6f036462
TL
398 column: 1,
399 endLine: 2,
400 endColumn: 14
eb39fafa
DC
401 }
402 ]
403 },
404 {
405 code: "var /*this is a long non-removed inline comment*/ i = 1;",
406 options: [20, 4, { ignoreComments: true }],
407 errors: [
408 {
409 messageId: "max",
410 data: { lineLength: 56, maxLength: 20 },
411 type: "Program",
412 line: 1,
6f036462
TL
413 column: 1,
414 endLine: 1,
415 endColumn: 57
eb39fafa
DC
416 }
417 ]
418 },
419 {
420 code:
421 "var foobar = 'this line isn\\'t matched by the regexp';\n" +
422 "var fizzbuzz = 'but this one is matched by the regexp';\n",
423 options: [20, 4, { ignorePattern: "fizzbuzz" }],
424 errors: [
425 {
426 messageId: "max",
427 data: { lineLength: 54, maxLength: 20 },
428 type: "Program",
429 line: 1,
6f036462
TL
430 column: 1,
431 endLine: 1,
432 endColumn: 55
eb39fafa
DC
433 }
434 ]
435 },
436 {
437 code: "var longLine = 'will trigger'; // even with a comment",
438 options: [10, 4, { ignoreComments: true }],
439 errors: [
440 {
441 messageId: "max",
442 data: { lineLength: 30, maxLength: 10 },
443 type: "Program",
444 line: 1,
6f036462
TL
445 column: 1,
446 endLine: 1,
447 endColumn: 31
eb39fafa
DC
448 }
449 ]
450 },
451 {
452 code: "var foo = module.exports = {}; // really long trailing comment",
453 options: [40, 4], // ignoreComments is disabled
454 errors: [
455 {
456 messageId: "max",
457 data: { lineLength: 62, maxLength: 40 },
458 type: "Program",
459 line: 1,
6f036462
TL
460 column: 1,
461 endLine: 1,
462 endColumn: 63
eb39fafa
DC
463 }
464 ]
465 },
466 {
467 code: "foo('http://example.com/this/is/?a=longish&url=in#here');",
468 options: [40, 4], // ignoreUrls is disabled
469 errors: [
470 {
471 messageId: "max",
472 data: { lineLength: 57, maxLength: 40 },
473 type: "Program",
474 line: 1,
6f036462
TL
475 column: 1,
476 endLine: 1,
477 endColumn: 58
eb39fafa
DC
478 }
479 ]
480 }, {
481 code: "foo(bar(bazz('this is a long'), 'line of'), 'stuff');",
482 options: [40, 4], // ignorePattern is disabled
483 errors: [
484 {
485 messageId: "max",
486 data: { lineLength: 53, maxLength: 40 },
487 type: "Program",
488 line: 1,
6f036462
TL
489 column: 1,
490 endLine: 1,
491 endColumn: 54
eb39fafa
DC
492 }
493 ]
494 }, {
495 code: "// A comment that exceeds the max comment length.",
496 options: [80, 4, { comments: 20 }],
497 errors: [
498 {
499 messageId: "maxComment",
500 data: { lineLength: 49, maxCommentLength: 20 },
501 type: "Program",
502 line: 1,
6f036462
TL
503 column: 1,
504 endLine: 1,
505 endColumn: 50
eb39fafa
DC
506 }
507 ]
508 }, {
509 code: "// A comment that exceeds the max comment length and the max code length, but will fail for being too long of a comment",
510 options: [40, 4, { comments: 80 }],
511 errors: [
512 {
513 messageId: "maxComment",
514 data: { lineLength: 119, maxCommentLength: 80 },
515 type: "Program",
516 line: 1,
6f036462
TL
517 column: 1,
518 endLine: 1,
519 endColumn: 120
eb39fafa
DC
520 }
521 ]
522 }, {
523 code: "// A comment that exceeds the max comment length.",
524 options: [{ code: 20 }],
525 errors: [
526 {
527 messageId: "max",
528 data: { lineLength: 49, maxLength: 20 },
529 type: "Program",
530 line: 1,
6f036462
TL
531 column: 1,
532 endLine: 1,
533 endColumn: 50
eb39fafa
DC
534 }
535 ]
536 }, {
537 code: "//This is very long comment with more than 40 characters which is invalid",
538 options: [40, 4, { ignoreTrailingComments: true }],
539 errors: [
540 {
541 messageId: "max",
542 data: { lineLength: 73, maxLength: 40 },
543 type: "Program",
544 line: 1,
6f036462
TL
545 column: 1,
546 endLine: 1,
547 endColumn: 74
eb39fafa
DC
548 }
549 ]
550 },
551
552 // check indented comment lines - https://github.com/eslint/eslint/issues/6322
553 {
554 code: "function foo() {\n" +
555 "//this line has 29 characters\n" +
556 "}",
557 options: [40, 4, { comments: 28 }],
558 errors: [
559 {
560 messageId: "maxComment",
561 data: { lineLength: 29, maxCommentLength: 28 },
562 type: "Program",
563 line: 2,
6f036462
TL
564 column: 1,
565 endLine: 2,
566 endColumn: 30
eb39fafa
DC
567 }
568 ]
569 }, {
570 code: "function foo() {\n" +
571 " //this line has 33 characters\n" +
572 "}",
573 options: [40, 4, { comments: 32 }],
574 errors: [
575 {
576 messageId: "maxComment",
577 data: { lineLength: 33, maxCommentLength: 32 },
578 type: "Program",
579 line: 2,
6f036462
TL
580 column: 1,
581 endLine: 2,
582 endColumn: 34
eb39fafa
DC
583 }
584 ]
585 }, {
586 code: "function foo() {\n" +
587 "/*this line has 29 characters\n" +
588 "and this one has 32 characters*/\n" +
589 "}",
590 options: [40, 4, { comments: 28 }],
591 errors: [
592 {
593 messageId: "maxComment",
594 data: { lineLength: 29, maxCommentLength: 28 },
595 type: "Program",
596 line: 2,
6f036462
TL
597 column: 1,
598 endLine: 2,
599 endColumn: 30
eb39fafa
DC
600 },
601 {
602 messageId: "maxComment",
603 data: { lineLength: 32, maxCommentLength: 28 },
604 type: "Program",
605 line: 3,
6f036462
TL
606 column: 1,
607 endLine: 3,
608 endColumn: 33
eb39fafa
DC
609 }
610 ]
611 }, {
612 code: "function foo() {\n" +
613 " /*this line has 33 characters\n" +
614 " and this one has 36 characters*/\n" +
615 "}",
616 options: [40, 4, { comments: 32 }],
617 errors: [
618 {
619 messageId: "maxComment",
620 data: { lineLength: 33, maxCommentLength: 32 },
621 type: "Program",
622 line: 2,
6f036462
TL
623 column: 1,
624 endLine: 2,
625 endColumn: 34
eb39fafa
DC
626 },
627 {
628 messageId: "maxComment",
629 data: { lineLength: 36, maxCommentLength: 32 },
630 type: "Program",
631 line: 3,
6f036462
TL
632 column: 1,
633 endLine: 3,
634 endColumn: 37
eb39fafa
DC
635 }
636 ]
637 }, {
638 code: "function foo() {\n" +
639 " var a; /*this line has 40 characters\n" +
640 " and this one has 36 characters*/\n" +
641 "}",
642 options: [39, 4, { comments: 35 }],
643 errors: [
644 {
645 messageId: "max",
646 data: { lineLength: 40, maxLength: 39 },
647 type: "Program",
648 line: 2,
6f036462
TL
649 column: 1,
650 endLine: 2,
651 endColumn: 41
eb39fafa
DC
652 },
653 {
654 messageId: "maxComment",
655 data: { lineLength: 36, maxCommentLength: 35 },
656 type: "Program",
657 line: 3,
6f036462
TL
658 column: 1,
659 endLine: 3,
660 endColumn: 37
eb39fafa
DC
661 }
662 ]
663 }, {
664 code: "function foo() {\n" +
665 " /*this line has 33 characters\n" +
666 " and this one has 43 characters*/ var a;\n" +
667 "}",
668 options: [42, 4, { comments: 32 }],
669 errors: [
670 {
671 messageId: "maxComment",
672 data: { lineLength: 33, maxCommentLength: 32 },
673 type: "Program",
674 line: 2,
6f036462
TL
675 column: 1,
676 endLine: 2,
677 endColumn: 34
eb39fafa
DC
678 },
679 {
680 messageId: "max",
681 data: { lineLength: 43, maxLength: 42 },
682 type: "Program",
683 line: 3,
6f036462
TL
684 column: 1,
685 endLine: 3,
686 endColumn: 44
eb39fafa
DC
687 }
688 ]
689 },
690
691 // check comments with the same length as non-comments - https://github.com/eslint/eslint/issues/6564
692 {
693 code: "// This commented line has precisely 51 characters.\n" +
694 "var x = 'This line also has exactly 51 characters';",
695 options: [20, { ignoreComments: true }],
696 errors: [
697 {
698 messageId: "max",
699 data: { lineLength: 51, maxLength: 20 },
700 type: "Program",
701 line: 2,
6f036462
TL
702 column: 1,
703 endLine: 2,
704 endColumn: 52
eb39fafa
DC
705 }
706 ]
707 },
708
709 // ignoreStrings and ignoreTemplateLiterals options
710 {
711 code: "var foo = veryLongIdentifier;\nvar bar = 'this is a very long string';",
712 options: [29, { ignoreStrings: false, ignoreTemplateLiterals: true }],
713 errors: [
714 {
715 messageId: "max",
716 data: { lineLength: 39, maxLength: 29 },
717 type: "Program",
718 line: 2,
6f036462
TL
719 column: 1,
720 endLine: 2,
721 endColumn: 40
eb39fafa
DC
722 }
723 ]
724 },
725 {
726 code: "var foo = veryLongIdentifier;\nvar bar = /this is a very very long pattern/;",
727 options: [29, { ignoreStrings: false, ignoreRegExpLiterals: false }],
728 errors: [
729 {
730 messageId: "max",
731 data: { lineLength: 45, maxLength: 29 },
732 type: "Program",
733 line: 2,
6f036462
TL
734 column: 1,
735 endLine: 2,
736 endColumn: 46
eb39fafa
DC
737 }
738 ]
739 },
740 {
741 code: "var foo = veryLongIdentifier;\nvar bar = new RegExp('this is a very very long pattern');",
742 options: [29, { ignoreStrings: false, ignoreRegExpLiterals: true }],
743 errors: [
744 {
745 messageId: "max",
746 data: { lineLength: 57, maxLength: 29 },
747 type: "Program",
748 line: 2,
6f036462
TL
749 column: 1,
750 endLine: 2,
751 endColumn: 58
eb39fafa
DC
752 }
753 ]
754 },
755 {
756 code: "var foo = veryLongIdentifier;\nvar bar = \"this is a very long string\";",
757 options: [29, { ignoreStrings: false, ignoreTemplateLiterals: true }],
758 errors: [
759 {
760 messageId: "max",
761 data: { lineLength: 39, maxLength: 29 },
762 type: "Program",
763 line: 2,
6f036462
TL
764 column: 1,
765 endLine: 2,
766 endColumn: 40
eb39fafa
DC
767 }
768 ]
769 },
770 {
771 code: "var foo = veryLongIdentifier;\nvar bar = `this is a very long string`;",
772 options: [29, { ignoreStrings: false, ignoreTemplateLiterals: false }],
773 parserOptions,
774 errors: [
775 {
776 messageId: "max",
777 data: { lineLength: 39, maxLength: 29 },
778 type: "Program",
779 line: 2,
6f036462
TL
780 column: 1,
781 endLine: 2,
782 endColumn: 40
eb39fafa
DC
783 }
784 ]
785 },
786 {
787 code: "var foo = veryLongIdentifier;\nvar bar = `this is a very long string\nand this is another line that is very long`;",
788 options: [29, { ignoreStrings: false, ignoreTemplateLiterals: false }],
789 parserOptions,
790 errors: [
791 {
792 messageId: "max",
793 data: { lineLength: 37, maxLength: 29 },
794 type: "Program",
795 line: 2,
6f036462
TL
796 column: 1,
797 endLine: 2,
798 endColumn: 38
eb39fafa
DC
799 },
800 {
801 messageId: "max",
802 data: { lineLength: 44, maxLength: 29 },
803 type: "Program",
804 line: 3,
6f036462
TL
805 column: 1,
806 endLine: 3,
807 endColumn: 45
eb39fafa
DC
808 }
809 ]
810 },
811 {
812 code: "var foo = <div>this is a very very very long string</div>;",
813 options: [29, 4, { ignoreStrings: true }],
814 parserOptions: { ecmaFeatures: { jsx: true } },
815 errors: [
816 {
817 messageId: "max",
818 data: { lineLength: 58, maxLength: 29 },
819 type: "Program",
820 line: 1,
6f036462
TL
821 column: 1,
822 endLine: 1,
823 endColumn: 59
eb39fafa
DC
824 }
825 ]
826 },
827
828 // Multi-code-point unicode glyphs
829 {
830 code: "'🙁😁😟☹️😣😖😩😱👎'",
831 options: [10],
832 errors: [
833 {
834 messageId: "max",
835 data: { lineLength: 12, maxLength: 10 },
836 type: "Program",
837 line: 1,
6f036462
TL
838 column: 1,
839 endLine: 1,
840 endColumn: 21
eb39fafa
DC
841 }
842 ]
843 },
844
845 {
846 code: "a",
847 options: [0],
848 errors: [
849 {
850 messageId: "max",
851 data: { lineLength: 1, maxLength: 0 },
852 type: "Program",
853 line: 1,
6f036462
TL
854 column: 1,
855 endLine: 1,
856 endColumn: 2
eb39fafa
DC
857 }
858 ]
859 },
860
861 // https://github.com/eslint/eslint/issues/12213
862 {
863 code: "var jsx = (<>\n" +
864 " { /* this line has 38 characters */}\n" +
865 "</>)",
866 options: [15, { comments: 37 }],
867 parserOptions: { ecmaFeatures: { jsx: true } },
868 errors: [
869 {
870 messageId: "maxComment",
871 data: { lineLength: 38, maxCommentLength: 37 },
872 type: "Program",
873 line: 2,
6f036462
TL
874 column: 1,
875 endLine: 2,
876 endColumn: 39
eb39fafa
DC
877 }
878 ]
879 },
880 {
881 code: "var jsx = (<>\n" +
882 "\t\t{ /* this line has 40 characters */}\n" +
883 "</>)",
884 options: [15, 4, { comments: 40 }],
885 parserOptions: { ecmaFeatures: { jsx: true } },
886 errors: [
887 {
888 messageId: "maxComment",
889 data: { lineLength: 44, maxCommentLength: 40 },
890 type: "Program",
891 line: 2,
6f036462
TL
892 column: 1,
893 endLine: 2,
894 endColumn: 39
eb39fafa
DC
895 }
896 ]
897 },
898 {
899 code: "var jsx = (<>\n" +
900 "{ 38/* this line has 38 characters */}\n" +
901 "</>)",
902 options: [15, { comments: 38 }],
903 parserOptions: { ecmaFeatures: { jsx: true } },
904 errors: [
905 {
906 messageId: "max",
907 data: { lineLength: 38, maxLength: 15 },
908 type: "Program",
909 line: 2,
6f036462
TL
910 column: 1,
911 endLine: 2,
912 endColumn: 39
eb39fafa
DC
913 }
914 ]
915 },
916 {
917 code: "var jsx = (<>\n" +
918 "{ 38/* this line has 38 characters */}\n" +
919 "</>)",
920 options: [37, { ignoreTrailingComments: true }],
921 parserOptions: { ecmaFeatures: { jsx: true } },
922 errors: [
923 {
924 messageId: "max",
925 data: { lineLength: 38, maxLength: 37 },
926 type: "Program",
927 line: 2,
6f036462
TL
928 column: 1,
929 endLine: 2,
930 endColumn: 39
eb39fafa
DC
931 }
932 ]
933 },
934 {
935 code: "var jsx = (<>\n" +
936 "{ 38/* this line has 38 characters */}\n" +
937 "</>)",
938 options: [37, { ignoreComments: true }],
939 parserOptions: { ecmaFeatures: { jsx: true } },
940 errors: [
941 {
942 messageId: "max",
943 data: { lineLength: 38, maxLength: 37 },
944 type: "Program",
945 line: 2,
6f036462
TL
946 column: 1,
947 endLine: 2,
948 endColumn: 39
eb39fafa
DC
949 }
950 ]
951 },
952 {
953 code: "var jsx = (<>\n" +
954 " <> 50 </>{ 50/* this line has 50 characters */}\n" +
955 "</>)",
956 options: [49, { comments: 100 }],
957 parserOptions: { ecmaFeatures: { jsx: true } },
958 errors: [
959 {
960 messageId: "max",
961 data: { lineLength: 50, maxLength: 49 },
962 type: "Program",
963 line: 2,
6f036462
TL
964 column: 1,
965 endLine: 2,
966 endColumn: 51
eb39fafa
DC
967 }
968 ]
969 },
970 {
971 code: "var jsx = (<>\n" +
972 " {/* this line has 44 characters */}\n" +
973 " <> </> {/* this line has 44 characters */}\n" +
974 "</>)",
975 options: [37, { ignoreTrailingComments: true }],
976 parserOptions: { ecmaFeatures: { jsx: true } },
977 errors: [
978 {
979 messageId: "max",
980 data: { lineLength: 44, maxLength: 37 },
981 type: "Program",
982 line: 2,
6f036462
TL
983 column: 1,
984 endLine: 2,
985 endColumn: 45
eb39fafa
DC
986 }
987 ]
988 },
989 {
990 code: "var jsx = <Foo\n" +
991 " attr = {a && b/* this line has 57 characters */}\n" +
992 "></Foo>;",
993 options: [56],
994 parserOptions: { ecmaFeatures: { jsx: true } },
995 errors: [
996 {
997 messageId: "max",
998 data: { lineLength: 57, maxLength: 56 },
999 type: "Program",
1000 line: 2,
6f036462
TL
1001 column: 1,
1002 endLine: 2,
1003 endColumn: 58
eb39fafa
DC
1004 }
1005 ]
1006 },
1007 {
1008 code: "var jsx = <Foo\n" +
1009 " attr = {/* this line has 57 characters */a && b}\n" +
1010 "></Foo>;",
1011 options: [56],
1012 parserOptions: { ecmaFeatures: { jsx: true } },
1013 errors: [
1014 {
1015 messageId: "max",
1016 data: { lineLength: 57, maxLength: 56 },
1017 type: "Program",
1018 line: 2,
6f036462
TL
1019 column: 1,
1020 endLine: 2,
1021 endColumn: 58
eb39fafa
DC
1022 }
1023 ]
1024 },
1025 {
1026 code: "var jsx = <Foo\n" +
1027 " attr = {a & b/* this line has 56 characters */}\n" +
1028 "></Foo>;",
1029 options: [55, { ignoreTrailingComments: true }],
1030 parserOptions: { ecmaFeatures: { jsx: true } },
1031 errors: [
1032 {
1033 messageId: "max",
1034 data: { lineLength: 56, maxLength: 55 },
1035 type: "Program",
1036 line: 2,
6f036462
TL
1037 column: 1,
1038 endLine: 2,
1039 endColumn: 57
eb39fafa
DC
1040 }
1041 ]
1042 },
1043 {
1044 code: "var jsx = <Foo\n" +
1045 " attr = \n" +
1046 " {a & b /* this line has 51 characters */}\n" +
1047 "></Foo>;",
1048 options: [30, { comments: 44 }],
1049 parserOptions: { ecmaFeatures: { jsx: true } },
1050 errors: [
1051 {
1052 messageId: "max",
1053 data: { lineLength: 51, maxLength: 30 },
1054 type: "Program",
1055 line: 3,
6f036462
TL
1056 column: 1,
1057 endLine: 3,
1058 endColumn: 52
eb39fafa
DC
1059 }
1060 ]
1061 },
1062 {
1063 code: "var jsx = (<>\n" +
1064 " {/* this line has 37 characters */}\n" +
1065 " <> </> {/* this line with two separate comments */} {/* have 80 characters */}\n" +
1066 "</>)",
1067 options: [79],
1068 parserOptions: { ecmaFeatures: { jsx: true } },
1069 errors: [
1070 {
1071 messageId: "max",
1072 data: { lineLength: 80, maxLength: 79 },
1073 type: "Program",
1074 line: 3,
6f036462
TL
1075 column: 1,
1076 endLine: 3,
1077 endColumn: 81
eb39fafa
DC
1078 }
1079 ]
1080 },
1081 {
1082 code: "var jsx = (<>\n" +
1083 " <> </> {/* this line with two separate comments */} {/* have 87 characters */} <> </>\n" +
1084 "</>)",
1085 options: [85, { ignoreTrailingComments: true }],
1086 parserOptions: { ecmaFeatures: { jsx: true } },
1087 errors: [
1088 {
1089 messageId: "max",
1090 data: { lineLength: 87, maxLength: 85 },
1091 type: "Program",
1092 line: 2,
6f036462
TL
1093 column: 1,
1094 endLine: 2,
1095 endColumn: 88
eb39fafa
DC
1096 }
1097 ]
1098 },
1099 {
1100 code: "var jsx = (<>\n" +
1101 " {/* this line has 37 characters */}\n" +
1102 " <> </> {/* this line with two separate comments */} {/* have 87 characters */} <> </>\n" +
1103 "</>)",
1104 options: [37, { ignoreComments: true }],
1105 parserOptions: { ecmaFeatures: { jsx: true } },
1106 errors: [
1107 {
1108 messageId: "max",
1109 data: { lineLength: 87, maxLength: 37 },
1110 type: "Program",
1111 line: 3,
6f036462
TL
1112 column: 1,
1113 endLine: 3,
1114 endColumn: 88
eb39fafa
DC
1115 }
1116 ]
1117 },
1118 {
1119 code: "var jsx = (<>\n" +
1120 " {/* this line has 37 characters */}\n" +
1121 " <> </> {/* this line with two separate comments */} {/* have > 80 characters */ /* another comment in same braces */}\n" +
1122 "</>)",
1123 options: [37],
1124 parserOptions: { ecmaFeatures: { jsx: true } },
1125 errors: [
1126 {
1127 messageId: "max",
1128 data: { lineLength: 119, maxLength: 37 },
1129 type: "Program",
1130 line: 3,
6f036462
TL
1131 column: 1,
1132 endLine: 3,
1133 endColumn: 120
eb39fafa
DC
1134 }
1135 ]
1136 },
1137 {
1138 code: "var jsx = (<>\n" +
1139 " {/* this line has 37 characters */}\n" +
1140 " <> </> {/* this is not treated as a comment */ a & b} {/* trailing */ /* comments */}\n" +
1141 "</>)",
1142 options: [37, { ignoreTrailingComments: true }],
1143 parserOptions: { ecmaFeatures: { jsx: true } },
1144 errors: [
1145 {
1146 messageId: "max",
1147 data: { lineLength: 55, maxLength: 37 },
1148 type: "Program",
1149 line: 3,
6f036462
TL
1150 column: 1,
1151 endLine: 3,
1152 endColumn: 56
eb39fafa
DC
1153 }
1154 ]
1155 },
1156 {
1157 code: "var jsx = (<>\n" +
1158 " {/* this line has 37 characters */}\n" +
1159 " <> </> {/* this is not treated as a comment */ a & b} {/* trailing */ /* comments */}\n" +
1160 "</>)",
1161 options: [37, { ignoreComments: true }],
1162 parserOptions: { ecmaFeatures: { jsx: true } },
1163 errors: [
1164 {
1165 messageId: "max",
1166 data: { lineLength: 55, maxLength: 37 },
1167 type: "Program",
1168 line: 3,
6f036462
TL
1169 column: 1,
1170 endLine: 3,
1171 endColumn: 56
eb39fafa
DC
1172 }
1173 ]
1174 },
1175 {
1176 code: "var jsx = (<>\n" +
1177 "12345678901234{/*\n" +
1178 "*/}\n" +
1179 "</>)",
1180 options: [14, { ignoreTrailingComments: true }],
1181 parserOptions: { ecmaFeatures: { jsx: true } },
1182 errors: [
1183 {
1184 messageId: "max",
1185 data: { lineLength: 15, maxLength: 14 },
1186 type: "Program",
1187 line: 2,
6f036462
TL
1188 column: 1,
1189 endLine: 2,
1190 endColumn: 16
eb39fafa
DC
1191 }
1192 ]
1193 },
1194 {
1195 code: "var jsx = (<>\n" +
1196 "{/*\n" +
1197 "this line has 31 characters */}\n" +
1198 "</>)",
1199 options: [30, { comments: 100 }],
1200 parserOptions: { ecmaFeatures: { jsx: true } },
1201 errors: [
1202 {
1203 messageId: "max",
1204 data: { lineLength: 31, maxLength: 30 },
1205 type: "Program",
1206 line: 3,
6f036462
TL
1207 column: 1,
1208 endLine: 3,
1209 endColumn: 32
eb39fafa
DC
1210 }
1211 ]
1212 }
1213 ]
1214});