@futdevpro/dynamo-eslint 1.14.6 → 1.14.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/build/configs/base.js +12 -1
  2. package/build/configs/base.js.map +1 -1
  3. package/build/plugin/index.d.ts +8 -0
  4. package/build/plugin/index.d.ts.map +1 -1
  5. package/build/plugin/index.js +12 -0
  6. package/build/plugin/index.js.map +1 -1
  7. package/build/plugin/rules/explicit-types.js +2 -2
  8. package/build/plugin/rules/explicit-types.js.map +1 -1
  9. package/build/plugin/rules/prefer-enum-over-string-union.d.ts +4 -0
  10. package/build/plugin/rules/prefer-enum-over-string-union.d.ts.map +1 -0
  11. package/build/plugin/rules/prefer-enum-over-string-union.js +290 -0
  12. package/build/plugin/rules/prefer-enum-over-string-union.js.map +1 -0
  13. package/build/plugin/rules/prefer-enum-over-string-union.spec.d.ts +2 -0
  14. package/build/plugin/rules/prefer-enum-over-string-union.spec.d.ts.map +1 -0
  15. package/build/plugin/rules/prefer-enum-over-string-union.spec.js +505 -0
  16. package/build/plugin/rules/prefer-enum-over-string-union.spec.js.map +1 -0
  17. package/build/plugin/rules/prefer-interface-over-duplicate-types.d.ts +4 -0
  18. package/build/plugin/rules/prefer-interface-over-duplicate-types.d.ts.map +1 -0
  19. package/build/plugin/rules/prefer-interface-over-duplicate-types.js +231 -0
  20. package/build/plugin/rules/prefer-interface-over-duplicate-types.js.map +1 -0
  21. package/build/plugin/rules/prefer-interface-over-duplicate-types.spec.d.ts +2 -0
  22. package/build/plugin/rules/prefer-interface-over-duplicate-types.spec.d.ts.map +1 -0
  23. package/build/plugin/rules/prefer-interface-over-duplicate-types.spec.js +324 -0
  24. package/build/plugin/rules/prefer-interface-over-duplicate-types.spec.js.map +1 -0
  25. package/build/plugin/rules/require-jsdoc-description.d.ts +4 -0
  26. package/build/plugin/rules/require-jsdoc-description.d.ts.map +1 -0
  27. package/build/plugin/rules/require-jsdoc-description.js +379 -0
  28. package/build/plugin/rules/require-jsdoc-description.js.map +1 -0
  29. package/build/plugin/rules/require-jsdoc-description.spec.d.ts +2 -0
  30. package/build/plugin/rules/require-jsdoc-description.spec.d.ts.map +1 -0
  31. package/build/plugin/rules/require-jsdoc-description.spec.js +452 -0
  32. package/build/plugin/rules/require-jsdoc-description.spec.js.map +1 -0
  33. package/build/plugin/rules/require-test-description-prefix.d.ts +4 -0
  34. package/build/plugin/rules/require-test-description-prefix.d.ts.map +1 -0
  35. package/build/plugin/rules/require-test-description-prefix.js +135 -0
  36. package/build/plugin/rules/require-test-description-prefix.js.map +1 -0
  37. package/build/plugin/rules/require-test-description-prefix.spec.d.ts +2 -0
  38. package/build/plugin/rules/require-test-description-prefix.spec.d.ts.map +1 -0
  39. package/build/plugin/rules/require-test-description-prefix.spec.js +371 -0
  40. package/build/plugin/rules/require-test-description-prefix.spec.js.map +1 -0
  41. package/futdevpro-dynamo-eslint-1.14.7.tgz +0 -0
  42. package/package.json +1 -1
  43. package/src/configs/base.ts +12 -1
  44. package/src/plugin/index.ts +12 -0
  45. package/src/plugin/rules/explicit-types.ts +2 -2
  46. package/src/plugin/rules/prefer-enum-over-string-union.spec.ts +583 -0
  47. package/src/plugin/rules/prefer-enum-over-string-union.ts +333 -0
  48. package/src/plugin/rules/prefer-interface-over-duplicate-types.spec.ts +374 -0
  49. package/src/plugin/rules/prefer-interface-over-duplicate-types.ts +276 -0
  50. package/src/plugin/rules/require-jsdoc-description.spec.ts +542 -0
  51. package/src/plugin/rules/require-jsdoc-description.ts +436 -0
  52. package/src/plugin/rules/require-test-description-prefix.spec.ts +459 -0
  53. package/src/plugin/rules/require-test-description-prefix.ts +153 -0
  54. package/futdevpro-dynamo-eslint-1.14.6.tgz +0 -0
@@ -0,0 +1,583 @@
1
+ import preferEnumRule from './prefer-enum-over-string-union';
2
+
3
+ describe('| prefer-enum-over-string-union', () => {
4
+ it('| should be a valid ESLint rule', () => {
5
+ expect(preferEnumRule.meta.type).toBe('suggestion');
6
+ expect(preferEnumRule.meta.docs.description).toBe('Suggest using enums instead of union types of string literals');
7
+ expect(preferEnumRule.meta.fixable).toBe('code');
8
+ });
9
+
10
+ it('| should not report when union has less than threshold values', () => {
11
+ let reportCalled = false;
12
+ const mockContext = {
13
+ report: (options: any) => {
14
+ reportCalled = true;
15
+ },
16
+ options: [{ minValues: 3 }],
17
+ sourceCode: {
18
+ getText: () => '',
19
+ },
20
+ } as any;
21
+
22
+ const rule = preferEnumRule.create(mockContext);
23
+
24
+ const mockNode = {
25
+ type: 'TSTypeAliasDeclaration',
26
+ id: { name: 'Status' },
27
+ typeAnnotation: {
28
+ type: 'TSUnionType',
29
+ types: [
30
+ { type: 'TSLiteralType', literal: { value: 'active' } },
31
+ { type: 'TSLiteralType', literal: { value: 'inactive' } },
32
+ ],
33
+ },
34
+ } as any;
35
+
36
+ rule.TSTypeAliasDeclaration(mockNode);
37
+
38
+ expect(reportCalled).toBe(false);
39
+ });
40
+
41
+ it('| should report when union has threshold or more string literals', () => {
42
+ let reportCalled = false;
43
+ const mockContext = {
44
+ report: (options: any) => {
45
+ reportCalled = true;
46
+ expect(options.messageId).toBe('preferEnum');
47
+ expect(options.data.count).toBe('3');
48
+ expect(options.fix).toBeDefined();
49
+ },
50
+ options: [{ minValues: 3 }],
51
+ sourceCode: {
52
+ getText: () => 'type Status = \'active\' | \'inactive\' | \'pending\'',
53
+ },
54
+ } as any;
55
+
56
+ const rule = preferEnumRule.create(mockContext);
57
+
58
+ const mockNode = {
59
+ type: 'TSTypeAliasDeclaration',
60
+ id: { name: 'Status' },
61
+ typeAnnotation: {
62
+ type: 'TSUnionType',
63
+ types: [
64
+ { type: 'TSLiteralType', literal: { value: 'active' } },
65
+ { type: 'TSLiteralType', literal: { value: 'inactive' } },
66
+ { type: 'TSLiteralType', literal: { value: 'pending' } },
67
+ ],
68
+ },
69
+ } as any;
70
+
71
+ rule.TSTypeAliasDeclaration(mockNode);
72
+
73
+ expect(reportCalled).toBe(true);
74
+ });
75
+
76
+ it('| should not report when union contains non-string literals', () => {
77
+ let reportCalled = false;
78
+ const mockContext = {
79
+ report: (options: any) => {
80
+ reportCalled = true;
81
+ },
82
+ options: [{ minValues: 3 }],
83
+ sourceCode: {
84
+ getText: () => '',
85
+ },
86
+ } as any;
87
+
88
+ const rule = preferEnumRule.create(mockContext);
89
+
90
+ const mockNode = {
91
+ type: 'TSTypeAliasDeclaration',
92
+ id: { name: 'Value' },
93
+ typeAnnotation: {
94
+ type: 'TSUnionType',
95
+ types: [
96
+ { type: 'TSLiteralType', literal: { value: 'active' } },
97
+ { type: 'TSLiteralType', literal: { value: 'inactive' } },
98
+ { type: 'TSNumberKeyword' },
99
+ ],
100
+ },
101
+ } as any;
102
+
103
+ rule.TSTypeAliasDeclaration(mockNode);
104
+
105
+ expect(reportCalled).toBe(false);
106
+ });
107
+
108
+ it('| should not report when allowTypeAliases is true', () => {
109
+ let reportCalled = false;
110
+ const mockContext = {
111
+ report: (options: any) => {
112
+ reportCalled = true;
113
+ },
114
+ options: [{ minValues: 3, allowTypeAliases: true }],
115
+ sourceCode: {
116
+ getText: () => '',
117
+ },
118
+ } as any;
119
+
120
+ const rule = preferEnumRule.create(mockContext);
121
+
122
+ const mockNode = {
123
+ type: 'TSTypeAliasDeclaration',
124
+ id: { name: 'Status' },
125
+ typeAnnotation: {
126
+ type: 'TSUnionType',
127
+ types: [
128
+ { type: 'TSLiteralType', literal: { value: 'active' } },
129
+ { type: 'TSLiteralType', literal: { value: 'inactive' } },
130
+ { type: 'TSLiteralType', literal: { value: 'pending' } },
131
+ ],
132
+ },
133
+ } as any;
134
+
135
+ rule.TSTypeAliasDeclaration(mockNode);
136
+
137
+ expect(reportCalled).toBe(false);
138
+ });
139
+
140
+ it('| should report on interface properties', () => {
141
+ let reportCalled = false;
142
+ const mockContext = {
143
+ report: (options: any) => {
144
+ reportCalled = true;
145
+ expect(options.messageId).toBe('preferEnum');
146
+ },
147
+ options: [{ minValues: 3 }],
148
+ sourceCode: {
149
+ getText: () => '',
150
+ },
151
+ } as any;
152
+
153
+ const rule = preferEnumRule.create(mockContext);
154
+
155
+ const mockNode = {
156
+ type: 'TSPropertySignature',
157
+ key: { name: 'role' },
158
+ typeAnnotation: {
159
+ typeAnnotation: {
160
+ type: 'TSUnionType',
161
+ types: [
162
+ { type: 'TSLiteralType', literal: { value: 'admin' } },
163
+ { type: 'TSLiteralType', literal: { value: 'user' } },
164
+ { type: 'TSLiteralType', literal: { value: 'guest' } },
165
+ ],
166
+ },
167
+ },
168
+ parent: { type: 'TSInterfaceDeclaration' },
169
+ } as any;
170
+
171
+ rule.TSPropertySignature(mockNode);
172
+
173
+ expect(reportCalled).toBe(true);
174
+ });
175
+
176
+ it('| should report on class properties', () => {
177
+ let reportCalled = false;
178
+ const mockContext = {
179
+ report: (options: any) => {
180
+ reportCalled = true;
181
+ expect(options.messageId).toBe('preferEnum');
182
+ },
183
+ options: [{ minValues: 3 }],
184
+ sourceCode: {
185
+ getText: () => '',
186
+ },
187
+ } as any;
188
+
189
+ const rule = preferEnumRule.create(mockContext);
190
+
191
+ const mockNode = {
192
+ type: 'PropertyDefinition',
193
+ key: { name: 'status' },
194
+ typeAnnotation: {
195
+ typeAnnotation: {
196
+ type: 'TSUnionType',
197
+ types: [
198
+ { type: 'TSLiteralType', literal: { value: 'active' } },
199
+ { type: 'TSLiteralType', literal: { value: 'inactive' } },
200
+ { type: 'TSLiteralType', literal: { value: 'pending' } },
201
+ ],
202
+ },
203
+ },
204
+ parent: { type: 'ClassDeclaration' },
205
+ } as any;
206
+
207
+ rule.PropertyDefinition(mockNode);
208
+
209
+ expect(reportCalled).toBe(true);
210
+ });
211
+
212
+ it('| should report on function parameters', () => {
213
+ let reportCalled = false;
214
+ const mockContext = {
215
+ report: (options: any) => {
216
+ reportCalled = true;
217
+ expect(options.messageId).toBe('preferEnum');
218
+ },
219
+ options: [{ minValues: 3 }],
220
+ sourceCode: {
221
+ getText: () => '',
222
+ },
223
+ } as any;
224
+
225
+ const rule = preferEnumRule.create(mockContext);
226
+
227
+ const mockNode = {
228
+ type: 'FunctionDeclaration',
229
+ id: { name: 'setStatus' },
230
+ params: [
231
+ {
232
+ type: 'Identifier',
233
+ name: 'status',
234
+ typeAnnotation: {
235
+ typeAnnotation: {
236
+ type: 'TSUnionType',
237
+ types: [
238
+ { type: 'TSLiteralType', literal: { value: 'active' } },
239
+ { type: 'TSLiteralType', literal: { value: 'inactive' } },
240
+ { type: 'TSLiteralType', literal: { value: 'pending' } },
241
+ ],
242
+ },
243
+ },
244
+ },
245
+ ],
246
+ } as any;
247
+
248
+ rule.FunctionDeclaration(mockNode);
249
+
250
+ expect(reportCalled).toBe(true);
251
+ });
252
+
253
+ it('| should report on arrow function parameters', () => {
254
+ let reportCalled = false;
255
+ const mockContext = {
256
+ report: (options: any) => {
257
+ reportCalled = true;
258
+ expect(options.messageId).toBe('preferEnum');
259
+ },
260
+ options: [{ minValues: 3 }],
261
+ sourceCode: {
262
+ getText: () => '',
263
+ },
264
+ } as any;
265
+
266
+ const rule = preferEnumRule.create(mockContext);
267
+
268
+ const mockNode = {
269
+ type: 'ArrowFunctionExpression',
270
+ params: [
271
+ {
272
+ type: 'Identifier',
273
+ name: 'status',
274
+ typeAnnotation: {
275
+ typeAnnotation: {
276
+ type: 'TSUnionType',
277
+ types: [
278
+ { type: 'TSLiteralType', literal: { value: 'active' } },
279
+ { type: 'TSLiteralType', literal: { value: 'inactive' } },
280
+ { type: 'TSLiteralType', literal: { value: 'pending' } },
281
+ ],
282
+ },
283
+ },
284
+ },
285
+ ],
286
+ } as any;
287
+
288
+ rule.ArrowFunctionExpression(mockNode);
289
+
290
+ expect(reportCalled).toBe(true);
291
+ });
292
+
293
+ it('| should report on variable declarations', () => {
294
+ let reportCalled = false;
295
+ const mockContext = {
296
+ report: (options: any) => {
297
+ reportCalled = true;
298
+ expect(options.messageId).toBe('preferEnum');
299
+ },
300
+ options: [{ minValues: 3 }],
301
+ sourceCode: {
302
+ getText: () => '',
303
+ },
304
+ } as any;
305
+
306
+ const rule = preferEnumRule.create(mockContext);
307
+
308
+ const mockNode = {
309
+ type: 'VariableDeclarator',
310
+ id: { name: 'status' },
311
+ typeAnnotation: {
312
+ typeAnnotation: {
313
+ type: 'TSUnionType',
314
+ types: [
315
+ { type: 'TSLiteralType', literal: { value: 'active' } },
316
+ { type: 'TSLiteralType', literal: { value: 'inactive' } },
317
+ { type: 'TSLiteralType', literal: { value: 'pending' } },
318
+ ],
319
+ },
320
+ },
321
+ parent: { type: 'VariableDeclaration' },
322
+ } as any;
323
+
324
+ rule.VariableDeclarator(mockNode);
325
+
326
+ expect(reportCalled).toBe(true);
327
+ });
328
+
329
+ it('| should not report on Angular @Input() properties', () => {
330
+ let reportCalled = false;
331
+ const mockContext = {
332
+ report: (options: any) => {
333
+ reportCalled = true;
334
+ },
335
+ options: [{ minValues: 3 }],
336
+ sourceCode: {
337
+ getText: () => '',
338
+ },
339
+ } as any;
340
+
341
+ const rule = preferEnumRule.create(mockContext);
342
+
343
+ const mockNode = {
344
+ type: 'PropertyDefinition',
345
+ key: { name: 'mode' },
346
+ decorators: [
347
+ {
348
+ expression: {
349
+ type: 'CallExpression',
350
+ callee: { name: 'Input' },
351
+ },
352
+ },
353
+ ],
354
+ typeAnnotation: {
355
+ typeAnnotation: {
356
+ type: 'TSUnionType',
357
+ types: [
358
+ { type: 'TSLiteralType', literal: { value: 'light' } },
359
+ { type: 'TSLiteralType', literal: { value: 'dark' } },
360
+ { type: 'TSLiteralType', literal: { value: 'auto' } },
361
+ ],
362
+ },
363
+ },
364
+ parent: { type: 'ClassDeclaration' },
365
+ } as any;
366
+
367
+ rule.PropertyDefinition(mockNode);
368
+
369
+ expect(reportCalled).toBe(false);
370
+ });
371
+
372
+ it('| should not report on Angular input() signal properties', () => {
373
+ let reportCalled = false;
374
+ const mockContext = {
375
+ report: (options: any) => {
376
+ reportCalled = true;
377
+ },
378
+ options: [{ minValues: 3 }],
379
+ sourceCode: {
380
+ getText: () => '',
381
+ },
382
+ } as any;
383
+
384
+ const rule = preferEnumRule.create(mockContext);
385
+
386
+ const mockNode = {
387
+ type: 'PropertyDefinition',
388
+ key: { name: 'size' },
389
+ value: {
390
+ type: 'CallExpression',
391
+ callee: { name: 'input' },
392
+ },
393
+ typeAnnotation: {
394
+ typeAnnotation: {
395
+ type: 'TSUnionType',
396
+ types: [
397
+ { type: 'TSLiteralType', literal: { value: 'small' } },
398
+ { type: 'TSLiteralType', literal: { value: 'medium' } },
399
+ { type: 'TSLiteralType', literal: { value: 'large' } },
400
+ ],
401
+ },
402
+ },
403
+ parent: { type: 'ClassDeclaration' },
404
+ } as any;
405
+
406
+ rule.PropertyDefinition(mockNode);
407
+
408
+ expect(reportCalled).toBe(false);
409
+ });
410
+
411
+ it('| should not report on Angular input.required() signal properties', () => {
412
+ let reportCalled = false;
413
+ const mockContext = {
414
+ report: (options: any) => {
415
+ reportCalled = true;
416
+ },
417
+ options: [{ minValues: 3 }],
418
+ sourceCode: {
419
+ getText: () => '',
420
+ },
421
+ } as any;
422
+
423
+ const rule = preferEnumRule.create(mockContext);
424
+
425
+ const mockNode = {
426
+ type: 'PropertyDefinition',
427
+ key: { name: 'theme' },
428
+ value: {
429
+ type: 'CallExpression',
430
+ callee: {
431
+ type: 'MemberExpression',
432
+ object: { name: 'input' },
433
+ property: { name: 'required' },
434
+ },
435
+ },
436
+ typeAnnotation: {
437
+ typeAnnotation: {
438
+ type: 'TSUnionType',
439
+ types: [
440
+ { type: 'TSLiteralType', literal: { value: 'light' } },
441
+ { type: 'TSLiteralType', literal: { value: 'dark' } },
442
+ { type: 'TSLiteralType', literal: { value: 'auto' } },
443
+ ],
444
+ },
445
+ },
446
+ parent: { type: 'ClassDeclaration' },
447
+ } as any;
448
+
449
+ rule.PropertyDefinition(mockNode);
450
+
451
+ expect(reportCalled).toBe(false);
452
+ });
453
+
454
+ it('| should handle custom minValues threshold', () => {
455
+ let reportCalled = false;
456
+ const mockContext = {
457
+ report: (options: any) => {
458
+ reportCalled = true;
459
+ expect(options.data.count).toBe('2');
460
+ },
461
+ options: [{ minValues: 2 }],
462
+ sourceCode: {
463
+ getText: () => '',
464
+ },
465
+ } as any;
466
+
467
+ const rule = preferEnumRule.create(mockContext);
468
+
469
+ const mockNode = {
470
+ type: 'TSTypeAliasDeclaration',
471
+ id: { name: 'Binary' },
472
+ typeAnnotation: {
473
+ type: 'TSUnionType',
474
+ types: [
475
+ { type: 'TSLiteralType', literal: { value: 'yes' } },
476
+ { type: 'TSLiteralType', literal: { value: 'no' } },
477
+ ],
478
+ },
479
+ } as any;
480
+
481
+ rule.TSTypeAliasDeclaration(mockNode);
482
+
483
+ expect(reportCalled).toBe(true);
484
+ });
485
+
486
+ it('| should handle edge cases with empty strings and special characters', () => {
487
+ let reportCalled = false;
488
+ const mockContext = {
489
+ report: (options: any) => {
490
+ reportCalled = true;
491
+ expect(options.data.count).toBe('3');
492
+ },
493
+ options: [{ minValues: 3 }],
494
+ sourceCode: {
495
+ getText: () => '',
496
+ },
497
+ } as any;
498
+
499
+ const rule = preferEnumRule.create(mockContext);
500
+
501
+ const mockNode = {
502
+ type: 'TSTypeAliasDeclaration',
503
+ id: { name: 'Special' },
504
+ typeAnnotation: {
505
+ type: 'TSUnionType',
506
+ types: [
507
+ { type: 'TSLiteralType', literal: { value: '' } },
508
+ { type: 'TSLiteralType', literal: { value: 'hello-world' } },
509
+ { type: 'TSLiteralType', literal: { value: 'test_value' } },
510
+ ],
511
+ },
512
+ } as any;
513
+
514
+ rule.TSTypeAliasDeclaration(mockNode);
515
+
516
+ expect(reportCalled).toBe(true);
517
+ });
518
+
519
+ it('| should provide auto-fix for type aliases', () => {
520
+ const mockContext = {
521
+ report: (options: any) => {
522
+ expect(options.fix).toBeDefined();
523
+ expect(typeof options.fix).toBe('function');
524
+
525
+ // Test the fix function
526
+ const fixResult = options.fix({
527
+ replaceText: (node: any, text: string) => {
528
+ expect(text).toContain('Status');
529
+
530
+ return [];
531
+ },
532
+ });
533
+
534
+ expect(Array.isArray(fixResult)).toBe(true);
535
+ },
536
+ options: [{ minValues: 3 }],
537
+ sourceCode: {
538
+ getText: () => 'type Status = \'active\' | \'inactive\' | \'pending\'',
539
+ },
540
+ } as any;
541
+
542
+ const rule = preferEnumRule.create(mockContext);
543
+
544
+ const mockNode = {
545
+ type: 'TSTypeAliasDeclaration',
546
+ id: { name: 'Status' },
547
+ typeAnnotation: {
548
+ type: 'TSUnionType',
549
+ types: [
550
+ { type: 'TSLiteralType', literal: { value: 'active' } },
551
+ { type: 'TSLiteralType', literal: { value: 'inactive' } },
552
+ { type: 'TSLiteralType', literal: { value: 'pending' } },
553
+ ],
554
+ },
555
+ } as any;
556
+
557
+ rule.TSTypeAliasDeclaration(mockNode);
558
+ });
559
+
560
+ it('| should handle errors gracefully', () => {
561
+ const mockContext = {
562
+ report: (options: any) => {
563
+ // Should not throw
564
+ },
565
+ options: [{ minValues: 3 }],
566
+ sourceCode: {
567
+ getText: () => '',
568
+ },
569
+ } as any;
570
+
571
+ const rule = preferEnumRule.create(mockContext);
572
+
573
+ // Test with malformed nodes
574
+ const malformedNode = {
575
+ type: 'TSTypeAliasDeclaration',
576
+ // Missing required properties
577
+ } as any;
578
+
579
+ expect(() => {
580
+ rule.TSTypeAliasDeclaration(malformedNode);
581
+ }).not.toThrow();
582
+ });
583
+ });