@futdevpro/dynamo-eslint 1.20.2 → 1.20.5

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 (127) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +305 -305
  3. package/build/configs/ngx.js +2 -2
  4. package/build/configs/ngx.js.map +1 -1
  5. package/build/plugin/rules/ts/no-as-cast.d.ts.map +1 -1
  6. package/build/plugin/rules/ts/no-as-cast.js +43 -0
  7. package/build/plugin/rules/ts/no-as-cast.js.map +1 -1
  8. package/package.json +14 -7
  9. package/.c8rc.json +0 -26
  10. package/.cursor/rules/__assistant_guide.mdc +0 -30
  11. package/.cursor/rules/__main.mdc +0 -64
  12. package/.cursor/rules/_ag_backend-structure.mdc +0 -86
  13. package/.cursor/rules/_ag_backend.mdc +0 -16
  14. package/.cursor/rules/_ag_debug.mdc +0 -8
  15. package/.cursor/rules/_ag_documentation_writing_rules.mdc +0 -372
  16. package/.cursor/rules/_ag_file-refactoring.mdc +0 -113
  17. package/.cursor/rules/_ag_fixes_rules.mdc +0 -6
  18. package/.cursor/rules/_ag_frontend-structure.mdc +0 -87
  19. package/.cursor/rules/_ag_frontend.mdc +0 -40
  20. package/.cursor/rules/_ag_import-rules.mdc +0 -45
  21. package/.cursor/rules/_ag_naming.mdc +0 -116
  22. package/.cursor/rules/_ag_running_commands.mdc +0 -5
  23. package/.cursor/rules/_ag_server-controller.mdc +0 -6
  24. package/.cursor/rules/_ag_should-be.mdc +0 -7
  25. package/.cursor/rules/_ag_swearing.mdc +0 -47
  26. package/.cursor/rules/ai_development_guide.md +0 -61
  27. package/.cursor/rules/ai_directives.md +0 -114
  28. package/.cursor/rules/cursor-rules.md +0 -160
  29. package/.cursor/rules/default-command.mdc +0 -465
  30. package/.cursor/rules/error_code_pattern.md +0 -40
  31. package/.cursor/rules/saved rule mcp server use.md +0 -16
  32. package/.dynamo/pipeline.cicd.config.json +0 -184
  33. package/.dynamo/version-bump.config.json +0 -5
  34. package/.eslintrc.json +0 -4
  35. package/.github/workflows/main.yml +0 -436
  36. package/.husky/pre-commit +0 -2
  37. package/.vscode/settings.json +0 -11
  38. package/__documentations/2026-04-18-ccap-review-integration.md +0 -173
  39. package/__documentations/2026-08-18-bfr-ctm-005-eslint9-validator-report.md +0 -45
  40. package/__documentations/2026-08-22-angular-20-phase2-release.md +0 -79
  41. package/eslint.config.js +0 -15
  42. package/pnpm-workspace.yaml +0 -2
  43. package/samples/.vscode/settings.json +0 -13
  44. package/samples/base/.eslintrc.json +0 -6
  45. package/samples/base/eslint.config.js +0 -3
  46. package/samples/fsm/.eslintrc.json +0 -4
  47. package/samples/fsm/eslint.config.js +0 -3
  48. package/samples/ngx/.eslintrc.json +0 -6
  49. package/samples/ngx/eslint.config.js +0 -3
  50. package/samples/ngx-package/.eslintrc.json +0 -4
  51. package/samples/ngx-package/eslint.config.js +0 -3
  52. package/samples/nts/.eslintrc.json +0 -6
  53. package/samples/nts/eslint.config.js +0 -3
  54. package/samples/nts-package/.eslintrc.json +0 -4
  55. package/samples/nts-package/eslint.config.js +0 -3
  56. package/samples/package.json.example +0 -22
  57. package/samples/poc-sample.ts +0 -38
  58. package/samples/poc-violations.ts +0 -54
  59. package/scripts/run-coverage-tests.js +0 -24
  60. package/spec/support/helpers/ts-node-helper.js +0 -9
  61. package/spec/support/jasmine.coverage.json +0 -23
  62. package/spec/support/jasmine.json +0 -24
  63. package/src/configs/angular20-compatibility.spec.ts +0 -62
  64. package/src/configs/base.ts +0 -156
  65. package/src/configs/fsm.ts +0 -10
  66. package/src/configs/ngx-package.ts +0 -10
  67. package/src/configs/ngx.ts +0 -93
  68. package/src/configs/nts-package.ts +0 -20
  69. package/src/configs/nts.ts +0 -34
  70. package/src/index.ts +0 -4
  71. package/src/plugin/index.ts +0 -86
  72. package/src/plugin/rules/angular/angular-for-track-logic.spec.ts +0 -44
  73. package/src/plugin/rules/angular/angular-for-track-logic.ts +0 -88
  74. package/src/plugin/rules/angular/effect-signal-loop.spec.ts +0 -89
  75. package/src/plugin/rules/angular/effect-signal-loop.ts +0 -125
  76. package/src/plugin/rules/angular/no-async-ngoninit.spec.ts +0 -50
  77. package/src/plugin/rules/angular/no-async-ngoninit.ts +0 -43
  78. package/src/plugin/rules/angular/no-component-direct-api.spec.ts +0 -78
  79. package/src/plugin/rules/angular/no-component-direct-api.ts +0 -82
  80. package/src/plugin/rules/angular/no-method-call-in-template.spec.ts +0 -63
  81. package/src/plugin/rules/angular/no-method-call-in-template.ts +0 -89
  82. package/src/plugin/rules/angular/no-ngfor-directive.spec.ts +0 -44
  83. package/src/plugin/rules/angular/no-ngfor-directive.ts +0 -62
  84. package/src/plugin/rules/angular/no-ngif-directive.spec.ts +0 -44
  85. package/src/plugin/rules/angular/no-ngif-directive.ts +0 -62
  86. package/src/plugin/rules/explicit-types.spec.ts +0 -190
  87. package/src/plugin/rules/explicit-types.ts +0 -186
  88. package/src/plugin/rules/import/import-order.spec.ts +0 -219
  89. package/src/plugin/rules/import/import-order.ts +0 -197
  90. package/src/plugin/rules/import/no-import-type.spec.ts +0 -69
  91. package/src/plugin/rules/import/no-import-type.ts +0 -46
  92. package/src/plugin/rules/import/no-js-import.spec.ts +0 -82
  93. package/src/plugin/rules/import/no-js-import.ts +0 -45
  94. package/src/plugin/rules/naming-patterns.spec.ts +0 -189
  95. package/src/plugin/rules/naming-patterns.ts +0 -426
  96. package/src/plugin/rules/no-getter-logic.spec.ts +0 -591
  97. package/src/plugin/rules/no-getter-logic.ts +0 -220
  98. package/src/plugin/rules/prefer-enum-over-string-union.spec.ts +0 -583
  99. package/src/plugin/rules/prefer-enum-over-string-union.ts +0 -333
  100. package/src/plugin/rules/prefer-interface-over-duplicate-types.spec.ts +0 -404
  101. package/src/plugin/rules/prefer-interface-over-duplicate-types.ts +0 -314
  102. package/src/plugin/rules/require-jsdoc-description.spec.ts +0 -779
  103. package/src/plugin/rules/require-jsdoc-description.ts +0 -572
  104. package/src/plugin/rules/require-test-description-prefix.spec.ts +0 -459
  105. package/src/plugin/rules/require-test-description-prefix.ts +0 -154
  106. package/src/plugin/rules/ts/data-model-extends.spec.ts +0 -84
  107. package/src/plugin/rules/ts/data-model-extends.ts +0 -100
  108. package/src/plugin/rules/ts/no-any-type.spec.ts +0 -28
  109. package/src/plugin/rules/ts/no-any-type.ts +0 -36
  110. package/src/plugin/rules/ts/no-as-cast.spec.ts +0 -51
  111. package/src/plugin/rules/ts/no-as-cast.ts +0 -51
  112. package/src/plugin/rules/ts/no-dynamic-imports.spec.ts +0 -54
  113. package/src/plugin/rules/ts/no-dynamic-imports.ts +0 -49
  114. package/src/plugin/rules/ts/no-native-browser-dialogs.spec.ts +0 -54
  115. package/src/plugin/rules/ts/no-native-browser-dialogs.ts +0 -84
  116. package/src/plugin/rules/ts/no-plain-function-export.spec.ts +0 -72
  117. package/src/plugin/rules/ts/no-plain-function-export.ts +0 -73
  118. package/src/plugin/rules/ts/one-export-per-file.spec.ts +0 -64
  119. package/src/plugin/rules/ts/one-export-per-file.ts +0 -77
  120. package/src/scripts/dynamo-fix.ts +0 -172
  121. package/src/scripts/eslintrc-audit.ts +0 -116
  122. package/src/scripts/fix-return-types.spec.ts +0 -65
  123. package/src/scripts/fix-return-types.ts +0 -289
  124. package/src/scripts/validate-imports.ts +0 -292
  125. package/src/scripts/validate-naming.ts +0 -213
  126. package/src/scripts/validator-cli.integration.spec.ts +0 -99
  127. package/tsconfig.json +0 -32
@@ -1,583 +0,0 @@
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, undefined, undefined);
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, undefined, undefined);
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, undefined, undefined);
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, undefined, undefined);
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, undefined, undefined);
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, undefined, undefined);
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, undefined, undefined);
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, undefined, undefined);
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, undefined, undefined);
581
- }).not.toThrow();
582
- });
583
- });