@futdevpro/dynamo-eslint 1.14.6 → 1.14.8

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 (61) hide show
  1. package/build/configs/base.js +12 -1
  2. package/build/configs/base.js.map +1 -1
  3. package/build/plugin/index.d.ts +8 -0
  4. package/build/plugin/index.d.ts.map +1 -1
  5. package/build/plugin/index.js +12 -0
  6. package/build/plugin/index.js.map +1 -1
  7. package/build/plugin/rules/explicit-types.js +2 -2
  8. package/build/plugin/rules/explicit-types.js.map +1 -1
  9. package/build/plugin/rules/import/import-order.d.ts.map +1 -1
  10. package/build/plugin/rules/import/import-order.js +41 -10
  11. package/build/plugin/rules/import/import-order.js.map +1 -1
  12. package/build/plugin/rules/import/import-order.spec.js +17 -1
  13. package/build/plugin/rules/import/import-order.spec.js.map +1 -1
  14. package/build/plugin/rules/prefer-enum-over-string-union.d.ts +4 -0
  15. package/build/plugin/rules/prefer-enum-over-string-union.d.ts.map +1 -0
  16. package/build/plugin/rules/prefer-enum-over-string-union.js +290 -0
  17. package/build/plugin/rules/prefer-enum-over-string-union.js.map +1 -0
  18. package/build/plugin/rules/prefer-enum-over-string-union.spec.d.ts +2 -0
  19. package/build/plugin/rules/prefer-enum-over-string-union.spec.d.ts.map +1 -0
  20. package/build/plugin/rules/prefer-enum-over-string-union.spec.js +505 -0
  21. package/build/plugin/rules/prefer-enum-over-string-union.spec.js.map +1 -0
  22. package/build/plugin/rules/prefer-interface-over-duplicate-types.d.ts +4 -0
  23. package/build/plugin/rules/prefer-interface-over-duplicate-types.d.ts.map +1 -0
  24. package/build/plugin/rules/prefer-interface-over-duplicate-types.js +231 -0
  25. package/build/plugin/rules/prefer-interface-over-duplicate-types.js.map +1 -0
  26. package/build/plugin/rules/prefer-interface-over-duplicate-types.spec.d.ts +2 -0
  27. package/build/plugin/rules/prefer-interface-over-duplicate-types.spec.d.ts.map +1 -0
  28. package/build/plugin/rules/prefer-interface-over-duplicate-types.spec.js +324 -0
  29. package/build/plugin/rules/prefer-interface-over-duplicate-types.spec.js.map +1 -0
  30. package/build/plugin/rules/require-jsdoc-description.d.ts +4 -0
  31. package/build/plugin/rules/require-jsdoc-description.d.ts.map +1 -0
  32. package/build/plugin/rules/require-jsdoc-description.js +379 -0
  33. package/build/plugin/rules/require-jsdoc-description.js.map +1 -0
  34. package/build/plugin/rules/require-jsdoc-description.spec.d.ts +2 -0
  35. package/build/plugin/rules/require-jsdoc-description.spec.d.ts.map +1 -0
  36. package/build/plugin/rules/require-jsdoc-description.spec.js +452 -0
  37. package/build/plugin/rules/require-jsdoc-description.spec.js.map +1 -0
  38. package/build/plugin/rules/require-test-description-prefix.d.ts +4 -0
  39. package/build/plugin/rules/require-test-description-prefix.d.ts.map +1 -0
  40. package/build/plugin/rules/require-test-description-prefix.js +135 -0
  41. package/build/plugin/rules/require-test-description-prefix.js.map +1 -0
  42. package/build/plugin/rules/require-test-description-prefix.spec.d.ts +2 -0
  43. package/build/plugin/rules/require-test-description-prefix.spec.d.ts.map +1 -0
  44. package/build/plugin/rules/require-test-description-prefix.spec.js +371 -0
  45. package/build/plugin/rules/require-test-description-prefix.spec.js.map +1 -0
  46. package/futdevpro-dynamo-eslint-1.14.8.tgz +0 -0
  47. package/package.json +1 -1
  48. package/src/configs/base.ts +12 -1
  49. package/src/plugin/index.ts +12 -0
  50. package/src/plugin/rules/explicit-types.ts +2 -2
  51. package/src/plugin/rules/import/import-order.spec.ts +17 -1
  52. package/src/plugin/rules/import/import-order.ts +47 -10
  53. package/src/plugin/rules/prefer-enum-over-string-union.spec.ts +583 -0
  54. package/src/plugin/rules/prefer-enum-over-string-union.ts +333 -0
  55. package/src/plugin/rules/prefer-interface-over-duplicate-types.spec.ts +374 -0
  56. package/src/plugin/rules/prefer-interface-over-duplicate-types.ts +276 -0
  57. package/src/plugin/rules/require-jsdoc-description.spec.ts +542 -0
  58. package/src/plugin/rules/require-jsdoc-description.ts +436 -0
  59. package/src/plugin/rules/require-test-description-prefix.spec.ts +459 -0
  60. package/src/plugin/rules/require-test-description-prefix.ts +153 -0
  61. package/futdevpro-dynamo-eslint-1.14.6.tgz +0 -0
@@ -0,0 +1,436 @@
1
+ import { Rule } from 'eslint';
2
+
3
+ interface RuleOptions {
4
+ scope?: 'public' | 'all';
5
+ }
6
+
7
+ const rule: Rule.RuleModule = {
8
+ meta: {
9
+ type: 'suggestion',
10
+ docs: {
11
+ description: 'Require JSDoc comment blocks with description for functions, classes, interfaces, and enums',
12
+ recommended: true,
13
+ },
14
+ schema: [
15
+ {
16
+ type: 'object',
17
+ properties: {
18
+ scope: {
19
+ type: 'string',
20
+ enum: [ 'public', 'all' ],
21
+ default: 'public',
22
+ },
23
+ },
24
+ additionalProperties: false,
25
+ },
26
+ ],
27
+ messages: {
28
+ missingJSDoc: '{{type}} "{{name}}" must have a JSDoc comment with description.',
29
+ emptyJSDoc: '{{type}} "{{name}}" JSDoc comment must contain description text.',
30
+ invalidJSDocPosition: '{{type}} "{{name}}" JSDoc comment must be on the line immediately before.',
31
+ },
32
+ },
33
+ create(context) {
34
+ const options: RuleOptions = context.options[0] || {};
35
+ const scope: string = options.scope || 'public';
36
+ const sourceCode: any = context.sourceCode;
37
+
38
+ /**
39
+ * Check if a node is public/exported (should be documented)
40
+ */
41
+ function isPublic(node: any): boolean {
42
+ try {
43
+ // Check if node itself is exported
44
+ if (node.parent && node.parent.type === 'ExportNamedDeclaration') {
45
+ return true;
46
+ }
47
+
48
+ if (node.parent && node.parent.type === 'ExportDefaultDeclaration') {
49
+ return true;
50
+ }
51
+
52
+ // Check for export keyword in declaration
53
+ if (node.type === 'FunctionDeclaration' && node.parent &&
54
+ node.parent.type === 'Program' && node.id) {
55
+ // Top-level function - check if exported
56
+ const program: any = node.parent;
57
+
58
+ if (program.body && Array.isArray(program.body)) {
59
+ for (const statement of program.body) {
60
+ if (statement.type === 'ExportNamedDeclaration' &&
61
+ statement.declaration === node) {
62
+ return true;
63
+ }
64
+ }
65
+ }
66
+ }
67
+
68
+ // For class members, check accessibility modifiers
69
+ if (node.type === 'MethodDefinition' || node.type === 'PropertyDefinition') {
70
+ // If has private modifier, it's not public
71
+ if (node.accessibility === 'private') {
72
+ return false;
73
+ }
74
+
75
+ // If has protected modifier, it's not public
76
+ if (node.accessibility === 'protected') {
77
+ return false;
78
+ }
79
+
80
+ // Default to public if no modifiers
81
+ return true;
82
+ }
83
+
84
+ // For top-level declarations, check if they're exported
85
+ if (node.parent && node.parent.type === 'Program') {
86
+ // Check if this declaration is exported
87
+ const program: any = node.parent;
88
+
89
+ if (program.body && Array.isArray(program.body)) {
90
+ for (const statement of program.body) {
91
+ if (statement.type === 'ExportNamedDeclaration' &&
92
+ statement.declaration === node) {
93
+ return true;
94
+ }
95
+
96
+ if (statement.type === 'ExportDefaultDeclaration' &&
97
+ statement.declaration === node) {
98
+ return true;
99
+ }
100
+ }
101
+ }
102
+
103
+ return false; // Not exported
104
+ }
105
+
106
+ // Default to public for other cases
107
+ return true;
108
+ } catch (error) {
109
+ console.error('[require-jsdoc-description] Error in isPublic:', error);
110
+
111
+ return true; // Default to requiring documentation
112
+ }
113
+ }
114
+
115
+ /**
116
+ * Check if JSDoc comment is on the line immediately before the node
117
+ */
118
+ function isJSDocOnPreviousLine(node: any, jsdocComment: any): boolean {
119
+ try {
120
+ const nodeStart: number | undefined = node.loc?.start?.line;
121
+ const commentEnd: number | undefined = jsdocComment.loc?.end?.line;
122
+
123
+ if (!nodeStart || !commentEnd) {
124
+ return false;
125
+ }
126
+
127
+ // JSDoc should be on the line immediately before (no blank lines)
128
+ return commentEnd === nodeStart - 1;
129
+ } catch (error) {
130
+ console.error('[require-jsdoc-description] Error in isJSDocOnPreviousLine:', error);
131
+
132
+ return false;
133
+ }
134
+ }
135
+
136
+ /**
137
+ * Extract description text from JSDoc comment
138
+ */
139
+ function extractDescription(jsdocComment: any): string {
140
+ try {
141
+ if (!jsdocComment.value) {
142
+ return '';
143
+ }
144
+
145
+ const lines = jsdocComment.value.split('\n');
146
+ let description = '';
147
+
148
+ for (const line of lines) {
149
+ // Remove leading * and whitespace
150
+ const cleanLine = line.replace(/^\s*\*\s?/, '').trim();
151
+
152
+ // Skip empty lines
153
+ if (!cleanLine) {
154
+ continue;
155
+ }
156
+
157
+ // Stop at @tags
158
+ if (cleanLine.startsWith('@')) {
159
+ break;
160
+ }
161
+
162
+ // Add to description
163
+ if (description) {
164
+ description += ' ';
165
+ }
166
+ description += cleanLine;
167
+ }
168
+
169
+ return description.trim();
170
+ } catch (error) {
171
+ console.error('[require-jsdoc-description] Error in extractDescription:', error);
172
+
173
+ return '';
174
+ }
175
+ }
176
+
177
+ /**
178
+ * Check if node has valid JSDoc comment
179
+ */
180
+ function hasValidJSDoc(node: any): { hasJSDoc: boolean; isValid: boolean; isOnPreviousLine: boolean } {
181
+ try {
182
+ const comments = sourceCode.getCommentsBefore(node);
183
+
184
+ // Find JSDoc comment (/** ... */)
185
+ const jsdocComment = comments.find((comment: any) =>
186
+ comment.type === 'Block' &&
187
+ comment.value.startsWith('*')
188
+ );
189
+
190
+ if (!jsdocComment) {
191
+ return { hasJSDoc: false, isValid: false, isOnPreviousLine: false };
192
+ }
193
+
194
+ const isOnPreviousLine: boolean = isJSDocOnPreviousLine(node, jsdocComment);
195
+ const description: string = extractDescription(jsdocComment);
196
+ const isValid: boolean = description.length > 0;
197
+
198
+ return { hasJSDoc: true, isValid, isOnPreviousLine };
199
+ } catch (error) {
200
+ console.error('[require-jsdoc-description] Error in hasValidJSDoc:', error);
201
+
202
+ return { hasJSDoc: false, isValid: false, isOnPreviousLine: false };
203
+ }
204
+ }
205
+
206
+ /**
207
+ * Get node name for error messages
208
+ */
209
+ function getNodeName(node: any): string {
210
+ try {
211
+ if (node.id && node.id.name) {
212
+ return node.id.name;
213
+ }
214
+
215
+ if (node.key && node.key.name) {
216
+ return node.key.name;
217
+ }
218
+
219
+ if (node.name && node.name.name) {
220
+ return node.name.name;
221
+ }
222
+
223
+ return 'anonymous';
224
+ } catch (error) {
225
+ console.error('[require-jsdoc-description] Error in getNodeName:', error);
226
+
227
+ return 'unknown';
228
+ }
229
+ }
230
+
231
+ /**
232
+ * Get node type for error messages
233
+ */
234
+ function getNodeType(node: any): string {
235
+ try {
236
+ // Check if it's a VariableDeclarator with function expression
237
+ if (node.type === 'VariableDeclarator' && node.init) {
238
+ if (node.init.type === 'FunctionExpression' || node.init.type === 'ArrowFunctionExpression') {
239
+ return 'Function';
240
+ }
241
+ }
242
+
243
+ switch (node.type) {
244
+ case 'FunctionDeclaration':
245
+ return 'Function';
246
+ case 'FunctionExpression':
247
+ return 'Function';
248
+ case 'ArrowFunctionExpression':
249
+ return 'Function';
250
+ case 'ClassDeclaration':
251
+ return 'Class';
252
+ case 'TSInterfaceDeclaration':
253
+ return 'Interface';
254
+ case 'TSEnumDeclaration':
255
+ return 'Enum';
256
+ case 'MethodDefinition':
257
+ return 'Method';
258
+ case 'PropertyDefinition':
259
+ return 'Property';
260
+
261
+ default:
262
+ return 'Declaration';
263
+ }
264
+ } catch (error) {
265
+ console.error('[require-jsdoc-description] Error in getNodeType:', error);
266
+
267
+ return 'Declaration';
268
+ }
269
+ }
270
+
271
+ /**
272
+ * Check if node should be documented based on scope
273
+ */
274
+ function shouldBeDocumented(node: any): boolean {
275
+ try {
276
+ if (scope === 'all') {
277
+ return true;
278
+ }
279
+
280
+ if (scope === 'public') {
281
+ return isPublic(node);
282
+ }
283
+
284
+ return true; // Default to requiring documentation
285
+ } catch (error) {
286
+ console.error('[require-jsdoc-description] Error in shouldBeDocumented:', error);
287
+
288
+ return true;
289
+ }
290
+ }
291
+
292
+ /**
293
+ * Report missing or invalid JSDoc
294
+ */
295
+ function reportJSDocIssue(
296
+ node: any,
297
+ jsdocResult: { hasJSDoc: boolean; isValid: boolean; isOnPreviousLine: boolean }
298
+ ): void {
299
+ try {
300
+ const name = getNodeName(node);
301
+ const type = getNodeType(node);
302
+
303
+ if (!jsdocResult.hasJSDoc) {
304
+ context.report({
305
+ node,
306
+ messageId: 'missingJSDoc',
307
+ data: { type, name },
308
+ });
309
+ } else if (!jsdocResult.isOnPreviousLine) {
310
+ context.report({
311
+ node,
312
+ messageId: 'invalidJSDocPosition',
313
+ data: { type, name },
314
+ });
315
+ } else if (!jsdocResult.isValid) {
316
+ context.report({
317
+ node,
318
+ messageId: 'emptyJSDoc',
319
+ data: { type, name },
320
+ });
321
+ }
322
+ } catch (error) {
323
+ console.error('[require-jsdoc-description] Error in reportJSDocIssue:', error);
324
+ }
325
+ }
326
+
327
+ return {
328
+ // Function declarations
329
+ FunctionDeclaration(node: any): void {
330
+ try {
331
+ if (!shouldBeDocumented(node)) {
332
+ return;
333
+ }
334
+
335
+ const jsdocResult = hasValidJSDoc(node);
336
+
337
+ if (!jsdocResult.hasJSDoc || !jsdocResult.isValid || !jsdocResult.isOnPreviousLine) {
338
+ reportJSDocIssue(node, jsdocResult);
339
+ }
340
+ } catch (error) {
341
+ console.error('[require-jsdoc-description] Error in FunctionDeclaration visitor:', error);
342
+ }
343
+ },
344
+
345
+ // Function expressions (when assigned to variables)
346
+ VariableDeclarator(node: any): void {
347
+ try {
348
+ if (node.init &&
349
+ (node.init.type === 'FunctionExpression' || node.init.type === 'ArrowFunctionExpression')) {
350
+ if (!shouldBeDocumented(node)) {
351
+ return;
352
+ }
353
+
354
+ const jsdocResult = hasValidJSDoc(node);
355
+
356
+ if (!jsdocResult.hasJSDoc || !jsdocResult.isValid || !jsdocResult.isOnPreviousLine) {
357
+ reportJSDocIssue(node, jsdocResult);
358
+ }
359
+ }
360
+ } catch (error) {
361
+ console.error('[require-jsdoc-description] Error in VariableDeclarator visitor:', error);
362
+ }
363
+ },
364
+
365
+ // Class declarations
366
+ ClassDeclaration(node: any): void {
367
+ try {
368
+ if (!shouldBeDocumented(node)) {
369
+ return;
370
+ }
371
+
372
+ const jsdocResult = hasValidJSDoc(node);
373
+
374
+ if (!jsdocResult.hasJSDoc || !jsdocResult.isValid || !jsdocResult.isOnPreviousLine) {
375
+ reportJSDocIssue(node, jsdocResult);
376
+ }
377
+ } catch (error) {
378
+ console.error('[require-jsdoc-description] Error in ClassDeclaration visitor:', error);
379
+ }
380
+ },
381
+
382
+ // Interface declarations
383
+ TSInterfaceDeclaration(node: any): void {
384
+ try {
385
+ if (!shouldBeDocumented(node)) {
386
+ return;
387
+ }
388
+
389
+ const jsdocResult = hasValidJSDoc(node);
390
+
391
+ if (!jsdocResult.hasJSDoc || !jsdocResult.isValid || !jsdocResult.isOnPreviousLine) {
392
+ reportJSDocIssue(node, jsdocResult);
393
+ }
394
+ } catch (error) {
395
+ console.error('[require-jsdoc-description] Error in TSInterfaceDeclaration visitor:', error);
396
+ }
397
+ },
398
+
399
+ // Enum declarations
400
+ TSEnumDeclaration(node: any): void {
401
+ try {
402
+ if (!shouldBeDocumented(node)) {
403
+ return;
404
+ }
405
+
406
+ const jsdocResult = hasValidJSDoc(node);
407
+
408
+ if (!jsdocResult.hasJSDoc || !jsdocResult.isValid || !jsdocResult.isOnPreviousLine) {
409
+ reportJSDocIssue(node, jsdocResult);
410
+ }
411
+ } catch (error) {
412
+ console.error('[require-jsdoc-description] Error in TSEnumDeclaration visitor:', error);
413
+ }
414
+ },
415
+
416
+ // Class methods
417
+ MethodDefinition(node: any): void {
418
+ try {
419
+ if (!shouldBeDocumented(node)) {
420
+ return;
421
+ }
422
+
423
+ const jsdocResult = hasValidJSDoc(node);
424
+
425
+ if (!jsdocResult.hasJSDoc || !jsdocResult.isValid || !jsdocResult.isOnPreviousLine) {
426
+ reportJSDocIssue(node, jsdocResult);
427
+ }
428
+ } catch (error) {
429
+ console.error('[require-jsdoc-description] Error in MethodDefinition visitor:', error);
430
+ }
431
+ },
432
+ };
433
+ },
434
+ };
435
+
436
+ export default rule;