@futdevpro/dynamo-eslint 1.14.4 → 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 (67) hide show
  1. package/.vscode/settings.json +0 -2
  2. package/build/configs/base.js +29 -7
  3. package/build/configs/base.js.map +1 -1
  4. package/build/plugin/index.d.ts +8 -0
  5. package/build/plugin/index.d.ts.map +1 -1
  6. package/build/plugin/index.js +12 -0
  7. package/build/plugin/index.js.map +1 -1
  8. package/build/plugin/rules/explicit-types.d.ts.map +1 -1
  9. package/build/plugin/rules/explicit-types.js +16 -2
  10. package/build/plugin/rules/explicit-types.js.map +1 -1
  11. package/build/plugin/rules/import/import-order.d.ts.map +1 -1
  12. package/build/plugin/rules/import/import-order.js +0 -9
  13. package/build/plugin/rules/import/import-order.js.map +1 -1
  14. package/build/plugin/rules/import/no-js-import.d.ts.map +1 -1
  15. package/build/plugin/rules/import/no-js-import.js +12 -15
  16. package/build/plugin/rules/import/no-js-import.js.map +1 -1
  17. package/build/plugin/rules/prefer-enum-over-string-union.d.ts +4 -0
  18. package/build/plugin/rules/prefer-enum-over-string-union.d.ts.map +1 -0
  19. package/build/plugin/rules/prefer-enum-over-string-union.js +290 -0
  20. package/build/plugin/rules/prefer-enum-over-string-union.js.map +1 -0
  21. package/build/plugin/rules/prefer-enum-over-string-union.spec.d.ts +2 -0
  22. package/build/plugin/rules/prefer-enum-over-string-union.spec.d.ts.map +1 -0
  23. package/build/plugin/rules/prefer-enum-over-string-union.spec.js +505 -0
  24. package/build/plugin/rules/prefer-enum-over-string-union.spec.js.map +1 -0
  25. package/build/plugin/rules/prefer-interface-over-duplicate-types.d.ts +4 -0
  26. package/build/plugin/rules/prefer-interface-over-duplicate-types.d.ts.map +1 -0
  27. package/build/plugin/rules/prefer-interface-over-duplicate-types.js +231 -0
  28. package/build/plugin/rules/prefer-interface-over-duplicate-types.js.map +1 -0
  29. package/build/plugin/rules/prefer-interface-over-duplicate-types.spec.d.ts +2 -0
  30. package/build/plugin/rules/prefer-interface-over-duplicate-types.spec.d.ts.map +1 -0
  31. package/build/plugin/rules/prefer-interface-over-duplicate-types.spec.js +324 -0
  32. package/build/plugin/rules/prefer-interface-over-duplicate-types.spec.js.map +1 -0
  33. package/build/plugin/rules/require-jsdoc-description.d.ts +4 -0
  34. package/build/plugin/rules/require-jsdoc-description.d.ts.map +1 -0
  35. package/build/plugin/rules/require-jsdoc-description.js +379 -0
  36. package/build/plugin/rules/require-jsdoc-description.js.map +1 -0
  37. package/build/plugin/rules/require-jsdoc-description.spec.d.ts +2 -0
  38. package/build/plugin/rules/require-jsdoc-description.spec.d.ts.map +1 -0
  39. package/build/plugin/rules/require-jsdoc-description.spec.js +452 -0
  40. package/build/plugin/rules/require-jsdoc-description.spec.js.map +1 -0
  41. package/build/plugin/rules/require-test-description-prefix.d.ts +4 -0
  42. package/build/plugin/rules/require-test-description-prefix.d.ts.map +1 -0
  43. package/build/plugin/rules/require-test-description-prefix.js +135 -0
  44. package/build/plugin/rules/require-test-description-prefix.js.map +1 -0
  45. package/build/plugin/rules/require-test-description-prefix.spec.d.ts +2 -0
  46. package/build/plugin/rules/require-test-description-prefix.spec.d.ts.map +1 -0
  47. package/build/plugin/rules/require-test-description-prefix.spec.js +371 -0
  48. package/build/plugin/rules/require-test-description-prefix.spec.js.map +1 -0
  49. package/build/scripts/eslintrc-audit.js.map +1 -1
  50. package/futdevpro-dynamo-eslint-1.14.7.tgz +0 -0
  51. package/package.json +1 -1
  52. package/samples/package.json.example +1 -1
  53. package/src/configs/base.ts +45 -23
  54. package/src/plugin/index.ts +12 -0
  55. package/src/plugin/rules/explicit-types.ts +19 -2
  56. package/src/plugin/rules/import/import-order.ts +0 -9
  57. package/src/plugin/rules/import/no-js-import.ts +19 -17
  58. package/src/plugin/rules/prefer-enum-over-string-union.spec.ts +583 -0
  59. package/src/plugin/rules/prefer-enum-over-string-union.ts +333 -0
  60. package/src/plugin/rules/prefer-interface-over-duplicate-types.spec.ts +374 -0
  61. package/src/plugin/rules/prefer-interface-over-duplicate-types.ts +276 -0
  62. package/src/plugin/rules/require-jsdoc-description.spec.ts +542 -0
  63. package/src/plugin/rules/require-jsdoc-description.ts +436 -0
  64. package/src/plugin/rules/require-test-description-prefix.spec.ts +459 -0
  65. package/src/plugin/rules/require-test-description-prefix.ts +153 -0
  66. package/src/scripts/eslintrc-audit.ts +8 -6
  67. package/futdevpro-dynamo-eslint-01.14.4.tgz +0 -0
@@ -0,0 +1,542 @@
1
+ import requireJSDocRule from './require-jsdoc-description';
2
+
3
+ describe('| require-jsdoc-description', () => {
4
+ it('| should be a valid ESLint rule', () => {
5
+ expect(requireJSDocRule.meta?.type).toBe('suggestion');
6
+ expect(requireJSDocRule.meta?.docs?.description).toContain('Require JSDoc comment blocks');
7
+ expect(requireJSDocRule.meta?.fixable).toBeUndefined();
8
+ });
9
+
10
+ it('| should have create function that returns visitor object', () => {
11
+ const mockContext = {
12
+ report: () => {},
13
+ options: [{ scope: 'public' }],
14
+ sourceCode: {
15
+ getCommentsBefore: () => [],
16
+ },
17
+ } as any;
18
+
19
+ const result = requireJSDocRule.create(mockContext);
20
+
21
+ expect(typeof result).toBe('object');
22
+ expect(typeof result.FunctionDeclaration).toBe('function');
23
+ expect(typeof result.ClassDeclaration).toBe('function');
24
+ expect(typeof result.TSInterfaceDeclaration).toBe('function');
25
+ expect(typeof result.TSEnumDeclaration).toBe('function');
26
+ expect(typeof result.MethodDefinition).toBe('function');
27
+ expect(typeof result.VariableDeclarator).toBe('function');
28
+ });
29
+
30
+ it('| should not report when function has valid JSDoc', () => {
31
+ const mockContext = {
32
+ report: (options: any) => {
33
+ fail('Should not report when function has valid JSDoc');
34
+ },
35
+ options: [{ scope: 'public' }],
36
+ sourceCode: {
37
+ getCommentsBefore: () => [{
38
+ type: 'Block',
39
+ value: '* This is a test function',
40
+ loc: { end: { line: 1 } },
41
+ }],
42
+ },
43
+ } as any;
44
+
45
+ const rule = requireJSDocRule.create(mockContext);
46
+
47
+ const mockNode = {
48
+ type: 'FunctionDeclaration',
49
+ id: { name: 'testFunction' },
50
+ loc: { start: { line: 2 } },
51
+ } as any;
52
+
53
+ rule.FunctionDeclaration(mockNode);
54
+ });
55
+
56
+ it('| should report when function is missing JSDoc', () => {
57
+ let reportCalled = false;
58
+ const mockContext = {
59
+ report: (options: any) => {
60
+ reportCalled = true;
61
+ expect(options.messageId).toBe('missingJSDoc');
62
+ expect(options.data.type).toBe('Function');
63
+ expect(options.data.name).toBe('testFunction');
64
+ },
65
+ options: [{ scope: 'public' }],
66
+ sourceCode: {
67
+ getCommentsBefore: () => [],
68
+ },
69
+ } as any;
70
+
71
+ const rule = requireJSDocRule.create(mockContext);
72
+
73
+ const mockNode = {
74
+ type: 'FunctionDeclaration',
75
+ id: { name: 'testFunction' },
76
+ loc: { start: { line: 1 } },
77
+ } as any;
78
+
79
+ rule.FunctionDeclaration(mockNode);
80
+
81
+ expect(reportCalled).toBe(true);
82
+ });
83
+
84
+ it('| should report when JSDoc is empty (no description)', () => {
85
+ let reportCalled = false;
86
+ const mockContext = {
87
+ report: (options: any) => {
88
+ reportCalled = true;
89
+ expect(options.messageId).toBe('emptyJSDoc');
90
+ expect(options.data.type).toBe('Function');
91
+ expect(options.data.name).toBe('testFunction');
92
+ },
93
+ options: [{ scope: 'public' }],
94
+ sourceCode: {
95
+ getCommentsBefore: () => [{
96
+ type: 'Block',
97
+ value: '*',
98
+ loc: { end: { line: 1 } },
99
+ }],
100
+ },
101
+ } as any;
102
+
103
+ const rule = requireJSDocRule.create(mockContext);
104
+
105
+ const mockNode = {
106
+ type: 'FunctionDeclaration',
107
+ id: { name: 'testFunction' },
108
+ loc: { start: { line: 2 } },
109
+ } as any;
110
+
111
+ rule.FunctionDeclaration(mockNode);
112
+
113
+ expect(reportCalled).toBe(true);
114
+ });
115
+
116
+ it('| should report when JSDoc is not on previous line', () => {
117
+ let reportCalled = false;
118
+ const mockContext = {
119
+ report: (options: any) => {
120
+ reportCalled = true;
121
+ expect(options.messageId).toBe('invalidJSDocPosition');
122
+ expect(options.data.type).toBe('Function');
123
+ expect(options.data.name).toBe('testFunction');
124
+ },
125
+ options: [{ scope: 'public' }],
126
+ sourceCode: {
127
+ getCommentsBefore: () => [{
128
+ type: 'Block',
129
+ value: '* This is a test function',
130
+ loc: { end: { line: 1 } },
131
+ }],
132
+ },
133
+ } as any;
134
+
135
+ const rule = requireJSDocRule.create(mockContext);
136
+
137
+ const mockNode = {
138
+ type: 'FunctionDeclaration',
139
+ id: { name: 'testFunction' },
140
+ loc: { start: { line: 3 } }, // Gap between comment and function
141
+ } as any;
142
+
143
+ rule.FunctionDeclaration(mockNode);
144
+
145
+ expect(reportCalled).toBe(true);
146
+ });
147
+
148
+ it('| should report when function is not exported and scope is public', () => {
149
+ const mockContext = {
150
+ report: (options: any) => {
151
+ fail('Should not report when function is not exported in public scope');
152
+ },
153
+ options: [{ scope: 'public' }],
154
+ sourceCode: {
155
+ getCommentsBefore: () => [],
156
+ },
157
+ } as any;
158
+
159
+ const rule = requireJSDocRule.create(mockContext);
160
+
161
+ const mockNode = {
162
+ type: 'FunctionDeclaration',
163
+ id: { name: 'privateFunction' },
164
+ loc: { start: { line: 1 } },
165
+ parent: { type: 'Program', body: [] },
166
+ } as any;
167
+
168
+ rule.FunctionDeclaration(mockNode);
169
+
170
+ // In public scope, non-exported functions should not be documented
171
+ });
172
+
173
+ it('| should report when function is private and scope is all', () => {
174
+ let reportCalled = false;
175
+ const mockContext = {
176
+ report: (options: any) => {
177
+ reportCalled = true;
178
+ expect(options.messageId).toBe('missingJSDoc');
179
+ },
180
+ options: [{ scope: 'all' }],
181
+ sourceCode: {
182
+ getCommentsBefore: () => [],
183
+ },
184
+ } as any;
185
+
186
+ const rule = requireJSDocRule.create(mockContext);
187
+
188
+ const mockNode = {
189
+ type: 'FunctionDeclaration',
190
+ id: { name: 'privateFunction' },
191
+ loc: { start: { line: 1 } },
192
+ } as any;
193
+
194
+ rule.FunctionDeclaration(mockNode);
195
+
196
+ expect(reportCalled).toBe(true);
197
+ });
198
+
199
+ it('| should handle class declarations', () => {
200
+ let reportCalled = false;
201
+ const mockContext = {
202
+ report: (options: any) => {
203
+ reportCalled = true;
204
+ expect(options.data.type).toBe('Class');
205
+ expect(options.data.name).toBe('TestClass');
206
+ },
207
+ options: [{ scope: 'public' }],
208
+ sourceCode: {
209
+ getCommentsBefore: () => [],
210
+ },
211
+ } as any;
212
+
213
+ const rule = requireJSDocRule.create(mockContext);
214
+
215
+ const mockNode = {
216
+ type: 'ClassDeclaration',
217
+ id: { name: 'TestClass' },
218
+ loc: { start: { line: 1 } },
219
+ } as any;
220
+
221
+ rule.ClassDeclaration(mockNode);
222
+
223
+ expect(reportCalled).toBe(true);
224
+ });
225
+
226
+ it('| should handle interface declarations', () => {
227
+ let reportCalled = false;
228
+ const mockContext = {
229
+ report: (options: any) => {
230
+ reportCalled = true;
231
+ expect(options.data.type).toBe('Interface');
232
+ expect(options.data.name).toBe('TestInterface');
233
+ },
234
+ options: [{ scope: 'public' }],
235
+ sourceCode: {
236
+ getCommentsBefore: () => [],
237
+ },
238
+ } as any;
239
+
240
+ const rule = requireJSDocRule.create(mockContext);
241
+
242
+ const mockNode = {
243
+ type: 'TSInterfaceDeclaration',
244
+ id: { name: 'TestInterface' },
245
+ loc: { start: { line: 1 } },
246
+ } as any;
247
+
248
+ rule.TSInterfaceDeclaration(mockNode);
249
+
250
+ expect(reportCalled).toBe(true);
251
+ });
252
+
253
+ it('| should handle enum declarations', () => {
254
+ let reportCalled = false;
255
+ const mockContext = {
256
+ report: (options: any) => {
257
+ reportCalled = true;
258
+ expect(options.data.type).toBe('Enum');
259
+ expect(options.data.name).toBe('TestEnum');
260
+ },
261
+ options: [{ scope: 'public' }],
262
+ sourceCode: {
263
+ getCommentsBefore: () => [],
264
+ },
265
+ } as any;
266
+
267
+ const rule = requireJSDocRule.create(mockContext);
268
+
269
+ const mockNode = {
270
+ type: 'TSEnumDeclaration',
271
+ id: { name: 'TestEnum' },
272
+ loc: { start: { line: 1 } },
273
+ } as any;
274
+
275
+ rule.TSEnumDeclaration(mockNode);
276
+
277
+ expect(reportCalled).toBe(true);
278
+ });
279
+
280
+ it('| should handle method definitions', () => {
281
+ let reportCalled = false;
282
+ const mockContext = {
283
+ report: (options: any) => {
284
+ reportCalled = true;
285
+ expect(options.data.type).toBe('Method');
286
+ expect(options.data.name).toBe('testMethod');
287
+ },
288
+ options: [{ scope: 'public' }],
289
+ sourceCode: {
290
+ getCommentsBefore: () => [],
291
+ },
292
+ } as any;
293
+
294
+ const rule = requireJSDocRule.create(mockContext);
295
+
296
+ const mockNode = {
297
+ type: 'MethodDefinition',
298
+ key: { name: 'testMethod' },
299
+ loc: { start: { line: 1 } },
300
+ } as any;
301
+
302
+ rule.MethodDefinition(mockNode);
303
+
304
+ expect(reportCalled).toBe(true);
305
+ });
306
+
307
+ it('| should handle function expressions in variable declarations', () => {
308
+ let reportCalled = false;
309
+ const mockContext = {
310
+ report: (options: any) => {
311
+ reportCalled = true;
312
+ expect(options.data.type).toBe('Function');
313
+ },
314
+ options: [{ scope: 'public' }],
315
+ sourceCode: {
316
+ getCommentsBefore: () => [],
317
+ },
318
+ } as any;
319
+
320
+ const rule = requireJSDocRule.create(mockContext);
321
+
322
+ const mockNode = {
323
+ type: 'VariableDeclarator',
324
+ id: { name: 'testFunction' },
325
+ init: { type: 'FunctionExpression' },
326
+ loc: { start: { line: 1 } },
327
+ } as any;
328
+
329
+ rule.VariableDeclarator(mockNode);
330
+
331
+ expect(reportCalled).toBe(true);
332
+ });
333
+
334
+ it('| should handle arrow functions in variable declarations', () => {
335
+ let reportCalled = false;
336
+ const mockContext = {
337
+ report: (options: any) => {
338
+ reportCalled = true;
339
+ expect(options.data.type).toBe('Function');
340
+ },
341
+ options: [{ scope: 'public' }],
342
+ sourceCode: {
343
+ getCommentsBefore: () => [],
344
+ },
345
+ } as any;
346
+
347
+ const rule = requireJSDocRule.create(mockContext);
348
+
349
+ const mockNode = {
350
+ type: 'VariableDeclarator',
351
+ id: { name: 'testArrowFunction' },
352
+ init: { type: 'ArrowFunctionExpression' },
353
+ loc: { start: { line: 1 } },
354
+ } as any;
355
+
356
+ rule.VariableDeclarator(mockNode);
357
+
358
+ expect(reportCalled).toBe(true);
359
+ });
360
+
361
+ it('| should not report when variable declarator is not a function', () => {
362
+ const mockContext = {
363
+ report: (options: any) => {
364
+ fail('Should not report when variable is not a function');
365
+ },
366
+ options: [{ scope: 'public' }],
367
+ sourceCode: {
368
+ getCommentsBefore: () => [],
369
+ },
370
+ } as any;
371
+
372
+ const rule = requireJSDocRule.create(mockContext);
373
+
374
+ const mockNode = {
375
+ type: 'VariableDeclarator',
376
+ id: { name: 'testVariable' },
377
+ init: { type: 'Literal', value: 'test' },
378
+ loc: { start: { line: 1 } },
379
+ } as any;
380
+
381
+ rule.VariableDeclarator(mockNode);
382
+ });
383
+
384
+ it('| should handle JSDoc with @param tags', () => {
385
+ const mockContext = {
386
+ report: (options: any) => {
387
+ fail('Should not report when JSDoc has description and @param tags');
388
+ },
389
+ options: [{ scope: 'public' }],
390
+ sourceCode: {
391
+ getCommentsBefore: () => [{
392
+ type: 'Block',
393
+ value: '* This function does something\n* @param {string} name The name parameter',
394
+ loc: { end: { line: 1 } },
395
+ }],
396
+ },
397
+ } as any;
398
+
399
+ const rule = requireJSDocRule.create(mockContext);
400
+
401
+ const mockNode = {
402
+ type: 'FunctionDeclaration',
403
+ id: { name: 'testFunction' },
404
+ loc: { start: { line: 2 } },
405
+ } as any;
406
+
407
+ rule.FunctionDeclaration(mockNode);
408
+ });
409
+
410
+ it('| should handle JSDoc with only @param tags (no description)', () => {
411
+ let reportCalled = false;
412
+ const mockContext = {
413
+ report: (options: any) => {
414
+ reportCalled = true;
415
+ expect(options.messageId).toBe('emptyJSDoc');
416
+ },
417
+ options: [{ scope: 'public' }],
418
+ sourceCode: {
419
+ getCommentsBefore: () => [{
420
+ type: 'Block',
421
+ value: '* @param {string} name The name parameter',
422
+ loc: { end: { line: 1 } },
423
+ }],
424
+ },
425
+ } as any;
426
+
427
+ const rule = requireJSDocRule.create(mockContext);
428
+
429
+ const mockNode = {
430
+ type: 'FunctionDeclaration',
431
+ id: { name: 'testFunction' },
432
+ loc: { start: { line: 2 } },
433
+ } as any;
434
+
435
+ rule.FunctionDeclaration(mockNode);
436
+
437
+ expect(reportCalled).toBe(true);
438
+ });
439
+
440
+ it('| should handle default scope when no options provided', () => {
441
+ let reportCalled = false;
442
+ const mockContext = {
443
+ report: (options: any) => {
444
+ reportCalled = true;
445
+ expect(options.messageId).toBe('missingJSDoc');
446
+ },
447
+ options: [],
448
+ sourceCode: {
449
+ getCommentsBefore: () => [],
450
+ },
451
+ } as any;
452
+
453
+ const rule = requireJSDocRule.create(mockContext);
454
+
455
+ const mockNode = {
456
+ type: 'FunctionDeclaration',
457
+ id: { name: 'testFunction' },
458
+ loc: { start: { line: 1 } },
459
+ } as any;
460
+
461
+ rule.FunctionDeclaration(mockNode);
462
+
463
+ expect(reportCalled).toBe(true);
464
+ });
465
+
466
+ it('| should handle error cases gracefully', () => {
467
+ const mockContext = {
468
+ report: () => {},
469
+ options: [{ scope: 'public' }],
470
+ sourceCode: {
471
+ getCommentsBefore: () => {
472
+ throw new Error('Source code error');
473
+ },
474
+ },
475
+ } as any;
476
+
477
+ const rule = requireJSDocRule.create(mockContext);
478
+
479
+ const mockNode = {
480
+ type: 'FunctionDeclaration',
481
+ id: { name: 'testFunction' },
482
+ loc: { start: { line: 1 } },
483
+ } as any;
484
+
485
+ // Should not throw error
486
+ expect(() => {
487
+ rule.FunctionDeclaration(mockNode);
488
+ }).not.toThrow();
489
+ });
490
+
491
+ it('| should handle anonymous functions', () => {
492
+ let reportCalled = false;
493
+ const mockContext = {
494
+ report: (options: any) => {
495
+ reportCalled = true;
496
+ expect(options.data.name).toBe('anonymous');
497
+ },
498
+ options: [{ scope: 'public' }],
499
+ sourceCode: {
500
+ getCommentsBefore: () => [],
501
+ },
502
+ } as any;
503
+
504
+ const rule = requireJSDocRule.create(mockContext);
505
+
506
+ const mockNode = {
507
+ type: 'FunctionDeclaration',
508
+ id: null, // Anonymous function
509
+ loc: { start: { line: 1 } },
510
+ } as any;
511
+
512
+ rule.FunctionDeclaration(mockNode);
513
+
514
+ expect(reportCalled).toBe(true);
515
+ });
516
+
517
+ it('| should handle multiline JSDoc descriptions', () => {
518
+ const mockContext = {
519
+ report: (options: any) => {
520
+ fail('Should not report when JSDoc has multiline description');
521
+ },
522
+ options: [{ scope: 'public' }],
523
+ sourceCode: {
524
+ getCommentsBefore: () => [{
525
+ type: 'Block',
526
+ value: '* This is a multiline\n* description for the function\n* that explains what it does',
527
+ loc: { end: { line: 1 } },
528
+ }],
529
+ },
530
+ } as any;
531
+
532
+ const rule = requireJSDocRule.create(mockContext);
533
+
534
+ const mockNode = {
535
+ type: 'FunctionDeclaration',
536
+ id: { name: 'testFunction' },
537
+ loc: { start: { line: 2 } },
538
+ } as any;
539
+
540
+ rule.FunctionDeclaration(mockNode);
541
+ });
542
+ });