@futdevpro/dynamo-eslint 1.15.25 → 1.20.2

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 (146) hide show
  1. package/.c8rc.json +26 -26
  2. package/.cursor/rules/__assistant_guide.mdc +30 -30
  3. package/.cursor/rules/__main.mdc +64 -64
  4. package/.cursor/rules/_ag_backend-structure.mdc +85 -85
  5. package/.cursor/rules/_ag_backend.mdc +16 -16
  6. package/.cursor/rules/_ag_debug.mdc +7 -7
  7. package/.cursor/rules/_ag_documentation_writing_rules.mdc +372 -372
  8. package/.cursor/rules/_ag_file-refactoring.mdc +113 -113
  9. package/.cursor/rules/_ag_fixes_rules.mdc +5 -5
  10. package/.cursor/rules/_ag_frontend-structure.mdc +86 -86
  11. package/.cursor/rules/_ag_frontend.mdc +39 -39
  12. package/.cursor/rules/_ag_import-rules.mdc +44 -44
  13. package/.cursor/rules/_ag_naming.mdc +115 -115
  14. package/.cursor/rules/_ag_running_commands.mdc +4 -4
  15. package/.cursor/rules/_ag_server-controller.mdc +5 -5
  16. package/.cursor/rules/_ag_should-be.mdc +6 -6
  17. package/.cursor/rules/_ag_swearing.mdc +47 -47
  18. package/.cursor/rules/ai_development_guide.md +60 -60
  19. package/.cursor/rules/ai_directives.md +114 -114
  20. package/.cursor/rules/cursor-rules.md +160 -160
  21. package/.cursor/rules/default-command.mdc +464 -464
  22. package/.cursor/rules/error_code_pattern.md +39 -39
  23. package/.cursor/rules/saved rule mcp server use.md +15 -15
  24. package/.dynamo/pipeline.cicd.config.json +184 -184
  25. package/.dynamo/version-bump.config.json +5 -5
  26. package/.eslintrc.json +4 -4
  27. package/.github/workflows/main.yml +436 -436
  28. package/.husky/pre-commit +2 -2
  29. package/.vscode/settings.json +11 -11
  30. package/README.md +312 -315
  31. package/__documentations/2026-04-18-ccap-review-integration.md +173 -173
  32. package/__documentations/2026-08-18-bfr-ctm-005-eslint9-validator-report.md +45 -0
  33. package/__documentations/2026-08-22-angular-20-phase2-release.md +79 -0
  34. package/build/configs/base.d.ts +1 -2
  35. package/build/configs/base.d.ts.map +1 -1
  36. package/build/configs/base.js +3 -4
  37. package/build/configs/base.js.map +1 -1
  38. package/build/configs/ngx.d.ts +1 -3
  39. package/build/configs/ngx.d.ts.map +1 -1
  40. package/build/configs/ngx.js +4 -7
  41. package/build/configs/ngx.js.map +1 -1
  42. package/build/plugin/index.d.ts +24 -24
  43. package/build/plugin/rules/no-getter-logic.js +1 -1
  44. package/build/plugin/rules/no-getter-logic.js.map +1 -1
  45. package/build/plugin/rules/prefer-enum-over-string-union.js +7 -7
  46. package/build/plugin/rules/prefer-enum-over-string-union.js.map +1 -1
  47. package/build/plugin/rules/prefer-interface-over-duplicate-types.js +2 -2
  48. package/build/plugin/rules/prefer-interface-over-duplicate-types.js.map +1 -1
  49. package/build/plugin/rules/require-jsdoc-description.js +7 -7
  50. package/build/plugin/rules/require-jsdoc-description.js.map +1 -1
  51. package/build/scripts/dynamo-fix.js +1 -1
  52. package/build/scripts/dynamo-fix.js.map +1 -1
  53. package/build/scripts/fix-return-types.d.ts.map +1 -1
  54. package/build/scripts/fix-return-types.js.map +1 -1
  55. package/build/scripts/validate-imports.js +51 -27
  56. package/build/scripts/validate-imports.js.map +1 -1
  57. package/build/scripts/validate-naming.js +49 -10
  58. package/build/scripts/validate-naming.js.map +1 -1
  59. package/eslint.config.js +15 -15
  60. package/package.json +27 -28
  61. package/pnpm-workspace.yaml +2 -0
  62. package/samples/.vscode/settings.json +13 -13
  63. package/samples/base/.eslintrc.json +6 -6
  64. package/samples/base/eslint.config.js +3 -3
  65. package/samples/fsm/.eslintrc.json +4 -4
  66. package/samples/fsm/eslint.config.js +3 -3
  67. package/samples/ngx/.eslintrc.json +6 -6
  68. package/samples/ngx/eslint.config.js +3 -3
  69. package/samples/ngx-package/.eslintrc.json +4 -4
  70. package/samples/ngx-package/eslint.config.js +3 -3
  71. package/samples/nts/.eslintrc.json +6 -6
  72. package/samples/nts/eslint.config.js +3 -3
  73. package/samples/nts-package/.eslintrc.json +4 -4
  74. package/samples/nts-package/eslint.config.js +3 -3
  75. package/samples/package.json.example +22 -26
  76. package/samples/poc-sample.ts +38 -38
  77. package/samples/poc-violations.ts +54 -54
  78. package/scripts/run-coverage-tests.js +24 -24
  79. package/spec/support/helpers/ts-node-helper.js +9 -9
  80. package/spec/support/jasmine.coverage.json +23 -23
  81. package/spec/support/jasmine.json +24 -24
  82. package/src/configs/angular20-compatibility.spec.ts +62 -0
  83. package/src/configs/base.ts +156 -157
  84. package/src/configs/fsm.ts +10 -10
  85. package/src/configs/ngx-package.ts +10 -10
  86. package/src/configs/ngx.ts +92 -95
  87. package/src/configs/nts-package.ts +20 -20
  88. package/src/configs/nts.ts +34 -34
  89. package/src/index.ts +4 -4
  90. package/src/plugin/index.ts +86 -86
  91. package/src/plugin/rules/angular/angular-for-track-logic.spec.ts +44 -44
  92. package/src/plugin/rules/angular/angular-for-track-logic.ts +88 -88
  93. package/src/plugin/rules/angular/effect-signal-loop.spec.ts +89 -89
  94. package/src/plugin/rules/angular/effect-signal-loop.ts +125 -125
  95. package/src/plugin/rules/angular/no-async-ngoninit.spec.ts +50 -50
  96. package/src/plugin/rules/angular/no-async-ngoninit.ts +43 -43
  97. package/src/plugin/rules/angular/no-component-direct-api.spec.ts +78 -78
  98. package/src/plugin/rules/angular/no-component-direct-api.ts +82 -82
  99. package/src/plugin/rules/angular/no-method-call-in-template.spec.ts +63 -63
  100. package/src/plugin/rules/angular/no-method-call-in-template.ts +89 -89
  101. package/src/plugin/rules/angular/no-ngfor-directive.spec.ts +44 -44
  102. package/src/plugin/rules/angular/no-ngfor-directive.ts +62 -62
  103. package/src/plugin/rules/angular/no-ngif-directive.spec.ts +44 -44
  104. package/src/plugin/rules/angular/no-ngif-directive.ts +62 -62
  105. package/src/plugin/rules/explicit-types.spec.ts +190 -190
  106. package/src/plugin/rules/explicit-types.ts +186 -186
  107. package/src/plugin/rules/import/import-order.spec.ts +219 -219
  108. package/src/plugin/rules/import/import-order.ts +197 -197
  109. package/src/plugin/rules/import/no-import-type.spec.ts +69 -69
  110. package/src/plugin/rules/import/no-import-type.ts +46 -46
  111. package/src/plugin/rules/import/no-js-import.spec.ts +82 -82
  112. package/src/plugin/rules/import/no-js-import.ts +45 -45
  113. package/src/plugin/rules/naming-patterns.spec.ts +189 -189
  114. package/src/plugin/rules/naming-patterns.ts +426 -426
  115. package/src/plugin/rules/no-getter-logic.spec.ts +591 -591
  116. package/src/plugin/rules/no-getter-logic.ts +220 -220
  117. package/src/plugin/rules/prefer-enum-over-string-union.spec.ts +583 -583
  118. package/src/plugin/rules/prefer-enum-over-string-union.ts +333 -334
  119. package/src/plugin/rules/prefer-interface-over-duplicate-types.spec.ts +404 -404
  120. package/src/plugin/rules/prefer-interface-over-duplicate-types.ts +314 -314
  121. package/src/plugin/rules/require-jsdoc-description.spec.ts +779 -779
  122. package/src/plugin/rules/require-jsdoc-description.ts +572 -572
  123. package/src/plugin/rules/require-test-description-prefix.spec.ts +459 -459
  124. package/src/plugin/rules/require-test-description-prefix.ts +154 -154
  125. package/src/plugin/rules/ts/data-model-extends.spec.ts +84 -84
  126. package/src/plugin/rules/ts/data-model-extends.ts +100 -100
  127. package/src/plugin/rules/ts/no-any-type.spec.ts +28 -28
  128. package/src/plugin/rules/ts/no-any-type.ts +36 -36
  129. package/src/plugin/rules/ts/no-as-cast.spec.ts +51 -51
  130. package/src/plugin/rules/ts/no-as-cast.ts +51 -51
  131. package/src/plugin/rules/ts/no-dynamic-imports.spec.ts +54 -54
  132. package/src/plugin/rules/ts/no-dynamic-imports.ts +49 -49
  133. package/src/plugin/rules/ts/no-native-browser-dialogs.spec.ts +54 -54
  134. package/src/plugin/rules/ts/no-native-browser-dialogs.ts +84 -84
  135. package/src/plugin/rules/ts/no-plain-function-export.spec.ts +72 -72
  136. package/src/plugin/rules/ts/no-plain-function-export.ts +73 -73
  137. package/src/plugin/rules/ts/one-export-per-file.spec.ts +64 -64
  138. package/src/plugin/rules/ts/one-export-per-file.ts +77 -77
  139. package/src/scripts/dynamo-fix.ts +172 -172
  140. package/src/scripts/eslintrc-audit.ts +116 -116
  141. package/src/scripts/fix-return-types.spec.ts +65 -65
  142. package/src/scripts/fix-return-types.ts +286 -285
  143. package/src/scripts/validate-imports.ts +288 -257
  144. package/src/scripts/validate-naming.ts +209 -183
  145. package/src/scripts/validator-cli.integration.spec.ts +99 -0
  146. package/tsconfig.json +31 -31
@@ -1,779 +1,779 @@
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.TSTypeAliasDeclaration).toBe('function');
27
- expect(typeof result.MethodDefinition).toBe('function');
28
- expect(typeof result.VariableDeclarator).toBe('function');
29
- });
30
-
31
- it('| should not report when function has valid JSDoc', () => {
32
- const mockContext = {
33
- report: (options: any) => {
34
- fail('Should not report when function has valid JSDoc');
35
- },
36
- options: [{ scope: 'public' }],
37
- sourceCode: {
38
- getCommentsBefore: () => [{
39
- type: 'Block',
40
- value: '* This is a test function',
41
- loc: { end: { line: 1 } },
42
- }],
43
- },
44
- } as any;
45
-
46
- const rule = requireJSDocRule.create(mockContext);
47
-
48
- const mockNode = {
49
- type: 'FunctionDeclaration',
50
- id: { name: 'testFunction' },
51
- loc: { start: { line: 2 } },
52
- } as any;
53
-
54
- rule.FunctionDeclaration(mockNode);
55
- });
56
-
57
- it('| should report when function is missing JSDoc', () => {
58
- let reportCalled = false;
59
- const mockContext = {
60
- report: (options: any) => {
61
- reportCalled = true;
62
- expect(options.messageId).toBe('missingJSDoc');
63
- expect(options.data.type).toBe('Function');
64
- expect(options.data.name).toBe('testFunction');
65
- },
66
- options: [{ scope: 'public' }],
67
- sourceCode: {
68
- getCommentsBefore: () => [],
69
- },
70
- } as any;
71
-
72
- const rule = requireJSDocRule.create(mockContext);
73
-
74
- const mockNode = {
75
- type: 'FunctionDeclaration',
76
- id: { name: 'testFunction' },
77
- loc: { start: { line: 1 } },
78
- } as any;
79
-
80
- rule.FunctionDeclaration(mockNode);
81
-
82
- expect(reportCalled).toBe(true);
83
- });
84
-
85
- it('| should report when JSDoc is empty (no description)', () => {
86
- let reportCalled = false;
87
- const mockContext = {
88
- report: (options: any) => {
89
- reportCalled = true;
90
- expect(options.messageId).toBe('emptyJSDoc');
91
- expect(options.data.type).toBe('Function');
92
- expect(options.data.name).toBe('testFunction');
93
- },
94
- options: [{ scope: 'public' }],
95
- sourceCode: {
96
- getCommentsBefore: () => [{
97
- type: 'Block',
98
- value: '*',
99
- loc: { end: { line: 1 } },
100
- }],
101
- },
102
- } as any;
103
-
104
- const rule = requireJSDocRule.create(mockContext);
105
-
106
- const mockNode = {
107
- type: 'FunctionDeclaration',
108
- id: { name: 'testFunction' },
109
- loc: { start: { line: 2 } },
110
- } as any;
111
-
112
- rule.FunctionDeclaration(mockNode);
113
-
114
- expect(reportCalled).toBe(true);
115
- });
116
-
117
- it('| should report when JSDoc is not on previous line', () => {
118
- let reportCalled = false;
119
- const mockContext = {
120
- report: (options: any) => {
121
- reportCalled = true;
122
- expect(options.messageId).toBe('invalidJSDocPosition');
123
- expect(options.data.type).toBe('Function');
124
- expect(options.data.name).toBe('testFunction');
125
- },
126
- options: [{ scope: 'public' }],
127
- sourceCode: {
128
- getCommentsBefore: () => [{
129
- type: 'Block',
130
- value: '* This is a test function',
131
- loc: { end: { line: 1 } },
132
- }],
133
- },
134
- } as any;
135
-
136
- const rule = requireJSDocRule.create(mockContext);
137
-
138
- const mockNode = {
139
- type: 'FunctionDeclaration',
140
- id: { name: 'testFunction' },
141
- loc: { start: { line: 3 } }, // Gap between comment and function
142
- } as any;
143
-
144
- rule.FunctionDeclaration(mockNode);
145
-
146
- expect(reportCalled).toBe(true);
147
- });
148
-
149
- it('| should report when function is not exported and scope is public', () => {
150
- const mockContext = {
151
- report: (options: any) => {
152
- fail('Should not report when function is not exported in public scope');
153
- },
154
- options: [{ scope: 'public' }],
155
- sourceCode: {
156
- getCommentsBefore: () => [],
157
- },
158
- } as any;
159
-
160
- const rule = requireJSDocRule.create(mockContext);
161
-
162
- const mockNode = {
163
- type: 'FunctionDeclaration',
164
- id: { name: 'privateFunction' },
165
- loc: { start: { line: 1 } },
166
- parent: { type: 'Program', body: [] },
167
- } as any;
168
-
169
- rule.FunctionDeclaration(mockNode);
170
-
171
- // In public scope, non-exported functions should not be documented
172
- });
173
-
174
- it('| should report when function is private and scope is all', () => {
175
- let reportCalled = false;
176
- const mockContext = {
177
- report: (options: any) => {
178
- reportCalled = true;
179
- expect(options.messageId).toBe('missingJSDoc');
180
- },
181
- options: [{ scope: 'all' }],
182
- sourceCode: {
183
- getCommentsBefore: () => [],
184
- },
185
- } as any;
186
-
187
- const rule = requireJSDocRule.create(mockContext);
188
-
189
- const mockNode = {
190
- type: 'FunctionDeclaration',
191
- id: { name: 'privateFunction' },
192
- loc: { start: { line: 1 } },
193
- } as any;
194
-
195
- rule.FunctionDeclaration(mockNode);
196
-
197
- expect(reportCalled).toBe(true);
198
- });
199
-
200
- it('| should handle class declarations', () => {
201
- let reportCalled = false;
202
- const mockContext = {
203
- report: (options: any) => {
204
- reportCalled = true;
205
- expect(options.data.type).toBe('Class');
206
- expect(options.data.name).toBe('TestClass');
207
- },
208
- options: [{ scope: 'public' }],
209
- sourceCode: {
210
- getCommentsBefore: () => [],
211
- },
212
- } as any;
213
-
214
- const rule = requireJSDocRule.create(mockContext);
215
-
216
- const mockNode = {
217
- type: 'ClassDeclaration',
218
- id: { name: 'TestClass' },
219
- loc: { start: { line: 1 } },
220
- } as any;
221
-
222
- rule.ClassDeclaration(mockNode);
223
-
224
- expect(reportCalled).toBe(true);
225
- });
226
-
227
- it('| should handle interface declarations', () => {
228
- let reportCalled = false;
229
- const mockContext = {
230
- report: (options: any) => {
231
- reportCalled = true;
232
- expect(options.data.type).toBe('Interface');
233
- expect(options.data.name).toBe('TestInterface');
234
- },
235
- options: [{ scope: 'public' }],
236
- sourceCode: {
237
- getCommentsBefore: () => [],
238
- },
239
- } as any;
240
-
241
- const rule = requireJSDocRule.create(mockContext);
242
-
243
- const mockNode = {
244
- type: 'TSInterfaceDeclaration',
245
- id: { name: 'TestInterface' },
246
- loc: { start: { line: 1 } },
247
- } as any;
248
-
249
- rule.TSInterfaceDeclaration(mockNode);
250
-
251
- expect(reportCalled).toBe(true);
252
- });
253
-
254
- it('| should handle enum declarations', () => {
255
- let reportCalled = false;
256
- const mockContext = {
257
- report: (options: any) => {
258
- reportCalled = true;
259
- expect(options.data.type).toBe('Enum');
260
- expect(options.data.name).toBe('TestEnum');
261
- },
262
- options: [{ scope: 'public' }],
263
- sourceCode: {
264
- getCommentsBefore: () => [],
265
- },
266
- } as any;
267
-
268
- const rule = requireJSDocRule.create(mockContext);
269
-
270
- const mockNode = {
271
- type: 'TSEnumDeclaration',
272
- id: { name: 'TestEnum' },
273
- loc: { start: { line: 1 } },
274
- } as any;
275
-
276
- rule.TSEnumDeclaration(mockNode);
277
-
278
- expect(reportCalled).toBe(true);
279
- });
280
-
281
- it('| should handle method definitions', () => {
282
- let reportCalled = false;
283
- const mockContext = {
284
- report: (options: any) => {
285
- reportCalled = true;
286
- expect(options.data.type).toBe('Method');
287
- expect(options.data.name).toBe('testMethod');
288
- },
289
- options: [{ scope: 'public' }],
290
- sourceCode: {
291
- getCommentsBefore: () => [],
292
- },
293
- } as any;
294
-
295
- const rule = requireJSDocRule.create(mockContext);
296
-
297
- const mockNode = {
298
- type: 'MethodDefinition',
299
- key: { name: 'testMethod' },
300
- loc: { start: { line: 1 } },
301
- } as any;
302
-
303
- rule.MethodDefinition(mockNode);
304
-
305
- expect(reportCalled).toBe(true);
306
- });
307
-
308
- it('| should handle function expressions in variable declarations', () => {
309
- let reportCalled = false;
310
- const mockContext = {
311
- report: (options: any) => {
312
- reportCalled = true;
313
- expect(options.data.type).toBe('Function');
314
- },
315
- options: [{ scope: 'public' }],
316
- sourceCode: {
317
- getCommentsBefore: () => [],
318
- },
319
- } as any;
320
-
321
- const rule = requireJSDocRule.create(mockContext);
322
-
323
- const mockNode = {
324
- type: 'VariableDeclarator',
325
- id: { name: 'testFunction' },
326
- init: { type: 'FunctionExpression' },
327
- loc: { start: { line: 1 } },
328
- } as any;
329
-
330
- rule.VariableDeclarator(mockNode);
331
-
332
- expect(reportCalled).toBe(true);
333
- });
334
-
335
- it('| should handle arrow functions in variable declarations', () => {
336
- let reportCalled = false;
337
- const mockContext = {
338
- report: (options: any) => {
339
- reportCalled = true;
340
- expect(options.data.type).toBe('Function');
341
- },
342
- options: [{ scope: 'public' }],
343
- sourceCode: {
344
- getCommentsBefore: () => [],
345
- },
346
- } as any;
347
-
348
- const rule = requireJSDocRule.create(mockContext);
349
-
350
- const mockNode = {
351
- type: 'VariableDeclarator',
352
- id: { name: 'testArrowFunction' },
353
- init: { type: 'ArrowFunctionExpression' },
354
- loc: { start: { line: 1 } },
355
- } as any;
356
-
357
- rule.VariableDeclarator(mockNode);
358
-
359
- expect(reportCalled).toBe(true);
360
- });
361
-
362
- it('| should not report when variable declarator is not a function', () => {
363
- const mockContext = {
364
- report: (options: any) => {
365
- fail('Should not report when variable is not a function');
366
- },
367
- options: [{ scope: 'public' }],
368
- sourceCode: {
369
- getCommentsBefore: () => [],
370
- },
371
- } as any;
372
-
373
- const rule = requireJSDocRule.create(mockContext);
374
-
375
- const mockNode = {
376
- type: 'VariableDeclarator',
377
- id: { name: 'testVariable' },
378
- init: { type: 'Literal', value: 'test' },
379
- loc: { start: { line: 1 } },
380
- } as any;
381
-
382
- rule.VariableDeclarator(mockNode);
383
- });
384
-
385
- it('| should handle JSDoc with @param tags', () => {
386
- const mockContext = {
387
- report: (options: any) => {
388
- fail('Should not report when JSDoc has description and @param tags');
389
- },
390
- options: [{ scope: 'public' }],
391
- sourceCode: {
392
- getCommentsBefore: () => [{
393
- type: 'Block',
394
- value: '* This function does something\n* @param {string} name The name parameter',
395
- loc: { end: { line: 1 } },
396
- }],
397
- },
398
- } as any;
399
-
400
- const rule = requireJSDocRule.create(mockContext);
401
-
402
- const mockNode = {
403
- type: 'FunctionDeclaration',
404
- id: { name: 'testFunction' },
405
- loc: { start: { line: 2 } },
406
- } as any;
407
-
408
- rule.FunctionDeclaration(mockNode);
409
- });
410
-
411
- it('| should handle JSDoc with only @param tags (no description)', () => {
412
- let reportCalled = false;
413
- const mockContext = {
414
- report: (options: any) => {
415
- reportCalled = true;
416
- expect(options.messageId).toBe('emptyJSDoc');
417
- },
418
- options: [{ scope: 'public' }],
419
- sourceCode: {
420
- getCommentsBefore: () => [{
421
- type: 'Block',
422
- value: '* @param {string} name The name parameter',
423
- loc: { end: { line: 1 } },
424
- }],
425
- },
426
- } as any;
427
-
428
- const rule = requireJSDocRule.create(mockContext);
429
-
430
- const mockNode = {
431
- type: 'FunctionDeclaration',
432
- id: { name: 'testFunction' },
433
- loc: { start: { line: 2 } },
434
- } as any;
435
-
436
- rule.FunctionDeclaration(mockNode);
437
-
438
- expect(reportCalled).toBe(true);
439
- });
440
-
441
- it('| should handle default scope when no options provided', () => {
442
- let reportCalled = false;
443
- const mockContext = {
444
- report: (options: any) => {
445
- reportCalled = true;
446
- expect(options.messageId).toBe('missingJSDoc');
447
- },
448
- options: [],
449
- sourceCode: {
450
- getCommentsBefore: () => [],
451
- },
452
- } as any;
453
-
454
- const rule = requireJSDocRule.create(mockContext);
455
-
456
- const mockNode = {
457
- type: 'FunctionDeclaration',
458
- id: { name: 'testFunction' },
459
- loc: { start: { line: 1 } },
460
- } as any;
461
-
462
- rule.FunctionDeclaration(mockNode);
463
-
464
- expect(reportCalled).toBe(true);
465
- });
466
-
467
- it('| should handle error cases gracefully', () => {
468
- const mockContext = {
469
- report: () => {},
470
- options: [{ scope: 'public' }],
471
- sourceCode: {
472
- getCommentsBefore: () => {
473
- throw new Error('Source code error');
474
- },
475
- },
476
- } as any;
477
-
478
- const rule = requireJSDocRule.create(mockContext);
479
-
480
- const mockNode = {
481
- type: 'FunctionDeclaration',
482
- id: { name: 'testFunction' },
483
- loc: { start: { line: 1 } },
484
- } as any;
485
-
486
- // Should not throw error
487
- expect(() => {
488
- rule.FunctionDeclaration(mockNode);
489
- }).not.toThrow();
490
- });
491
-
492
- it('| should handle anonymous functions', () => {
493
- let reportCalled = false;
494
- const mockContext = {
495
- report: (options: any) => {
496
- reportCalled = true;
497
- expect(options.data.name).toBe('anonymous');
498
- },
499
- options: [{ scope: 'public' }],
500
- sourceCode: {
501
- getCommentsBefore: () => [],
502
- },
503
- } as any;
504
-
505
- const rule = requireJSDocRule.create(mockContext);
506
-
507
- const mockNode = {
508
- type: 'FunctionDeclaration',
509
- id: null, // Anonymous function
510
- loc: { start: { line: 1 } },
511
- } as any;
512
-
513
- rule.FunctionDeclaration(mockNode);
514
-
515
- expect(reportCalled).toBe(true);
516
- });
517
-
518
- it('| should handle multiline JSDoc descriptions', () => {
519
- const mockContext = {
520
- report: (options: any) => {
521
- fail('Should not report when JSDoc has multiline description');
522
- },
523
- options: [{ scope: 'public' }],
524
- sourceCode: {
525
- getCommentsBefore: () => [{
526
- type: 'Block',
527
- value: '* This is a multiline\n* description for the function\n* that explains what it does',
528
- loc: { end: { line: 1 } },
529
- }],
530
- },
531
- } as any;
532
-
533
- const rule = requireJSDocRule.create(mockContext);
534
-
535
- const mockNode = {
536
- type: 'FunctionDeclaration',
537
- id: { name: 'testFunction' },
538
- loc: { start: { line: 2 } },
539
- } as any;
540
-
541
- rule.FunctionDeclaration(mockNode);
542
- });
543
-
544
- it('| should handle abstract class with multiline JSDoc', () => {
545
- const mockContext = {
546
- report: (options: any) => {
547
- fail('Should not report when abstract class has multiline JSDoc');
548
- },
549
- options: [{ scope: 'public' }],
550
- sourceCode: {
551
- getCommentsBefore: () => [{
552
- type: 'Block',
553
- value: '* Abstract data service osztály a user műveletek kezeléséhez.\n* Kezeli a login, register, validation és egyéb user-rel kapcsolatos műveleteket.',
554
- loc: { end: { line: 3 } },
555
- }],
556
- },
557
- } as any;
558
-
559
- const rule = requireJSDocRule.create(mockContext);
560
-
561
- const mockNode = {
562
- type: 'ClassDeclaration',
563
- id: { name: 'FDPNTS_User_DataService' },
564
- loc: { start: { line: 4 } },
565
- parent: {
566
- type: 'ExportNamedDeclaration',
567
- },
568
- } as any;
569
-
570
- rule.ClassDeclaration(mockNode);
571
- });
572
-
573
- it('| should handle multiline JSDoc with empty lines', () => {
574
- const mockContext = {
575
- report: (options: any) => {
576
- fail('Should not report when JSDoc has multiline description with empty lines');
577
- },
578
- options: [{ scope: 'public' }],
579
- sourceCode: {
580
- getCommentsBefore: () => [{
581
- type: 'Block',
582
- value: '* This is a multiline description\n*\n* with empty lines in between\n* that should still be valid',
583
- loc: { end: { line: 4 } },
584
- }],
585
- },
586
- } as any;
587
-
588
- const rule = requireJSDocRule.create(mockContext);
589
-
590
- const mockNode = {
591
- type: 'FunctionDeclaration',
592
- id: { name: 'testFunction' },
593
- loc: { start: { line: 5 } },
594
- } as any;
595
-
596
- rule.FunctionDeclaration(mockNode);
597
- });
598
-
599
- it('| should handle multiline JSDoc followed by @tags', () => {
600
- const mockContext = {
601
- report: (options: any) => {
602
- fail('Should not report when JSDoc has description before @tags');
603
- },
604
- options: [{ scope: 'public' }],
605
- sourceCode: {
606
- getCommentsBefore: () => [{
607
- type: 'Block',
608
- value: '* This is a description\n* that spans multiple lines\n* @param {string} name The name parameter',
609
- loc: { end: { line: 2 } },
610
- }],
611
- },
612
- } as any;
613
-
614
- const rule = requireJSDocRule.create(mockContext);
615
-
616
- const mockNode = {
617
- type: 'FunctionDeclaration',
618
- id: { name: 'testFunction' },
619
- loc: { start: { line: 3 } },
620
- } as any;
621
-
622
- rule.FunctionDeclaration(mockNode);
623
- });
624
-
625
- it('| should find JSDoc on the export wrapper for `export class X`', () => {
626
- // A belso ClassDeclaration ele NINCS comment — csak az ExportNamedDeclaration ele.
627
- // A fix nelkul a szabaly tevesen "missingJSDoc"-ot jelez.
628
- const jsdoc = {
629
- type: 'Block',
630
- value: '* Exported class with JSDoc above the export keyword.',
631
- loc: { end: { line: 1 } },
632
- };
633
- const exportNode: any = { type: 'ExportNamedDeclaration' };
634
- const mockContext = {
635
- report: () => {
636
- fail('Should not report — JSDoc is present above the export wrapper');
637
- },
638
- options: [{ scope: 'public' }],
639
- sourceCode: {
640
- getCommentsBefore: (anchor: any): any[] => (anchor === exportNode ? [ jsdoc ] : []),
641
- },
642
- } as any;
643
-
644
- const rule = requireJSDocRule.create(mockContext);
645
-
646
- const mockNode: any = {
647
- type: 'ClassDeclaration',
648
- id: { name: 'X' },
649
- loc: { start: { line: 2 } },
650
- };
651
- mockNode.parent = exportNode;
652
- exportNode.declaration = mockNode;
653
-
654
- rule.ClassDeclaration(mockNode);
655
- });
656
-
657
- it('| should find JSDoc on the export wrapper for an arrow-const function', () => {
658
- const jsdoc = {
659
- type: 'Block',
660
- value: '* Arrow-const with explicit JSDoc above the export.',
661
- loc: { end: { line: 1 } },
662
- };
663
- const varDecl: any = { type: 'VariableDeclaration' };
664
- const exportNode: any = { type: 'ExportNamedDeclaration', declaration: varDecl };
665
- varDecl.parent = exportNode;
666
-
667
- const mockContext = {
668
- report: () => {
669
- fail('Should not report — arrow-const JSDoc is present above the export');
670
- },
671
- options: [{ scope: 'public' }],
672
- sourceCode: {
673
- getCommentsBefore: (anchor: any): any[] => (anchor === exportNode ? [ jsdoc ] : []),
674
- },
675
- } as any;
676
-
677
- const rule = requireJSDocRule.create(mockContext);
678
-
679
- const mockNode: any = {
680
- type: 'VariableDeclarator',
681
- id: { name: 'fn' },
682
- init: { type: 'ArrowFunctionExpression' },
683
- loc: { start: { line: 2 } },
684
- parent: varDecl,
685
- };
686
-
687
- rule.VariableDeclarator(mockNode);
688
- });
689
-
690
- it('| should find JSDoc above a decorator stack', () => {
691
- const jsdoc = {
692
- type: 'Block',
693
- value: '* Decorated component with JSDoc above the decorator.',
694
- loc: { end: { line: 1 } },
695
- };
696
- const decorator: any = { type: 'Decorator' };
697
-
698
- const mockContext = {
699
- report: () => {
700
- fail('Should not report — JSDoc is present above the decorator stack');
701
- },
702
- options: [{ scope: 'public' }],
703
- sourceCode: {
704
- getCommentsBefore: (anchor: any): any[] => (anchor === decorator ? [ jsdoc ] : []),
705
- },
706
- } as any;
707
-
708
- const rule = requireJSDocRule.create(mockContext);
709
-
710
- const mockNode: any = {
711
- type: 'ClassDeclaration',
712
- id: { name: 'X' },
713
- loc: { start: { line: 2 } },
714
- decorators: [ decorator ],
715
- };
716
-
717
- rule.ClassDeclaration(mockNode);
718
- });
719
-
720
- it('| should still report a genuinely missing JSDoc on an export-wrapped class', () => {
721
- let reportCalled = false;
722
- const exportNode: any = { type: 'ExportNamedDeclaration' };
723
- const mockContext = {
724
- report: (options: any) => {
725
- reportCalled = true;
726
- expect(options.messageId).toBe('missingJSDoc');
727
- expect(options.data.name).toBe('Undocumented');
728
- },
729
- options: [{ scope: 'public' }],
730
- sourceCode: {
731
- getCommentsBefore: (): any[] => [],
732
- },
733
- } as any;
734
-
735
- const rule = requireJSDocRule.create(mockContext);
736
-
737
- const mockNode: any = {
738
- type: 'ClassDeclaration',
739
- id: { name: 'Undocumented' },
740
- loc: { start: { line: 1 } },
741
- };
742
- mockNode.parent = exportNode;
743
- exportNode.declaration = mockNode;
744
-
745
- rule.ClassDeclaration(mockNode);
746
-
747
- expect(reportCalled).toBe(true);
748
- });
749
-
750
- it('| should report when abstract class is missing JSDoc', () => {
751
- let reportCalled = false;
752
- const mockContext = {
753
- report: (options: any) => {
754
- reportCalled = true;
755
- expect(options.data.type).toBe('Class');
756
- expect(options.data.name).toBe('AbstractClass');
757
- },
758
- options: [{ scope: 'public' }],
759
- sourceCode: {
760
- getCommentsBefore: () => [],
761
- },
762
- } as any;
763
-
764
- const rule = requireJSDocRule.create(mockContext);
765
-
766
- const mockNode = {
767
- type: 'ClassDeclaration',
768
- id: { name: 'AbstractClass' },
769
- loc: { start: { line: 1 } },
770
- parent: {
771
- type: 'ExportNamedDeclaration',
772
- },
773
- } as any;
774
-
775
- rule.ClassDeclaration(mockNode);
776
-
777
- expect(reportCalled).toBe(true);
778
- });
779
- });
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.TSTypeAliasDeclaration).toBe('function');
27
+ expect(typeof result.MethodDefinition).toBe('function');
28
+ expect(typeof result.VariableDeclarator).toBe('function');
29
+ });
30
+
31
+ it('| should not report when function has valid JSDoc', () => {
32
+ const mockContext = {
33
+ report: (options: any) => {
34
+ fail('Should not report when function has valid JSDoc');
35
+ },
36
+ options: [{ scope: 'public' }],
37
+ sourceCode: {
38
+ getCommentsBefore: () => [{
39
+ type: 'Block',
40
+ value: '* This is a test function',
41
+ loc: { end: { line: 1 } },
42
+ }],
43
+ },
44
+ } as any;
45
+
46
+ const rule = requireJSDocRule.create(mockContext);
47
+
48
+ const mockNode = {
49
+ type: 'FunctionDeclaration',
50
+ id: { name: 'testFunction' },
51
+ loc: { start: { line: 2 } },
52
+ } as any;
53
+
54
+ rule.FunctionDeclaration(mockNode);
55
+ });
56
+
57
+ it('| should report when function is missing JSDoc', () => {
58
+ let reportCalled = false;
59
+ const mockContext = {
60
+ report: (options: any) => {
61
+ reportCalled = true;
62
+ expect(options.messageId).toBe('missingJSDoc');
63
+ expect(options.data.type).toBe('Function');
64
+ expect(options.data.name).toBe('testFunction');
65
+ },
66
+ options: [{ scope: 'public' }],
67
+ sourceCode: {
68
+ getCommentsBefore: () => [],
69
+ },
70
+ } as any;
71
+
72
+ const rule = requireJSDocRule.create(mockContext);
73
+
74
+ const mockNode = {
75
+ type: 'FunctionDeclaration',
76
+ id: { name: 'testFunction' },
77
+ loc: { start: { line: 1 } },
78
+ } as any;
79
+
80
+ rule.FunctionDeclaration(mockNode);
81
+
82
+ expect(reportCalled).toBe(true);
83
+ });
84
+
85
+ it('| should report when JSDoc is empty (no description)', () => {
86
+ let reportCalled = false;
87
+ const mockContext = {
88
+ report: (options: any) => {
89
+ reportCalled = true;
90
+ expect(options.messageId).toBe('emptyJSDoc');
91
+ expect(options.data.type).toBe('Function');
92
+ expect(options.data.name).toBe('testFunction');
93
+ },
94
+ options: [{ scope: 'public' }],
95
+ sourceCode: {
96
+ getCommentsBefore: () => [{
97
+ type: 'Block',
98
+ value: '*',
99
+ loc: { end: { line: 1 } },
100
+ }],
101
+ },
102
+ } as any;
103
+
104
+ const rule = requireJSDocRule.create(mockContext);
105
+
106
+ const mockNode = {
107
+ type: 'FunctionDeclaration',
108
+ id: { name: 'testFunction' },
109
+ loc: { start: { line: 2 } },
110
+ } as any;
111
+
112
+ rule.FunctionDeclaration(mockNode);
113
+
114
+ expect(reportCalled).toBe(true);
115
+ });
116
+
117
+ it('| should report when JSDoc is not on previous line', () => {
118
+ let reportCalled = false;
119
+ const mockContext = {
120
+ report: (options: any) => {
121
+ reportCalled = true;
122
+ expect(options.messageId).toBe('invalidJSDocPosition');
123
+ expect(options.data.type).toBe('Function');
124
+ expect(options.data.name).toBe('testFunction');
125
+ },
126
+ options: [{ scope: 'public' }],
127
+ sourceCode: {
128
+ getCommentsBefore: () => [{
129
+ type: 'Block',
130
+ value: '* This is a test function',
131
+ loc: { end: { line: 1 } },
132
+ }],
133
+ },
134
+ } as any;
135
+
136
+ const rule = requireJSDocRule.create(mockContext);
137
+
138
+ const mockNode = {
139
+ type: 'FunctionDeclaration',
140
+ id: { name: 'testFunction' },
141
+ loc: { start: { line: 3 } }, // Gap between comment and function
142
+ } as any;
143
+
144
+ rule.FunctionDeclaration(mockNode);
145
+
146
+ expect(reportCalled).toBe(true);
147
+ });
148
+
149
+ it('| should report when function is not exported and scope is public', () => {
150
+ const mockContext = {
151
+ report: (options: any) => {
152
+ fail('Should not report when function is not exported in public scope');
153
+ },
154
+ options: [{ scope: 'public' }],
155
+ sourceCode: {
156
+ getCommentsBefore: () => [],
157
+ },
158
+ } as any;
159
+
160
+ const rule = requireJSDocRule.create(mockContext);
161
+
162
+ const mockNode = {
163
+ type: 'FunctionDeclaration',
164
+ id: { name: 'privateFunction' },
165
+ loc: { start: { line: 1 } },
166
+ parent: { type: 'Program', body: [] },
167
+ } as any;
168
+
169
+ rule.FunctionDeclaration(mockNode);
170
+
171
+ // In public scope, non-exported functions should not be documented
172
+ });
173
+
174
+ it('| should report when function is private and scope is all', () => {
175
+ let reportCalled = false;
176
+ const mockContext = {
177
+ report: (options: any) => {
178
+ reportCalled = true;
179
+ expect(options.messageId).toBe('missingJSDoc');
180
+ },
181
+ options: [{ scope: 'all' }],
182
+ sourceCode: {
183
+ getCommentsBefore: () => [],
184
+ },
185
+ } as any;
186
+
187
+ const rule = requireJSDocRule.create(mockContext);
188
+
189
+ const mockNode = {
190
+ type: 'FunctionDeclaration',
191
+ id: { name: 'privateFunction' },
192
+ loc: { start: { line: 1 } },
193
+ } as any;
194
+
195
+ rule.FunctionDeclaration(mockNode);
196
+
197
+ expect(reportCalled).toBe(true);
198
+ });
199
+
200
+ it('| should handle class declarations', () => {
201
+ let reportCalled = false;
202
+ const mockContext = {
203
+ report: (options: any) => {
204
+ reportCalled = true;
205
+ expect(options.data.type).toBe('Class');
206
+ expect(options.data.name).toBe('TestClass');
207
+ },
208
+ options: [{ scope: 'public' }],
209
+ sourceCode: {
210
+ getCommentsBefore: () => [],
211
+ },
212
+ } as any;
213
+
214
+ const rule = requireJSDocRule.create(mockContext);
215
+
216
+ const mockNode = {
217
+ type: 'ClassDeclaration',
218
+ id: { name: 'TestClass' },
219
+ loc: { start: { line: 1 } },
220
+ } as any;
221
+
222
+ rule.ClassDeclaration(mockNode);
223
+
224
+ expect(reportCalled).toBe(true);
225
+ });
226
+
227
+ it('| should handle interface declarations', () => {
228
+ let reportCalled = false;
229
+ const mockContext = {
230
+ report: (options: any) => {
231
+ reportCalled = true;
232
+ expect(options.data.type).toBe('Interface');
233
+ expect(options.data.name).toBe('TestInterface');
234
+ },
235
+ options: [{ scope: 'public' }],
236
+ sourceCode: {
237
+ getCommentsBefore: () => [],
238
+ },
239
+ } as any;
240
+
241
+ const rule = requireJSDocRule.create(mockContext);
242
+
243
+ const mockNode = {
244
+ type: 'TSInterfaceDeclaration',
245
+ id: { name: 'TestInterface' },
246
+ loc: { start: { line: 1 } },
247
+ } as any;
248
+
249
+ rule.TSInterfaceDeclaration(mockNode, undefined, undefined);
250
+
251
+ expect(reportCalled).toBe(true);
252
+ });
253
+
254
+ it('| should handle enum declarations', () => {
255
+ let reportCalled = false;
256
+ const mockContext = {
257
+ report: (options: any) => {
258
+ reportCalled = true;
259
+ expect(options.data.type).toBe('Enum');
260
+ expect(options.data.name).toBe('TestEnum');
261
+ },
262
+ options: [{ scope: 'public' }],
263
+ sourceCode: {
264
+ getCommentsBefore: () => [],
265
+ },
266
+ } as any;
267
+
268
+ const rule = requireJSDocRule.create(mockContext);
269
+
270
+ const mockNode = {
271
+ type: 'TSEnumDeclaration',
272
+ id: { name: 'TestEnum' },
273
+ loc: { start: { line: 1 } },
274
+ } as any;
275
+
276
+ rule.TSEnumDeclaration(mockNode, undefined, undefined);
277
+
278
+ expect(reportCalled).toBe(true);
279
+ });
280
+
281
+ it('| should handle method definitions', () => {
282
+ let reportCalled = false;
283
+ const mockContext = {
284
+ report: (options: any) => {
285
+ reportCalled = true;
286
+ expect(options.data.type).toBe('Method');
287
+ expect(options.data.name).toBe('testMethod');
288
+ },
289
+ options: [{ scope: 'public' }],
290
+ sourceCode: {
291
+ getCommentsBefore: () => [],
292
+ },
293
+ } as any;
294
+
295
+ const rule = requireJSDocRule.create(mockContext);
296
+
297
+ const mockNode = {
298
+ type: 'MethodDefinition',
299
+ key: { name: 'testMethod' },
300
+ loc: { start: { line: 1 } },
301
+ } as any;
302
+
303
+ rule.MethodDefinition(mockNode);
304
+
305
+ expect(reportCalled).toBe(true);
306
+ });
307
+
308
+ it('| should handle function expressions in variable declarations', () => {
309
+ let reportCalled = false;
310
+ const mockContext = {
311
+ report: (options: any) => {
312
+ reportCalled = true;
313
+ expect(options.data.type).toBe('Function');
314
+ },
315
+ options: [{ scope: 'public' }],
316
+ sourceCode: {
317
+ getCommentsBefore: () => [],
318
+ },
319
+ } as any;
320
+
321
+ const rule = requireJSDocRule.create(mockContext);
322
+
323
+ const mockNode = {
324
+ type: 'VariableDeclarator',
325
+ id: { name: 'testFunction' },
326
+ init: { type: 'FunctionExpression' },
327
+ loc: { start: { line: 1 } },
328
+ } as any;
329
+
330
+ rule.VariableDeclarator(mockNode);
331
+
332
+ expect(reportCalled).toBe(true);
333
+ });
334
+
335
+ it('| should handle arrow functions in variable declarations', () => {
336
+ let reportCalled = false;
337
+ const mockContext = {
338
+ report: (options: any) => {
339
+ reportCalled = true;
340
+ expect(options.data.type).toBe('Function');
341
+ },
342
+ options: [{ scope: 'public' }],
343
+ sourceCode: {
344
+ getCommentsBefore: () => [],
345
+ },
346
+ } as any;
347
+
348
+ const rule = requireJSDocRule.create(mockContext);
349
+
350
+ const mockNode = {
351
+ type: 'VariableDeclarator',
352
+ id: { name: 'testArrowFunction' },
353
+ init: { type: 'ArrowFunctionExpression' },
354
+ loc: { start: { line: 1 } },
355
+ } as any;
356
+
357
+ rule.VariableDeclarator(mockNode);
358
+
359
+ expect(reportCalled).toBe(true);
360
+ });
361
+
362
+ it('| should not report when variable declarator is not a function', () => {
363
+ const mockContext = {
364
+ report: (options: any) => {
365
+ fail('Should not report when variable is not a function');
366
+ },
367
+ options: [{ scope: 'public' }],
368
+ sourceCode: {
369
+ getCommentsBefore: () => [],
370
+ },
371
+ } as any;
372
+
373
+ const rule = requireJSDocRule.create(mockContext);
374
+
375
+ const mockNode = {
376
+ type: 'VariableDeclarator',
377
+ id: { name: 'testVariable' },
378
+ init: { type: 'Literal', value: 'test' },
379
+ loc: { start: { line: 1 } },
380
+ } as any;
381
+
382
+ rule.VariableDeclarator(mockNode);
383
+ });
384
+
385
+ it('| should handle JSDoc with @param tags', () => {
386
+ const mockContext = {
387
+ report: (options: any) => {
388
+ fail('Should not report when JSDoc has description and @param tags');
389
+ },
390
+ options: [{ scope: 'public' }],
391
+ sourceCode: {
392
+ getCommentsBefore: () => [{
393
+ type: 'Block',
394
+ value: '* This function does something\n* @param {string} name The name parameter',
395
+ loc: { end: { line: 1 } },
396
+ }],
397
+ },
398
+ } as any;
399
+
400
+ const rule = requireJSDocRule.create(mockContext);
401
+
402
+ const mockNode = {
403
+ type: 'FunctionDeclaration',
404
+ id: { name: 'testFunction' },
405
+ loc: { start: { line: 2 } },
406
+ } as any;
407
+
408
+ rule.FunctionDeclaration(mockNode);
409
+ });
410
+
411
+ it('| should handle JSDoc with only @param tags (no description)', () => {
412
+ let reportCalled = false;
413
+ const mockContext = {
414
+ report: (options: any) => {
415
+ reportCalled = true;
416
+ expect(options.messageId).toBe('emptyJSDoc');
417
+ },
418
+ options: [{ scope: 'public' }],
419
+ sourceCode: {
420
+ getCommentsBefore: () => [{
421
+ type: 'Block',
422
+ value: '* @param {string} name The name parameter',
423
+ loc: { end: { line: 1 } },
424
+ }],
425
+ },
426
+ } as any;
427
+
428
+ const rule = requireJSDocRule.create(mockContext);
429
+
430
+ const mockNode = {
431
+ type: 'FunctionDeclaration',
432
+ id: { name: 'testFunction' },
433
+ loc: { start: { line: 2 } },
434
+ } as any;
435
+
436
+ rule.FunctionDeclaration(mockNode);
437
+
438
+ expect(reportCalled).toBe(true);
439
+ });
440
+
441
+ it('| should handle default scope when no options provided', () => {
442
+ let reportCalled = false;
443
+ const mockContext = {
444
+ report: (options: any) => {
445
+ reportCalled = true;
446
+ expect(options.messageId).toBe('missingJSDoc');
447
+ },
448
+ options: [],
449
+ sourceCode: {
450
+ getCommentsBefore: () => [],
451
+ },
452
+ } as any;
453
+
454
+ const rule = requireJSDocRule.create(mockContext);
455
+
456
+ const mockNode = {
457
+ type: 'FunctionDeclaration',
458
+ id: { name: 'testFunction' },
459
+ loc: { start: { line: 1 } },
460
+ } as any;
461
+
462
+ rule.FunctionDeclaration(mockNode);
463
+
464
+ expect(reportCalled).toBe(true);
465
+ });
466
+
467
+ it('| should handle error cases gracefully', () => {
468
+ const mockContext = {
469
+ report: () => {},
470
+ options: [{ scope: 'public' }],
471
+ sourceCode: {
472
+ getCommentsBefore: () => {
473
+ throw new Error('Source code error');
474
+ },
475
+ },
476
+ } as any;
477
+
478
+ const rule = requireJSDocRule.create(mockContext);
479
+
480
+ const mockNode = {
481
+ type: 'FunctionDeclaration',
482
+ id: { name: 'testFunction' },
483
+ loc: { start: { line: 1 } },
484
+ } as any;
485
+
486
+ // Should not throw error
487
+ expect(() => {
488
+ rule.FunctionDeclaration(mockNode);
489
+ }).not.toThrow();
490
+ });
491
+
492
+ it('| should handle anonymous functions', () => {
493
+ let reportCalled = false;
494
+ const mockContext = {
495
+ report: (options: any) => {
496
+ reportCalled = true;
497
+ expect(options.data.name).toBe('anonymous');
498
+ },
499
+ options: [{ scope: 'public' }],
500
+ sourceCode: {
501
+ getCommentsBefore: () => [],
502
+ },
503
+ } as any;
504
+
505
+ const rule = requireJSDocRule.create(mockContext);
506
+
507
+ const mockNode = {
508
+ type: 'FunctionDeclaration',
509
+ id: null, // Anonymous function
510
+ loc: { start: { line: 1 } },
511
+ } as any;
512
+
513
+ rule.FunctionDeclaration(mockNode);
514
+
515
+ expect(reportCalled).toBe(true);
516
+ });
517
+
518
+ it('| should handle multiline JSDoc descriptions', () => {
519
+ const mockContext = {
520
+ report: (options: any) => {
521
+ fail('Should not report when JSDoc has multiline description');
522
+ },
523
+ options: [{ scope: 'public' }],
524
+ sourceCode: {
525
+ getCommentsBefore: () => [{
526
+ type: 'Block',
527
+ value: '* This is a multiline\n* description for the function\n* that explains what it does',
528
+ loc: { end: { line: 1 } },
529
+ }],
530
+ },
531
+ } as any;
532
+
533
+ const rule = requireJSDocRule.create(mockContext);
534
+
535
+ const mockNode = {
536
+ type: 'FunctionDeclaration',
537
+ id: { name: 'testFunction' },
538
+ loc: { start: { line: 2 } },
539
+ } as any;
540
+
541
+ rule.FunctionDeclaration(mockNode);
542
+ });
543
+
544
+ it('| should handle abstract class with multiline JSDoc', () => {
545
+ const mockContext = {
546
+ report: (options: any) => {
547
+ fail('Should not report when abstract class has multiline JSDoc');
548
+ },
549
+ options: [{ scope: 'public' }],
550
+ sourceCode: {
551
+ getCommentsBefore: () => [{
552
+ type: 'Block',
553
+ value: '* Abstract data service osztály a user műveletek kezeléséhez.\n* Kezeli a login, register, validation és egyéb user-rel kapcsolatos műveleteket.',
554
+ loc: { end: { line: 3 } },
555
+ }],
556
+ },
557
+ } as any;
558
+
559
+ const rule = requireJSDocRule.create(mockContext);
560
+
561
+ const mockNode = {
562
+ type: 'ClassDeclaration',
563
+ id: { name: 'FDPNTS_User_DataService' },
564
+ loc: { start: { line: 4 } },
565
+ parent: {
566
+ type: 'ExportNamedDeclaration',
567
+ },
568
+ } as any;
569
+
570
+ rule.ClassDeclaration(mockNode);
571
+ });
572
+
573
+ it('| should handle multiline JSDoc with empty lines', () => {
574
+ const mockContext = {
575
+ report: (options: any) => {
576
+ fail('Should not report when JSDoc has multiline description with empty lines');
577
+ },
578
+ options: [{ scope: 'public' }],
579
+ sourceCode: {
580
+ getCommentsBefore: () => [{
581
+ type: 'Block',
582
+ value: '* This is a multiline description\n*\n* with empty lines in between\n* that should still be valid',
583
+ loc: { end: { line: 4 } },
584
+ }],
585
+ },
586
+ } as any;
587
+
588
+ const rule = requireJSDocRule.create(mockContext);
589
+
590
+ const mockNode = {
591
+ type: 'FunctionDeclaration',
592
+ id: { name: 'testFunction' },
593
+ loc: { start: { line: 5 } },
594
+ } as any;
595
+
596
+ rule.FunctionDeclaration(mockNode);
597
+ });
598
+
599
+ it('| should handle multiline JSDoc followed by @tags', () => {
600
+ const mockContext = {
601
+ report: (options: any) => {
602
+ fail('Should not report when JSDoc has description before @tags');
603
+ },
604
+ options: [{ scope: 'public' }],
605
+ sourceCode: {
606
+ getCommentsBefore: () => [{
607
+ type: 'Block',
608
+ value: '* This is a description\n* that spans multiple lines\n* @param {string} name The name parameter',
609
+ loc: { end: { line: 2 } },
610
+ }],
611
+ },
612
+ } as any;
613
+
614
+ const rule = requireJSDocRule.create(mockContext);
615
+
616
+ const mockNode = {
617
+ type: 'FunctionDeclaration',
618
+ id: { name: 'testFunction' },
619
+ loc: { start: { line: 3 } },
620
+ } as any;
621
+
622
+ rule.FunctionDeclaration(mockNode);
623
+ });
624
+
625
+ it('| should find JSDoc on the export wrapper for `export class X`', () => {
626
+ // A belso ClassDeclaration ele NINCS comment — csak az ExportNamedDeclaration ele.
627
+ // A fix nelkul a szabaly tevesen "missingJSDoc"-ot jelez.
628
+ const jsdoc = {
629
+ type: 'Block',
630
+ value: '* Exported class with JSDoc above the export keyword.',
631
+ loc: { end: { line: 1 } },
632
+ };
633
+ const exportNode: any = { type: 'ExportNamedDeclaration' };
634
+ const mockContext = {
635
+ report: () => {
636
+ fail('Should not report — JSDoc is present above the export wrapper');
637
+ },
638
+ options: [{ scope: 'public' }],
639
+ sourceCode: {
640
+ getCommentsBefore: (anchor: any): any[] => (anchor === exportNode ? [ jsdoc ] : []),
641
+ },
642
+ } as any;
643
+
644
+ const rule = requireJSDocRule.create(mockContext);
645
+
646
+ const mockNode: any = {
647
+ type: 'ClassDeclaration',
648
+ id: { name: 'X' },
649
+ loc: { start: { line: 2 } },
650
+ };
651
+ mockNode.parent = exportNode;
652
+ exportNode.declaration = mockNode;
653
+
654
+ rule.ClassDeclaration(mockNode);
655
+ });
656
+
657
+ it('| should find JSDoc on the export wrapper for an arrow-const function', () => {
658
+ const jsdoc = {
659
+ type: 'Block',
660
+ value: '* Arrow-const with explicit JSDoc above the export.',
661
+ loc: { end: { line: 1 } },
662
+ };
663
+ const varDecl: any = { type: 'VariableDeclaration' };
664
+ const exportNode: any = { type: 'ExportNamedDeclaration', declaration: varDecl };
665
+ varDecl.parent = exportNode;
666
+
667
+ const mockContext = {
668
+ report: () => {
669
+ fail('Should not report — arrow-const JSDoc is present above the export');
670
+ },
671
+ options: [{ scope: 'public' }],
672
+ sourceCode: {
673
+ getCommentsBefore: (anchor: any): any[] => (anchor === exportNode ? [ jsdoc ] : []),
674
+ },
675
+ } as any;
676
+
677
+ const rule = requireJSDocRule.create(mockContext);
678
+
679
+ const mockNode: any = {
680
+ type: 'VariableDeclarator',
681
+ id: { name: 'fn' },
682
+ init: { type: 'ArrowFunctionExpression' },
683
+ loc: { start: { line: 2 } },
684
+ parent: varDecl,
685
+ };
686
+
687
+ rule.VariableDeclarator(mockNode);
688
+ });
689
+
690
+ it('| should find JSDoc above a decorator stack', () => {
691
+ const jsdoc = {
692
+ type: 'Block',
693
+ value: '* Decorated component with JSDoc above the decorator.',
694
+ loc: { end: { line: 1 } },
695
+ };
696
+ const decorator: any = { type: 'Decorator' };
697
+
698
+ const mockContext = {
699
+ report: () => {
700
+ fail('Should not report — JSDoc is present above the decorator stack');
701
+ },
702
+ options: [{ scope: 'public' }],
703
+ sourceCode: {
704
+ getCommentsBefore: (anchor: any): any[] => (anchor === decorator ? [ jsdoc ] : []),
705
+ },
706
+ } as any;
707
+
708
+ const rule = requireJSDocRule.create(mockContext);
709
+
710
+ const mockNode: any = {
711
+ type: 'ClassDeclaration',
712
+ id: { name: 'X' },
713
+ loc: { start: { line: 2 } },
714
+ decorators: [ decorator ],
715
+ };
716
+
717
+ rule.ClassDeclaration(mockNode);
718
+ });
719
+
720
+ it('| should still report a genuinely missing JSDoc on an export-wrapped class', () => {
721
+ let reportCalled = false;
722
+ const exportNode: any = { type: 'ExportNamedDeclaration' };
723
+ const mockContext = {
724
+ report: (options: any) => {
725
+ reportCalled = true;
726
+ expect(options.messageId).toBe('missingJSDoc');
727
+ expect(options.data.name).toBe('Undocumented');
728
+ },
729
+ options: [{ scope: 'public' }],
730
+ sourceCode: {
731
+ getCommentsBefore: (): any[] => [],
732
+ },
733
+ } as any;
734
+
735
+ const rule = requireJSDocRule.create(mockContext);
736
+
737
+ const mockNode: any = {
738
+ type: 'ClassDeclaration',
739
+ id: { name: 'Undocumented' },
740
+ loc: { start: { line: 1 } },
741
+ };
742
+ mockNode.parent = exportNode;
743
+ exportNode.declaration = mockNode;
744
+
745
+ rule.ClassDeclaration(mockNode);
746
+
747
+ expect(reportCalled).toBe(true);
748
+ });
749
+
750
+ it('| should report when abstract class is missing JSDoc', () => {
751
+ let reportCalled = false;
752
+ const mockContext = {
753
+ report: (options: any) => {
754
+ reportCalled = true;
755
+ expect(options.data.type).toBe('Class');
756
+ expect(options.data.name).toBe('AbstractClass');
757
+ },
758
+ options: [{ scope: 'public' }],
759
+ sourceCode: {
760
+ getCommentsBefore: () => [],
761
+ },
762
+ } as any;
763
+
764
+ const rule = requireJSDocRule.create(mockContext);
765
+
766
+ const mockNode = {
767
+ type: 'ClassDeclaration',
768
+ id: { name: 'AbstractClass' },
769
+ loc: { start: { line: 1 } },
770
+ parent: {
771
+ type: 'ExportNamedDeclaration',
772
+ },
773
+ } as any;
774
+
775
+ rule.ClassDeclaration(mockNode);
776
+
777
+ expect(reportCalled).toBe(true);
778
+ });
779
+ });