]>
Commit | Line | Data |
---|---|---|
eb39fafa DC |
1 | /** |
2 | * @fileoverview Tests for id-length rule. | |
3 | * @author Burak Yigit Kaya | |
4 | */ | |
5 | ||
6 | "use strict"; | |
7 | ||
8 | //------------------------------------------------------------------------------ | |
9 | // Requirements | |
10 | //------------------------------------------------------------------------------ | |
11 | ||
12 | const rule = require("../../../lib/rules/id-length"), | |
13 | { RuleTester } = require("../../../lib/rule-tester"); | |
14 | ||
15 | //------------------------------------------------------------------------------ | |
16 | // Tests | |
17 | //------------------------------------------------------------------------------ | |
18 | ||
19 | const ruleTester = new RuleTester(); | |
20 | const tooShortError = { messageId: "tooShort", type: "Identifier" }; | |
609c276f | 21 | const tooShortErrorPrivate = { messageId: "tooShortPrivate", type: "PrivateIdentifier" }; |
eb39fafa | 22 | const tooLongError = { messageId: "tooLong", type: "Identifier" }; |
609c276f | 23 | const tooLongErrorPrivate = { messageId: "tooLongPrivate", type: "PrivateIdentifier" }; |
eb39fafa DC |
24 | |
25 | ruleTester.run("id-length", rule, { | |
26 | valid: [ | |
27 | "var xyz;", | |
28 | "var xy = 1;", | |
29 | "function xyz() {};", | |
30 | "function xyz(abc, de) {};", | |
31 | "var obj = { abc: 1, de: 2 };", | |
32 | "var obj = { 'a': 1, bc: 2 };", | |
33 | "var obj = {}; obj['a'] = 2;", | |
34 | "abc = d;", | |
35 | "try { blah(); } catch (err) { /* pass */ }", | |
36 | "var handler = function ($e) {};", | |
37 | "var _a = 2", | |
38 | "var _ad$$ = new $;", | |
39 | "var xyz = new ΣΣ();", | |
40 | "unrelatedExpressionThatNeedsToBeIgnored();", | |
41 | "var obj = { 'a': 1, bc: 2 }; obj.tk = obj.a;", | |
42 | "var query = location.query.q || '';", | |
43 | "var query = location.query.q ? location.query.q : ''", | |
44 | { code: "let {a: foo} = bar;", parserOptions: { ecmaVersion: 6 } }, | |
45 | { code: "let foo = { [a]: 1 };", parserOptions: { ecmaVersion: 6 } }, | |
46 | { code: "let foo = { [a + b]: 1 };", parserOptions: { ecmaVersion: 6 } }, | |
47 | { code: "var x = Foo(42)", options: [{ min: 1 }] }, | |
48 | { code: "var x = Foo(42)", options: [{ min: 0 }] }, | |
49 | { code: "foo.$x = Foo(42)", options: [{ min: 1 }] }, | |
50 | { code: "var lalala = Foo(42)", options: [{ max: 6 }] }, | |
51 | { code: "for (var q, h=0; h < 10; h++) { console.log(h); q++; }", options: [{ exceptions: ["h", "q"] }] }, | |
52 | { code: "(num) => { num * num };", parserOptions: { ecmaVersion: 6 } }, | |
53 | { code: "function foo(num = 0) { }", parserOptions: { ecmaVersion: 6 } }, | |
54 | { code: "class MyClass { }", parserOptions: { ecmaVersion: 6 } }, | |
55 | { code: "class Foo { method() {} }", parserOptions: { ecmaVersion: 6 } }, | |
56 | { code: "function foo(...args) { }", parserOptions: { ecmaVersion: 6 } }, | |
57 | { code: "var { prop } = {};", parserOptions: { ecmaVersion: 6 } }, | |
58 | { code: "var { [a]: prop } = {};", parserOptions: { ecmaVersion: 6 } }, | |
59 | { code: "var { a: foo } = {};", options: [{ min: 3 }], parserOptions: { ecmaVersion: 6 } }, | |
60 | { code: "var { prop: foo } = {};", options: [{ max: 3 }], parserOptions: { ecmaVersion: 6 } }, | |
61 | { code: "var { longName: foo } = {};", options: [{ min: 3, max: 5 }], parserOptions: { ecmaVersion: 6 } }, | |
62 | { code: "var { foo: a } = {};", options: [{ exceptions: ["a"] }], parserOptions: { ecmaVersion: 6 } }, | |
63 | { code: "var { a: { b: { c: longName } } } = {};", parserOptions: { ecmaVersion: 6 } }, | |
64 | { code: "({ a: obj.x.y.z } = {});", options: [{ properties: "never" }], parserOptions: { ecmaVersion: 6 } }, | |
65 | { code: "import something from 'y';", parserOptions: { ecmaVersion: 6, sourceType: "module" } }, | |
66 | { code: "export var num = 0;", parserOptions: { ecmaVersion: 6, sourceType: "module" } }, | |
67 | { code: "({ prop: obj.x.y.something } = {});", parserOptions: { ecmaVersion: 6 } }, | |
68 | { code: "({ prop: obj.longName } = {});", parserOptions: { ecmaVersion: 6 } }, | |
69 | { code: "var obj = { a: 1, bc: 2 };", options: [{ properties: "never" }] }, | |
70 | { code: "var obj = { [a]: 2 };", options: [{ properties: "never" }], parserOptions: { ecmaVersion: 6 } }, | |
71 | { code: "var obj = {}; obj.a = 1; obj.bc = 2;", options: [{ properties: "never" }] }, | |
72 | { code: "({ prop: obj.x } = {});", options: [{ properties: "never" }], parserOptions: { ecmaVersion: 6 } }, | |
73 | { code: "var obj = { aaaaa: 1 };", options: [{ max: 4, properties: "never" }] }, | |
74 | { code: "var obj = {}; obj.aaaaa = 1;", options: [{ max: 4, properties: "never" }] }, | |
75 | { code: "({ a: obj.x.y.z } = {});", options: [{ max: 4, properties: "never" }], parserOptions: { ecmaVersion: 6 } }, | |
76 | { code: "({ prop: obj.xxxxx } = {});", options: [{ max: 4, properties: "never" }], parserOptions: { ecmaVersion: 6 } }, | |
77 | { code: "var arr = [i,j,f,b]", parserOptions: { ecmaVersion: 6 } }, | |
78 | { code: "function foo([arr]) {}", parserOptions: { ecmaVersion: 6 } }, | |
79 | { code: "var {x} = foo;", options: [{ properties: "never" }], parserOptions: { ecmaVersion: 6 } }, | |
80 | { code: "var {x, y: {z}} = foo;", options: [{ properties: "never" }], parserOptions: { ecmaVersion: 6 } }, | |
81 | { code: "let foo = { [a]: 1 };", options: [{ properties: "always" }], parserOptions: { ecmaVersion: 6 } }, | |
6f036462 TL |
82 | { code: "let foo = { [a + b]: 1 };", options: [{ properties: "always" }], parserOptions: { ecmaVersion: 6 } }, |
83 | { code: "function BEFORE_send() {};", options: [{ min: 3, max: 5, exceptionPatterns: ["^BEFORE_"] }] }, | |
84 | { code: "function BEFORE_send() {};", options: [{ min: 3, max: 5, exceptionPatterns: ["^BEFORE_", "send$"] }] }, | |
85 | { code: "function BEFORE_send() {};", options: [{ min: 3, max: 5, exceptionPatterns: ["^BEFORE_", "^A", "^Z"] }] }, | |
86 | { code: "function BEFORE_send() {};", options: [{ min: 3, max: 5, exceptionPatterns: ["^A", "^BEFORE_", "^Z"] }] }, | |
609c276f TL |
87 | { code: "var x = 1 ;", options: [{ min: 3, max: 5, exceptionPatterns: ["[x-z]"] }] }, |
88 | ||
89 | // Class Fields | |
90 | { | |
91 | code: "class Foo { #xyz() {} }", | |
92 | parserOptions: { ecmaVersion: 2022 } | |
93 | }, | |
94 | { | |
95 | code: "class Foo { xyz = 1 }", | |
96 | parserOptions: { ecmaVersion: 2022 } | |
97 | }, | |
98 | { | |
99 | code: "class Foo { #xyz = 1 }", | |
100 | parserOptions: { ecmaVersion: 2022 } | |
101 | }, | |
102 | { | |
103 | code: "class Foo { #abc() {} }", | |
104 | options: [{ max: 3 }], | |
105 | parserOptions: { ecmaVersion: 2022 } | |
106 | }, | |
107 | { | |
108 | code: "class Foo { abc = 1 }", | |
109 | options: [{ max: 3 }], | |
110 | parserOptions: { ecmaVersion: 2022 } | |
111 | }, | |
112 | { | |
113 | code: "class Foo { #abc = 1 }", | |
114 | options: [{ max: 3 }], | |
115 | parserOptions: { ecmaVersion: 2022 } | |
f2a92ac6 DC |
116 | }, |
117 | ||
118 | // Identifier consisting of two code units | |
119 | { | |
120 | code: "var 𠮟 = 2", | |
121 | options: [{ min: 1, max: 1 }], | |
122 | parserOptions: { ecmaVersion: 6 } | |
123 | }, | |
124 | { | |
125 | code: "var 葛󠄀 = 2", // 2 code points but only 1 grapheme | |
126 | options: [{ min: 1, max: 1 }], | |
127 | parserOptions: { ecmaVersion: 6 } | |
128 | }, | |
129 | { | |
130 | code: "var a = { 𐌘: 1 };", | |
131 | options: [{ min: 1, max: 1 }], | |
132 | parserOptions: { | |
133 | ecmaVersion: 6 | |
134 | } | |
135 | }, | |
136 | { | |
137 | code: "(𐌘) => { 𐌘 * 𐌘 };", | |
138 | options: [{ min: 1, max: 1 }], | |
139 | parserOptions: { | |
140 | ecmaVersion: 6 | |
141 | } | |
142 | }, | |
143 | { | |
144 | code: "class 𠮟 { }", | |
145 | options: [{ min: 1, max: 1 }], | |
146 | parserOptions: { | |
147 | ecmaVersion: 6 | |
148 | } | |
149 | }, | |
150 | { | |
151 | code: "class F { 𐌘() {} }", | |
152 | options: [{ min: 1, max: 1 }], | |
153 | parserOptions: { | |
154 | ecmaVersion: 6 | |
155 | } | |
156 | }, | |
157 | { | |
158 | code: "class F { #𐌘() {} }", | |
159 | options: [{ min: 1, max: 1 }], | |
160 | parserOptions: { | |
161 | ecmaVersion: 2022 | |
162 | } | |
163 | }, | |
164 | { | |
165 | code: "class F { 𐌘 = 1 }", | |
166 | options: [{ min: 1, max: 1 }], | |
167 | parserOptions: { | |
168 | ecmaVersion: 2022 | |
169 | } | |
170 | }, | |
171 | { | |
172 | code: "class F { #𐌘 = 1 }", | |
173 | options: [{ min: 1, max: 1 }], | |
174 | parserOptions: { | |
175 | ecmaVersion: 2022 | |
176 | } | |
177 | }, | |
178 | { | |
179 | code: "function f(...𐌘) { }", | |
180 | options: [{ min: 1, max: 1 }], | |
181 | parserOptions: { | |
182 | ecmaVersion: 6 | |
183 | } | |
184 | }, | |
185 | { | |
186 | code: "function f([𐌘]) { }", | |
187 | options: [{ min: 1, max: 1 }], | |
188 | parserOptions: { | |
189 | ecmaVersion: 6 | |
190 | } | |
191 | }, | |
192 | { | |
193 | code: "var [ 𐌘 ] = a;", | |
194 | options: [{ min: 1, max: 1 }], | |
195 | parserOptions: { | |
196 | ecmaVersion: 6 | |
197 | } | |
198 | }, | |
199 | { | |
200 | code: "var { p: [𐌘]} = {};", | |
201 | options: [{ min: 1, max: 1 }], | |
202 | parserOptions: { | |
203 | ecmaVersion: 6 | |
204 | } | |
205 | }, | |
206 | { | |
207 | code: "function f({𐌘}) { }", | |
208 | options: [{ min: 1, max: 1 }], | |
209 | parserOptions: { | |
210 | ecmaVersion: 6 | |
211 | } | |
212 | }, | |
213 | { | |
214 | code: "var { 𐌘 } = {};", | |
215 | options: [{ min: 1, max: 1 }], | |
216 | parserOptions: { | |
217 | ecmaVersion: 6 | |
218 | } | |
219 | }, | |
220 | { | |
221 | code: "var { p: 𐌘} = {};", | |
222 | options: [{ min: 1, max: 1 }], | |
223 | parserOptions: { | |
224 | ecmaVersion: 6 | |
225 | } | |
226 | }, | |
227 | { | |
228 | code: "({ prop: o.𐌘 } = {});", | |
229 | options: [{ min: 1, max: 1 }], | |
230 | parserOptions: { | |
231 | ecmaVersion: 6 | |
232 | } | |
609c276f | 233 | } |
eb39fafa DC |
234 | ], |
235 | invalid: [ | |
236 | { code: "var x = 1;", errors: [tooShortError] }, | |
237 | { code: "var x;", errors: [tooShortError] }, | |
238 | { code: "obj.e = document.body;", errors: [tooShortError] }, | |
239 | { code: "function x() {};", errors: [tooShortError] }, | |
240 | { code: "function xyz(a) {};", errors: [tooShortError] }, | |
241 | { code: "var obj = { a: 1, bc: 2 };", errors: [tooShortError] }, | |
242 | { code: "try { blah(); } catch (e) { /* pass */ }", errors: [tooShortError] }, | |
243 | { code: "var handler = function (e) {};", errors: [tooShortError] }, | |
244 | { code: "for (var i=0; i < 10; i++) { console.log(i); }", errors: [tooShortError] }, | |
245 | { code: "var j=0; while (j > -10) { console.log(--j); }", errors: [tooShortError] }, | |
246 | { code: "var [i] = arr;", parserOptions: { ecmaVersion: 6 }, errors: [tooShortError] }, | |
247 | { code: "var [,i,a] = arr;", parserOptions: { ecmaVersion: 6 }, errors: [tooShortError, tooShortError] }, | |
248 | { code: "function foo([a]) {}", parserOptions: { ecmaVersion: 6 }, errors: [tooShortError] }, | |
249 | { | |
250 | code: "var _$xt_$ = Foo(42)", | |
251 | options: [{ min: 2, max: 4 }], | |
252 | errors: [ | |
253 | tooLongError | |
254 | ] | |
255 | }, | |
256 | { | |
257 | code: "var _$x$_t$ = Foo(42)", | |
258 | options: [{ min: 2, max: 4 }], | |
259 | errors: [ | |
260 | tooLongError | |
261 | ] | |
262 | }, | |
6f036462 TL |
263 | { |
264 | code: "var toString;", | |
265 | options: [{ max: 5 }], | |
266 | errors: [ | |
267 | tooLongError | |
268 | ] | |
269 | }, | |
eb39fafa DC |
270 | { |
271 | code: "(a) => { a * a };", | |
272 | parserOptions: { ecmaVersion: 6 }, | |
273 | errors: [ | |
274 | tooShortError | |
275 | ] | |
276 | }, | |
277 | { | |
278 | code: "function foo(x = 0) { }", | |
279 | parserOptions: { ecmaVersion: 6 }, | |
280 | errors: [ | |
281 | tooShortError | |
282 | ] | |
283 | }, | |
284 | { | |
285 | code: "class x { }", | |
286 | parserOptions: { ecmaVersion: 6 }, | |
287 | errors: [ | |
288 | tooShortError | |
289 | ] | |
290 | }, | |
291 | { | |
292 | code: "class Foo { x() {} }", | |
293 | parserOptions: { ecmaVersion: 6 }, | |
294 | errors: [ | |
295 | tooShortError | |
296 | ] | |
297 | }, | |
298 | { | |
299 | code: "function foo(...x) { }", | |
300 | parserOptions: { ecmaVersion: 6 }, | |
301 | errors: [ | |
302 | tooShortError | |
303 | ] | |
304 | }, | |
305 | { | |
306 | code: "function foo({x}) { }", | |
307 | parserOptions: { ecmaVersion: 6 }, | |
308 | errors: [ | |
309 | tooShortError | |
310 | ] | |
311 | }, | |
312 | { | |
313 | code: "function foo({x: a}) { }", | |
314 | parserOptions: { ecmaVersion: 6 }, | |
315 | errors: [ | |
316 | { | |
317 | messageId: "tooShort", | |
318 | data: { name: "a", min: 2 }, | |
319 | type: "Identifier" | |
320 | } | |
321 | ] | |
322 | }, | |
323 | { | |
324 | code: "function foo({x: a, longName}) { }", | |
325 | parserOptions: { ecmaVersion: 6 }, | |
326 | errors: [ | |
327 | tooShortError | |
328 | ] | |
329 | }, | |
330 | { | |
331 | code: "function foo({ longName: a }) {}", | |
332 | options: [{ min: 3, max: 5 }], | |
333 | parserOptions: { ecmaVersion: 6 }, | |
334 | errors: [ | |
335 | tooShortError | |
336 | ] | |
337 | }, | |
338 | { | |
339 | code: "function foo({ prop: longName }) {};", | |
340 | options: [{ min: 3, max: 5 }], | |
341 | parserOptions: { ecmaVersion: 6 }, | |
342 | errors: [ | |
343 | tooLongError | |
344 | ] | |
345 | }, | |
346 | { | |
347 | code: "function foo({ a: b }) {};", | |
348 | options: [{ exceptions: ["a"] }], | |
349 | parserOptions: { ecmaVersion: 6 }, | |
350 | errors: [ | |
351 | { | |
352 | messageId: "tooShort", | |
353 | data: { name: "b", min: 2 }, | |
354 | line: 1, | |
355 | column: 19, | |
356 | type: "Identifier" | |
357 | } | |
358 | ] | |
359 | }, | |
6f036462 TL |
360 | { |
361 | code: "var hasOwnProperty;", | |
362 | options: [{ max: 10, exceptions: [] }], | |
363 | errors: [ | |
364 | { | |
365 | messageId: "tooLong", | |
366 | data: { name: "hasOwnProperty", max: 10 }, | |
367 | line: 1, | |
368 | column: 5, | |
369 | type: "Identifier" | |
370 | } | |
371 | ] | |
372 | }, | |
eb39fafa DC |
373 | { |
374 | code: "function foo({ a: { b: { c: d, e } } }) { }", | |
375 | parserOptions: { ecmaVersion: 6 }, | |
376 | errors: [ | |
377 | { | |
378 | messageId: "tooShort", | |
379 | data: { name: "d", min: 2 }, | |
380 | line: 1, | |
381 | column: 29, | |
382 | type: "Identifier" | |
383 | }, | |
384 | { | |
385 | messageId: "tooShort", | |
386 | data: { name: "e", min: 2 }, | |
387 | line: 1, | |
388 | column: 32, | |
389 | type: "Identifier" | |
390 | } | |
391 | ] | |
392 | }, | |
393 | { | |
394 | code: "var { x} = {};", | |
395 | parserOptions: { ecmaVersion: 6 }, | |
396 | errors: [ | |
397 | tooShortError | |
398 | ] | |
399 | }, | |
400 | { | |
401 | code: "var { x: a} = {};", | |
402 | parserOptions: { ecmaVersion: 6 }, | |
403 | errors: [ | |
404 | { | |
405 | messageId: "tooShort", | |
406 | data: { name: "a", min: 2 }, | |
407 | type: "Identifier" | |
408 | } | |
409 | ] | |
410 | }, | |
411 | { | |
412 | code: "var { a: a} = {};", | |
413 | parserOptions: { ecmaVersion: 6 }, | |
414 | errors: [ | |
415 | tooShortError | |
416 | ] | |
417 | }, | |
418 | { | |
419 | code: "var { prop: a } = {};", | |
420 | parserOptions: { ecmaVersion: 6 }, | |
421 | errors: [ | |
422 | tooShortError | |
423 | ] | |
424 | }, | |
425 | { | |
426 | code: "var { longName: a } = {};", | |
427 | options: [{ min: 3, max: 5 }], | |
428 | parserOptions: { ecmaVersion: 6 }, | |
429 | errors: [ | |
430 | tooShortError | |
431 | ] | |
432 | }, | |
433 | { | |
434 | code: "var { prop: [x] } = {};", | |
435 | parserOptions: { ecmaVersion: 6 }, | |
436 | errors: [ | |
437 | tooShortError | |
438 | ] | |
439 | }, | |
440 | { | |
441 | code: "var { prop: [[x]] } = {};", | |
442 | parserOptions: { ecmaVersion: 6 }, | |
443 | errors: [ | |
444 | tooShortError | |
445 | ] | |
446 | }, | |
447 | { | |
448 | code: "var { prop: longName } = {};", | |
449 | options: [{ min: 3, max: 5 }], | |
450 | parserOptions: { ecmaVersion: 6 }, | |
451 | errors: [ | |
452 | { | |
453 | messageId: "tooLong", | |
454 | data: { name: "longName", max: 5 }, | |
455 | line: 1, | |
456 | column: 13, | |
457 | type: "Identifier" | |
458 | } | |
459 | ] | |
460 | }, | |
461 | { | |
462 | code: "var { x: a} = {};", | |
463 | options: [{ exceptions: ["x"] }], | |
464 | parserOptions: { ecmaVersion: 6 }, | |
465 | errors: [ | |
466 | { | |
467 | messageId: "tooShort", | |
468 | data: { name: "a", min: 2 }, | |
469 | line: 1, | |
470 | column: 10, | |
471 | type: "Identifier" | |
472 | } | |
473 | ] | |
474 | }, | |
475 | { | |
476 | code: "var { a: { b: { c: d } } } = {};", | |
477 | parserOptions: { ecmaVersion: 6 }, | |
478 | errors: [ | |
479 | { | |
480 | messageId: "tooShort", | |
481 | data: { name: "d", min: 2 }, | |
482 | line: 1, | |
483 | column: 20, | |
484 | type: "Identifier" | |
485 | } | |
486 | ] | |
487 | }, | |
488 | { | |
489 | code: "var { a: { b: { c: d, e } } } = {};", | |
490 | parserOptions: { ecmaVersion: 6 }, | |
491 | errors: [ | |
492 | { | |
493 | messageId: "tooShort", | |
494 | data: { name: "d", min: 2 }, | |
495 | line: 1, | |
496 | column: 20, | |
497 | type: "Identifier" | |
498 | }, | |
499 | { | |
500 | messageId: "tooShort", | |
501 | data: { name: "e", min: 2 }, | |
502 | line: 1, | |
503 | column: 23, | |
504 | type: "Identifier" | |
505 | } | |
506 | ] | |
507 | }, | |
508 | { | |
509 | code: "var { a: { b: { c, e: longName } } } = {};", | |
510 | parserOptions: { ecmaVersion: 6 }, | |
511 | errors: [ | |
512 | { | |
513 | messageId: "tooShort", | |
514 | data: { name: "c", min: 2 }, | |
515 | line: 1, | |
516 | column: 17, | |
517 | type: "Identifier" | |
518 | } | |
519 | ] | |
520 | }, | |
521 | { | |
522 | code: "var { a: { b: { c: d, e: longName } } } = {};", | |
523 | parserOptions: { ecmaVersion: 6 }, | |
524 | errors: [ | |
525 | { | |
526 | messageId: "tooShort", | |
527 | data: { name: "d", min: 2 }, | |
528 | line: 1, | |
529 | column: 20, | |
530 | type: "Identifier" | |
531 | } | |
532 | ] | |
533 | }, | |
534 | { | |
535 | code: "var { a, b: { c: d, e: longName } } = {};", | |
536 | parserOptions: { ecmaVersion: 6 }, | |
537 | errors: [ | |
538 | { | |
539 | messageId: "tooShort", | |
540 | data: { name: "a", min: 2 }, | |
541 | line: 1, | |
542 | column: 7, | |
543 | type: "Identifier" | |
544 | }, | |
545 | { | |
546 | messageId: "tooShort", | |
547 | data: { name: "d", min: 2 }, | |
548 | line: 1, | |
549 | column: 18, | |
550 | type: "Identifier" | |
551 | } | |
552 | ] | |
553 | }, | |
554 | { | |
555 | code: "import x from 'y';", | |
556 | parserOptions: { ecmaVersion: 6, sourceType: "module" }, | |
557 | errors: [ | |
558 | tooShortError | |
559 | ] | |
560 | }, | |
561 | { | |
562 | code: "export var x = 0;", | |
563 | parserOptions: { ecmaVersion: 6, sourceType: "module" }, | |
564 | errors: [ | |
565 | tooShortError | |
566 | ] | |
567 | }, | |
568 | { | |
569 | code: "({ a: obj.x.y.z } = {});", | |
570 | parserOptions: { ecmaVersion: 6 }, | |
571 | errors: [ | |
572 | { | |
573 | messageId: "tooShort", | |
574 | data: { name: "z", min: 2 }, | |
575 | line: 1, | |
576 | column: 15, | |
577 | type: "Identifier" | |
578 | } | |
579 | ] | |
580 | }, | |
581 | { | |
582 | code: "({ prop: obj.x } = {});", | |
583 | parserOptions: { ecmaVersion: 6 }, | |
584 | errors: [ | |
585 | { | |
586 | messageId: "tooShort", | |
587 | data: { name: "x", min: 2 }, | |
588 | line: 1, | |
589 | column: 14, | |
590 | type: "Identifier" | |
591 | } | |
592 | ] | |
593 | }, | |
594 | { code: "var x = 1;", options: [{ properties: "never" }], errors: [tooShortError] }, | |
595 | { | |
596 | code: "var {prop: x} = foo;", | |
597 | options: [{ properties: "never" }], | |
598 | parserOptions: { ecmaVersion: 6 }, | |
599 | errors: [ | |
600 | { | |
601 | messageId: "tooShort", | |
602 | data: { name: "x", min: 2 }, | |
603 | line: 1, | |
604 | column: 12, | |
605 | type: "Identifier" | |
606 | } | |
607 | ] | |
608 | }, | |
609 | { | |
610 | code: "var foo = {x: prop};", | |
611 | options: [{ properties: "always" }], | |
612 | parserOptions: { ecmaVersion: 6 }, | |
613 | errors: [ | |
614 | tooShortError | |
615 | ] | |
6f036462 TL |
616 | }, |
617 | { | |
618 | code: "function BEFORE_send() {};", | |
619 | options: [{ min: 3, max: 5 }], | |
620 | errors: [ | |
621 | tooLongError | |
622 | ] | |
623 | }, | |
624 | { | |
625 | code: "function NOTMATCHED_send() {};", | |
626 | options: [{ min: 3, max: 5, exceptionPatterns: ["^BEFORE_"] }], | |
627 | errors: [ | |
628 | tooLongError | |
629 | ] | |
630 | }, | |
631 | { | |
632 | code: "function N() {};", | |
633 | options: [{ min: 3, max: 5, exceptionPatterns: ["^BEFORE_"] }], | |
634 | errors: [ | |
635 | tooShortError | |
636 | ] | |
609c276f TL |
637 | }, |
638 | ||
639 | // Class Fields | |
640 | { | |
641 | code: "class Foo { #x() {} }", | |
642 | parserOptions: { ecmaVersion: 2022 }, | |
643 | errors: [ | |
644 | tooShortErrorPrivate | |
645 | ] | |
646 | }, | |
647 | { | |
648 | code: "class Foo { x = 1 }", | |
649 | parserOptions: { ecmaVersion: 2022 }, | |
650 | errors: [ | |
651 | tooShortError | |
652 | ] | |
653 | }, | |
654 | { | |
655 | code: "class Foo { #x = 1 }", | |
656 | parserOptions: { ecmaVersion: 2022 }, | |
657 | errors: [ | |
658 | tooShortErrorPrivate | |
659 | ] | |
660 | }, | |
661 | { | |
662 | code: "class Foo { #abcdefg() {} }", | |
663 | options: [{ max: 3 }], | |
664 | parserOptions: { ecmaVersion: 2022 }, | |
665 | errors: [ | |
666 | tooLongErrorPrivate | |
667 | ] | |
668 | }, | |
669 | { | |
670 | code: "class Foo { abcdefg = 1 }", | |
671 | options: [{ max: 3 }], | |
672 | parserOptions: { ecmaVersion: 2022 }, | |
673 | errors: [ | |
674 | tooLongError | |
675 | ] | |
676 | }, | |
677 | { | |
678 | code: "class Foo { #abcdefg = 1 }", | |
679 | options: [{ max: 3 }], | |
680 | parserOptions: { ecmaVersion: 2022 }, | |
681 | errors: [ | |
682 | tooLongErrorPrivate | |
683 | ] | |
f2a92ac6 DC |
684 | }, |
685 | ||
686 | // Identifier consisting of two code units | |
687 | { | |
688 | code: "var 𠮟 = 2", | |
689 | parserOptions: { ecmaVersion: 6 }, | |
690 | errors: [ | |
691 | tooShortError | |
692 | ] | |
693 | }, | |
694 | { | |
695 | code: "var 葛󠄀 = 2", // 2 code points but only 1 grapheme | |
696 | parserOptions: { ecmaVersion: 6 }, | |
697 | errors: [ | |
698 | tooShortError | |
699 | ] | |
700 | }, | |
701 | { | |
702 | code: "var myObj = { 𐌘: 1 };", | |
703 | parserOptions: { | |
704 | ecmaVersion: 6 | |
705 | }, | |
706 | errors: [ | |
707 | tooShortError | |
708 | ] | |
709 | }, | |
710 | { | |
711 | code: "(𐌘) => { 𐌘 * 𐌘 };", | |
712 | parserOptions: { | |
713 | ecmaVersion: 6 | |
714 | }, | |
715 | errors: [ | |
716 | tooShortError | |
717 | ] | |
718 | }, | |
719 | { | |
720 | code: "class 𠮟 { }", | |
721 | parserOptions: { | |
722 | ecmaVersion: 6 | |
723 | }, | |
724 | errors: [ | |
725 | tooShortError | |
726 | ] | |
727 | }, | |
728 | { | |
729 | code: "class Foo { 𐌘() {} }", | |
730 | parserOptions: { | |
731 | ecmaVersion: 6 | |
732 | }, | |
733 | errors: [ | |
734 | tooShortError | |
735 | ] | |
736 | }, | |
737 | { | |
738 | code: "class Foo1 { #𐌘() {} }", | |
739 | parserOptions: { | |
740 | ecmaVersion: 2022 | |
741 | }, | |
742 | errors: [ | |
743 | tooShortErrorPrivate | |
744 | ] | |
745 | }, | |
746 | { | |
747 | code: "class Foo2 { 𐌘 = 1 }", | |
748 | parserOptions: { | |
749 | ecmaVersion: 2022 | |
750 | }, | |
751 | errors: [ | |
752 | tooShortError | |
753 | ] | |
754 | }, | |
755 | { | |
756 | code: "class Foo3 { #𐌘 = 1 }", | |
757 | parserOptions: { | |
758 | ecmaVersion: 2022 | |
759 | }, | |
760 | errors: [ | |
761 | tooShortErrorPrivate | |
762 | ] | |
763 | }, | |
764 | { | |
765 | code: "function foo1(...𐌘) { }", | |
766 | parserOptions: { | |
767 | ecmaVersion: 6 | |
768 | }, | |
769 | errors: [ | |
770 | tooShortError | |
771 | ] | |
772 | }, | |
773 | { | |
774 | code: "function foo([𐌘]) { }", | |
775 | parserOptions: { | |
776 | ecmaVersion: 6 | |
777 | }, | |
778 | errors: [ | |
779 | tooShortError | |
780 | ] | |
781 | }, | |
782 | { | |
783 | code: "var [ 𐌘 ] = arr;", | |
784 | parserOptions: { | |
785 | ecmaVersion: 6 | |
786 | }, | |
787 | errors: [ | |
788 | tooShortError | |
789 | ] | |
790 | }, | |
791 | { | |
792 | code: "var { prop: [𐌘]} = {};", | |
793 | parserOptions: { | |
794 | ecmaVersion: 6 | |
795 | }, | |
796 | errors: [ | |
797 | tooShortError | |
798 | ] | |
799 | }, | |
800 | { | |
801 | code: "function foo({𐌘}) { }", | |
802 | parserOptions: { | |
803 | ecmaVersion: 6 | |
804 | }, | |
805 | errors: [ | |
806 | tooShortError | |
807 | ] | |
808 | }, | |
809 | { | |
810 | code: "var { 𐌘 } = {};", | |
811 | parserOptions: { | |
812 | ecmaVersion: 6 | |
813 | }, | |
814 | errors: [ | |
815 | tooShortError | |
816 | ] | |
817 | }, | |
818 | { | |
819 | code: "var { prop: 𐌘} = {};", | |
820 | parserOptions: { | |
821 | ecmaVersion: 6 | |
822 | }, | |
823 | errors: [ | |
824 | tooShortError | |
825 | ] | |
826 | }, | |
827 | { | |
828 | code: "({ prop: obj.𐌘 } = {});", | |
829 | parserOptions: { | |
830 | ecmaVersion: 6 | |
831 | }, | |
832 | errors: [ | |
833 | tooShortError | |
834 | ] | |
eb39fafa DC |
835 | } |
836 | ] | |
837 | }); |