@futdevpro/dynamo-eslint 1.14.3 → 1.14.6

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/.eslintrc.json +4 -0
  2. package/.vscode/settings.json +11 -0
  3. package/README.md +17 -2
  4. package/build/configs/base.js +19 -7
  5. package/build/configs/base.js.map +1 -1
  6. package/build/plugin/index.d.ts +2 -0
  7. package/build/plugin/index.d.ts.map +1 -1
  8. package/build/plugin/index.js +3 -0
  9. package/build/plugin/index.js.map +1 -1
  10. package/build/plugin/rules/explicit-types.d.ts +4 -0
  11. package/build/plugin/rules/explicit-types.d.ts.map +1 -0
  12. package/build/plugin/rules/explicit-types.js +179 -0
  13. package/build/plugin/rules/explicit-types.js.map +1 -0
  14. package/build/plugin/rules/explicit-types.spec.d.ts +2 -0
  15. package/build/plugin/rules/explicit-types.spec.d.ts.map +1 -0
  16. package/build/plugin/rules/explicit-types.spec.js +162 -0
  17. package/build/plugin/rules/explicit-types.spec.js.map +1 -0
  18. package/build/plugin/rules/import/import-order.d.ts.map +1 -1
  19. package/build/plugin/rules/import/import-order.js +0 -9
  20. package/build/plugin/rules/import/import-order.js.map +1 -1
  21. package/build/plugin/rules/import/no-import-type.d.ts.map +1 -1
  22. package/build/plugin/rules/import/no-import-type.js +23 -12
  23. package/build/plugin/rules/import/no-import-type.js.map +1 -1
  24. package/build/plugin/rules/import/no-js-import.d.ts.map +1 -1
  25. package/build/plugin/rules/import/no-js-import.js +19 -11
  26. package/build/plugin/rules/import/no-js-import.js.map +1 -1
  27. package/build/plugin/rules/naming-patterns.d.ts.map +1 -1
  28. package/build/plugin/rules/naming-patterns.js +7 -2
  29. package/build/plugin/rules/naming-patterns.js.map +1 -1
  30. package/build/scripts/dynamo-fix.d.ts +24 -0
  31. package/build/scripts/dynamo-fix.d.ts.map +1 -1
  32. package/build/scripts/dynamo-fix.js +57 -2
  33. package/build/scripts/dynamo-fix.js.map +1 -1
  34. package/build/scripts/eslintrc-audit.d.ts +24 -0
  35. package/build/scripts/eslintrc-audit.d.ts.map +1 -1
  36. package/build/scripts/eslintrc-audit.js +65 -0
  37. package/build/scripts/eslintrc-audit.js.map +1 -1
  38. package/build/scripts/fix-return-types.d.ts +25 -0
  39. package/build/scripts/fix-return-types.d.ts.map +1 -1
  40. package/build/scripts/fix-return-types.js +80 -9
  41. package/build/scripts/fix-return-types.js.map +1 -1
  42. package/build/scripts/validate-imports.d.ts +24 -0
  43. package/build/scripts/validate-imports.d.ts.map +1 -1
  44. package/build/scripts/validate-imports.js +62 -1
  45. package/build/scripts/validate-imports.js.map +1 -1
  46. package/build/scripts/validate-naming.d.ts +24 -0
  47. package/build/scripts/validate-naming.d.ts.map +1 -1
  48. package/build/scripts/validate-naming.js +72 -9
  49. package/build/scripts/validate-naming.js.map +1 -1
  50. package/eslint.config.js +9 -49
  51. package/futdevpro-dynamo-eslint-1.14.6.tgz +0 -0
  52. package/package.json +1 -1
  53. package/samples/package.json.example +1 -1
  54. package/src/configs/base.ts +34 -22
  55. package/src/plugin/index.ts +3 -0
  56. package/src/plugin/rules/explicit-types.spec.ts +190 -0
  57. package/src/plugin/rules/explicit-types.ts +186 -0
  58. package/src/plugin/rules/import/import-order.ts +0 -9
  59. package/src/plugin/rules/import/no-import-type.ts +21 -12
  60. package/src/plugin/rules/import/no-js-import.ts +25 -15
  61. package/src/plugin/rules/naming-patterns.ts +6 -2
  62. package/src/scripts/dynamo-fix.ts +66 -2
  63. package/src/scripts/eslintrc-audit.ts +79 -6
  64. package/src/scripts/fix-return-types.ts +91 -9
  65. package/src/scripts/validate-imports.ts +71 -2
  66. package/src/scripts/validate-naming.ts +108 -17
  67. package/futdevpro-dynamo-eslint-01.14.3.tgz +0 -0
@@ -1,17 +1,63 @@
1
1
  #!/usr/bin/env node
2
+ /**
3
+ * @fileoverview Dynamo ESLint Auto-Fix Script
4
+ *
5
+ * This script runs ESLint with auto-fix capabilities on TypeScript files across the project.
6
+ * It processes all .ts and .tsx files, applies Dynamo-specific rules, and automatically
7
+ * fixes issues where possible.
8
+ *
9
+ * @usage
10
+ * ```bash
11
+ * dynamo-fix
12
+ * ```
13
+ *
14
+ * @example
15
+ * ```bash
16
+ * # Fix all TypeScript files in the project
17
+ * npx dynamo-fix
18
+ *
19
+ * # Or run via npm script
20
+ * npm run fix
21
+ * ```
22
+ *
23
+ * @author Future Development Program Ltd.
24
+ * @version 1.14.3
25
+ */
26
+
2
27
  import fg from 'fast-glob';
3
28
  import { ESLint } from 'eslint';
4
29
  import { writeFileSync } from 'fs';
5
30
 
31
+ /**
32
+ * Result of fixing a single file
33
+ */
6
34
  interface FixResult {
35
+ /** Path to the file that was processed */
7
36
  file: string;
37
+ /** Whether the file was actually modified */
8
38
  fixed: boolean;
39
+ /** Number of errors found in the file */
9
40
  errors: number;
41
+ /** Number of warnings found in the file */
10
42
  warnings: number;
43
+ /** Number of fixes applied to the file */
11
44
  fixes: number;
12
45
  }
13
46
 
47
+ /**
48
+ * Fixes a single TypeScript file using ESLint with auto-fix capabilities
49
+ *
50
+ * @param filePath - Path to the TypeScript file to fix
51
+ * @returns Promise that resolves to a FixResult object containing fix statistics
52
+ *
53
+ * @example
54
+ * ```typescript
55
+ * const result = await fixFile('./src/components/Button.tsx');
56
+ * console.log(`Fixed ${result.fixes} issues in ${result.file}`);
57
+ * ```
58
+ */
14
59
  async function fixFile(filePath: string): Promise<FixResult> {
60
+ // Configure ESLint with Dynamo-specific rules and auto-fix enabled
15
61
  const eslint = new ESLint({
16
62
  baseConfig: [
17
63
  { ignores: [ 'build/**', 'dist/**', 'node_modules/**' ] },
@@ -38,14 +84,16 @@ async function fixFile(filePath: string): Promise<FixResult> {
38
84
  fix: true, // Enable auto-fixing
39
85
  });
40
86
 
87
+ // Run ESLint on the file
41
88
  const results = await eslint.lintFiles([ filePath ]);
42
89
  const result = results[0];
43
90
 
91
+ // Write the fixed content back to the file if changes were made
44
92
  if (result && result.output) {
45
- // Write the fixed content back to the file
46
93
  writeFileSync(filePath, result.output);
47
94
  }
48
95
 
96
+ // Return comprehensive fix statistics
49
97
  return {
50
98
  file: filePath,
51
99
  fixed: result && result.output !== undefined,
@@ -55,7 +103,18 @@ async function fixFile(filePath: string): Promise<FixResult> {
55
103
  };
56
104
  }
57
105
 
106
+ /**
107
+ * Main function that processes all TypeScript files in the project
108
+ *
109
+ * Scans for all .ts and .tsx files, applies ESLint fixes, and provides
110
+ * comprehensive reporting on the results.
111
+ *
112
+ * @returns Promise that resolves when all files have been processed
113
+ *
114
+ * @throws {Error} When file processing fails
115
+ */
58
116
  async function main() {
117
+ // Find all TypeScript files, excluding common directories and test files
59
118
  const files = await fg([ '**/*.{ts,tsx}' ], {
60
119
  ignore: [ '**/node_modules/**', '**/build/**', '**/dist/**', '**/*.spec.ts', '**/*.test.ts' ],
61
120
  });
@@ -68,17 +127,20 @@ async function main() {
68
127
  let totalWarnings = 0;
69
128
  let totalFixes = 0;
70
129
 
130
+ // Process each file individually
71
131
  for (const file of files) {
72
132
  try {
73
133
  const result = await fixFile(file);
74
134
 
75
135
  results.push(result);
76
136
 
137
+ // Track successful fixes
77
138
  if (result.fixed) {
78
139
  totalFixed++;
79
140
  console.log(`✅ Fixed: ${result.file}`);
80
141
  }
81
142
 
143
+ // Accumulate statistics
82
144
  totalErrors += result.errors;
83
145
  totalWarnings += result.warnings;
84
146
  totalFixes += result.fixes;
@@ -87,7 +149,7 @@ async function main() {
87
149
  }
88
150
  }
89
151
 
90
- // Report results
152
+ // Generate comprehensive summary report
91
153
  console.log(`\n📊 Fix Summary:`);
92
154
  console.log(` Files processed: ${files.length}`);
93
155
  console.log(` Files fixed: ${totalFixed}`);
@@ -95,6 +157,7 @@ async function main() {
95
157
  console.log(` Total warnings: ${totalWarnings}`);
96
158
  console.log(` Total fixes applied: ${totalFixes}`);
97
159
 
160
+ // Provide appropriate success/failure message
98
161
  if (totalFixed === 0) {
99
162
  console.log('✅ No files needed fixing!');
100
163
  } else {
@@ -102,6 +165,7 @@ async function main() {
102
165
  }
103
166
  }
104
167
 
168
+ // Execute the main function and handle any errors
105
169
  main().catch((err) => {
106
170
  console.error('Fix failed:', err);
107
171
  process.exit(1);
@@ -1,43 +1,116 @@
1
1
  #!/usr/bin/env node
2
+ /**
3
+ * @fileoverview ESLint Configuration Audit Script
4
+ *
5
+ * This script analyzes ESLint configuration files (.eslintrc.json) across the project
6
+ * to provide statistics on rule usage. It helps identify commonly used rules and
7
+ * potential configuration inconsistencies.
8
+ *
9
+ * @usage
10
+ * ```bash
11
+ * dynamo-eslintrc-audit
12
+ * ```
13
+ *
14
+ * @example
15
+ * ```bash
16
+ * # Audit all ESLint configurations in the project
17
+ * npx dynamo-eslintrc-audit
18
+ *
19
+ * # Or run via npm script
20
+ * npm run audit:eslintrc
21
+ * ```
22
+ *
23
+ * @author Future Development Program Ltd.
24
+ * @version 1.14.3
25
+ */
26
+
2
27
  import fg from 'fast-glob';
3
28
  import { readFileSync } from 'fs';
4
-
29
+ /** Type alias for any JSON value */
5
30
  type AnyJson = any;
6
31
 
32
+ /**
33
+ * Safely parses a JSON file and returns the parsed object or null if parsing fails
34
+ *
35
+ * @param jsonPath - Path to the JSON file to parse
36
+ * @returns Parsed JSON object or null if parsing fails
37
+ *
38
+ * @example
39
+ * ```typescript
40
+ * const config = safeParse('./.eslintrc.json');
41
+ * if (config) {
42
+ * console.log('Rules:', Object.keys(config.rules || {}));
43
+ * }
44
+ * ```
45
+ */
7
46
  function safeParse(jsonPath: string): AnyJson | null {
8
47
  try {
9
48
  const content = readFileSync(jsonPath, 'utf8');
10
49
 
11
50
  return JSON.parse(content);
12
51
  } catch {
52
+ // Return null for any parsing errors (malformed JSON, file not found, etc.)
13
53
  return null;
14
54
  }
15
55
  }
16
56
 
17
- async function main() {
18
- const files = await fg([ '**/.eslintrc.json' ], { ignore: [ '**/node_modules/**' ] });
57
+ /**
58
+ * Main function that analyzes ESLint configuration files and generates rule usage statistics
59
+ *
60
+ * Scans for all .eslintrc.json files in the project, extracts rule configurations,
61
+ * and provides a sorted table of the most commonly used rules.
62
+ *
63
+ * @returns Promise that resolves when analysis is complete
64
+ *
65
+ * @example
66
+ * ```typescript
67
+ * // The function will output a table like:
68
+ * // ┌─────────┬─────────────────────────┬───────┐
69
+ * // │ (index) │ rule │ count │
70
+ * // ├─────────┼─────────────────────────┼───────┤
71
+ * // │ 0 │ 'no-unused-vars' │ 5 │
72
+ * // │ 1 │ 'semi' │ 4 │
73
+ * // └─────────┴─────────────────────────┴───────┘
74
+ * ```
75
+ */
76
+ async function main(): Promise<void> {
77
+ // Find all ESLint configuration files, excluding node_modules
78
+ const files: string[] = await fg([ '**/.eslintrc.json' ], { ignore: [ '**/node_modules/**' ] });
19
79
  const ruleCounts: Record<string, number> = {};
20
- const total = files.length;
80
+ const total: number = files.length;
21
81
 
82
+ // Process each configuration file
22
83
  for (const p of files) {
23
84
  const cfg = safeParse(p);
24
85
 
86
+ // Skip files without rules configuration
25
87
  if (!cfg?.rules) continue;
26
88
 
89
+ // Count each rule occurrence
27
90
  for (const key of Object.keys(cfg.rules)) {
28
91
  ruleCounts[key] = (ruleCounts[key] ?? 0) + 1;
29
92
  }
30
93
  }
31
94
 
32
- const entries = Object.entries(ruleCounts).sort((a, b) => b[1] - a[1]);
95
+ // Sort rules by usage count (most used first)
96
+ const entries = Object.entries(ruleCounts).sort(
97
+ (a: [ string, number ], b: [ string, number ]): number => b[1] - a[1]
98
+ );
33
99
 
100
+ // Display results
34
101
  console.log(`[dynamo-eslintrc-audit] analyzed ${total} files`);
35
102
  console.table(entries.slice(0, 50).map(([ rule, count ]) => ({ rule, count })));
36
103
  }
37
104
 
38
- main().catch((err) => {
105
+ // Execute the main function and handle any errors
106
+ main().catch((err: Error): void => {
39
107
  console.error(err);
40
108
  process.exit(1);
41
109
  });
42
110
 
43
111
 
112
+
113
+
114
+
115
+
116
+
@@ -1,20 +1,69 @@
1
1
  #!/usr/bin/env node
2
+ /**
3
+ * @fileoverview TypeScript Type Annotation Fix Script
4
+ *
5
+ * This script uses TypeScript's AST (Abstract Syntax Tree) to automatically add
6
+ * type annotations to functions and arrow functions. It analyzes TypeScript files,
7
+ * infers return types using the TypeScript compiler, and adds explicit type
8
+ * annotations where missing.
9
+ *
10
+ * @usage
11
+ * ```bash
12
+ * dynamo-fix-return-types
13
+ * ```
14
+ *
15
+ * @example
16
+ * ```bash
17
+ * # Fix type annotations in all TypeScript files
18
+ * npx dynamo-fix-return-types
19
+ *
20
+ * # Or run via npm script
21
+ * npm run fix:types
22
+ * ```
23
+ *
24
+ * @author Future Development Program Ltd.
25
+ * @version 1.14.3
26
+ */
27
+
2
28
  import * as ts from 'typescript';
3
29
  import * as fs from 'fs';
4
30
  import * as path from 'path';
5
31
  import fg from 'fast-glob';
6
32
  import { DyFM_Log } from '@futdevpro/fsm-dynamo';
7
33
 
34
+ /**
35
+ * Result of fixing type annotations in a single file
36
+ */
8
37
  interface FixResult {
38
+ /** Path to the file that was processed */
9
39
  file: string;
40
+ /** Whether the file was actually modified */
10
41
  fixed: boolean;
42
+ /** Number of type annotations added to the file */
11
43
  changes: number;
12
44
  }
13
45
 
14
- function addReturnTypesToFile(filePath: string): FixResult {
46
+ /**
47
+ * Adds type annotations to functions and arrow functions in a TypeScript file
48
+ *
49
+ * Uses TypeScript's compiler API to analyze the file, infer return types,
50
+ * and automatically add explicit type annotations where missing.
51
+ *
52
+ * @param filePath - Path to the TypeScript file to process
53
+ * @returns FixResult object containing statistics about the changes made
54
+ *
55
+ * @example
56
+ * ```typescript
57
+ * const result = addTypesToFile('./src/utils.ts');
58
+ * console.log(`Added ${result.changes} type annotations to ${result.file}`);
59
+ * ```
60
+ */
61
+ function addTypesToFile(filePath: string): FixResult {
62
+ // Read and parse the source file
15
63
  const sourceCode = fs.readFileSync(filePath, 'utf8');
16
64
  const sourceFile = ts.createSourceFile(filePath, sourceCode, ts.ScriptTarget.Latest, true);
17
65
 
66
+ // Create TypeScript program for type checking
18
67
  const program = ts.createProgram([filePath], {
19
68
  target: ts.ScriptTarget.Latest,
20
69
  module: ts.ModuleKind.ESNext,
@@ -26,8 +75,14 @@ function addReturnTypesToFile(filePath: string): FixResult {
26
75
  let changes = 0;
27
76
  let hasChanges = false;
28
77
 
78
+ /**
79
+ * Recursively visits AST nodes and adds type annotations where needed
80
+ *
81
+ * @param node - The current AST node being visited
82
+ * @returns The potentially modified AST node
83
+ */
29
84
  function visit(node: ts.Node): ts.Node {
30
- // Handle function declarations
85
+ // Handle function declarations without return types
31
86
  if (ts.isFunctionDeclaration(node) && !node.type) {
32
87
  const signature = checker.getSignatureFromDeclaration(node);
33
88
 
@@ -35,6 +90,7 @@ function addReturnTypesToFile(filePath: string): FixResult {
35
90
  const returnType = checker.getReturnTypeOfSignature(signature);
36
91
  const typeString = checker.typeToString(returnType);
37
92
 
93
+ // Add type annotation if it's not void or any
38
94
  if (typeString !== 'void' && typeString !== 'any') {
39
95
  const newType = ts.factory.createTypeReferenceNode(typeString);
40
96
  const updatedNode = ts.factory.updateFunctionDeclaration(
@@ -54,7 +110,7 @@ function addReturnTypesToFile(filePath: string): FixResult {
54
110
  }
55
111
  }
56
112
 
57
- // Handle arrow functions
113
+ // Handle arrow functions without return types
58
114
  if (ts.isArrowFunction(node) && !node.type) {
59
115
  const signature = checker.getSignatureFromDeclaration(node);
60
116
 
@@ -62,6 +118,7 @@ function addReturnTypesToFile(filePath: string): FixResult {
62
118
  const returnType = checker.getReturnTypeOfSignature(signature);
63
119
  const typeString = checker.typeToString(returnType);
64
120
 
121
+ // Add type annotation if it's not void or any
65
122
  if (typeString !== 'void' && typeString !== 'any') {
66
123
  const newType = ts.factory.createTypeReferenceNode(typeString);
67
124
  const updatedNode = ts.factory.updateArrowFunction(
@@ -79,12 +136,18 @@ function addReturnTypesToFile(filePath: string): FixResult {
79
136
  }
80
137
  }
81
138
  }
139
+
140
+ // Note: Variable declarations, parameters, and class properties
141
+ // are handled by the existing @typescript-eslint/typedef rule
142
+ // and can be auto-fixed with eslint --fix
82
143
 
83
144
  return ts.visitEachChild(node, visit, {} as ts.TransformationContext);
84
145
  }
85
146
 
147
+ // Transform the AST and apply changes
86
148
  const result = ts.visitEachChild(sourceFile, visit, {} as ts.TransformationContext);
87
149
 
150
+ // Write the modified code back to the file if changes were made
88
151
  if (hasChanges) {
89
152
  const printer = ts.createPrinter();
90
153
  const newSourceCode = printer.printFile(result);
@@ -98,7 +161,19 @@ function addReturnTypesToFile(filePath: string): FixResult {
98
161
  };
99
162
  }
100
163
 
164
+
165
+ /**
166
+ * Main function that processes all TypeScript files and adds type annotations
167
+ *
168
+ * Scans for all .ts and .tsx files in the project, processes each file to add
169
+ * missing type annotations, and provides comprehensive reporting on the results.
170
+ *
171
+ * @returns Promise that resolves when all files have been processed
172
+ *
173
+ * @throws {Error} When file processing fails
174
+ */
101
175
  async function main() {
176
+ // Find all TypeScript files, excluding common directories and test files
102
177
  const files = await fg([ '**/*.{ts,tsx}' ], {
103
178
  ignore: [
104
179
  '**/node_modules/**',
@@ -109,40 +184,47 @@ async function main() {
109
184
  ],
110
185
  });
111
186
 
112
- DyFM_Log.log(`[fix-return-types] Processing ${files.length} files...`);
187
+ DyFM_Log.log(`[fix-types] Processing ${files.length} files...`);
113
188
 
114
189
  const results: FixResult[] = [];
115
190
  let totalFixed = 0;
116
191
  let totalChanges = 0;
117
192
 
193
+ // Process each file individually
118
194
  for (const file of files) {
119
195
  try {
120
- const result = addReturnTypesToFile(file);
196
+ const result = addTypesToFile(file);
121
197
  results.push(result);
122
198
 
199
+ // Track successful fixes
123
200
  if (result.fixed) {
124
201
  totalFixed++;
125
202
  totalChanges += result.changes;
126
- DyFM_Log.log(`✅ Fixed ${result.changes} return types in ${file}`);
203
+ DyFM_Log.log(`✅ Fixed ${result.changes} type annotations in ${file}`);
127
204
  }
128
205
  } catch (error) {
129
206
  DyFM_Log.error(`❌ Error processing ${file}:`, error);
130
207
  }
131
208
  }
132
209
 
210
+ // Generate comprehensive summary report
133
211
  DyFM_Log.log(`\n📊 Fix Summary:`);
134
212
  DyFM_Log.log(` Files processed: ${files.length}`);
135
213
  DyFM_Log.log(` Files fixed: ${totalFixed}`);
136
- DyFM_Log.log(` Total return types added: ${totalChanges}`);
214
+ DyFM_Log.log(` Total type annotations added: ${totalChanges}`);
137
215
 
216
+ // Provide appropriate success/failure message
138
217
  if (totalFixed > 0) {
139
- DyFM_Log.log(`🎉 Successfully added return types to ${totalFixed} files!`);
218
+ DyFM_Log.log(`🎉 Successfully added type annotations to ${totalFixed} files!`);
140
219
  } else {
141
- DyFM_Log.log('✅ No files needed return type fixes!');
220
+ DyFM_Log.log('✅ No files needed type annotation fixes!');
142
221
  }
143
222
  }
144
223
 
224
+ // Execute the main function and handle any errors
145
225
  main().catch((err) => {
146
226
  DyFM_Log.error('Fix script failed:', err);
147
227
  process.exit(1);
148
228
  });
229
+
230
+
@@ -1,4 +1,28 @@
1
1
  #!/usr/bin/env node
2
+ /**
3
+ * @fileoverview Import Validation Script
4
+ *
5
+ * This script validates import ordering across all TypeScript files in the project
6
+ * using the Dynamo import-order ESLint rule. It scans files, runs ESLint validation,
7
+ * and reports any import ordering violations.
8
+ *
9
+ * @usage
10
+ * ```bash
11
+ * dynamo-validate-imports
12
+ * ```
13
+ *
14
+ * @example
15
+ * ```bash
16
+ * # Validate import ordering in all TypeScript files
17
+ * npx dynamo-validate-imports
18
+ *
19
+ * # Or run via npm script
20
+ * npm run validate:imports
21
+ * ```
22
+ *
23
+ * @author Future Development Program Ltd.
24
+ * @version 1.14.3
25
+ */
2
26
 
3
27
 
4
28
 
@@ -84,17 +108,44 @@ import { DyFM_Log } from '@futdevpro/fsm-dynamo';
84
108
  import fg from 'fast-glob';
85
109
  import { ESLint } from 'eslint';
86
110
 
111
+ /**
112
+ * Result of validating imports in a single file
113
+ */
87
114
  interface ImportValidationResult {
115
+ /** Path to the file that was validated */
88
116
  file: string;
117
+ /** Array of import validation errors found in the file */
89
118
  errors: Array<{
119
+ /** Line number where the error occurred */
90
120
  line: number;
121
+ /** Column number where the error occurred */
91
122
  column: number;
123
+ /** Error message describing the violation */
92
124
  message: string;
125
+ /** ID of the ESLint rule that was violated */
93
126
  ruleId: string;
94
127
  }>;
95
128
  }
96
129
 
130
+ /**
131
+ * Validates import ordering in a single TypeScript file
132
+ *
133
+ * Uses ESLint with the Dynamo import-order rule to check for import ordering
134
+ * violations and returns detailed error information.
135
+ *
136
+ * @param filePath - Path to the TypeScript file to validate
137
+ * @returns Promise that resolves to an ImportValidationResult object
138
+ *
139
+ * @example
140
+ * ```typescript
141
+ * const result = await validateImportsInFile('./src/components/Button.tsx');
142
+ * if (result.errors.length > 0) {
143
+ * console.log(`Found ${result.errors.length} import violations`);
144
+ * }
145
+ * ```
146
+ */
97
147
  async function validateImportsInFile(filePath: string): Promise<ImportValidationResult> {
148
+ // Configure ESLint with Dynamo import-order rule
98
149
  const eslint = new ESLint({
99
150
  baseConfig: {
100
151
  parser: '@typescript-eslint/parser',
@@ -115,9 +166,11 @@ async function validateImportsInFile(filePath: string): Promise<ImportValidation
115
166
  } as any,
116
167
  });
117
168
 
169
+ // Run ESLint on the file
118
170
  const results = await eslint.lintFiles([ filePath ]);
119
171
  const result = results[0];
120
172
 
173
+ // Transform ESLint messages into our result format
121
174
  return {
122
175
  file: filePath,
123
176
  errors: result.messages.map(msg => ({
@@ -129,7 +182,19 @@ async function validateImportsInFile(filePath: string): Promise<ImportValidation
129
182
  };
130
183
  }
131
184
 
185
+ /**
186
+ * Main function that validates import ordering across all TypeScript files
187
+ *
188
+ * Scans for all .ts and .tsx files in the project, validates import ordering
189
+ * using the Dynamo import-order rule, and provides detailed reporting on any
190
+ * violations found.
191
+ *
192
+ * @returns Promise that resolves when all files have been validated
193
+ *
194
+ * @throws {Error} When validation fails and process exits with code 1
195
+ */
132
196
  async function main() {
197
+ // Find all TypeScript files, excluding common directories and test files
133
198
  const files = await fg([ '**/*.{ts,tsx}' ], {
134
199
  ignore: [ '**/node_modules/**', '**/build/**', '**/dist/**', '**/*.spec.ts', '**/*.test.ts' ],
135
200
  });
@@ -139,6 +204,7 @@ async function main() {
139
204
  const results: ImportValidationResult[] = [];
140
205
  let totalErrors = 0;
141
206
 
207
+ // Process each file individually
142
208
  for (const file of files) {
143
209
  try {
144
210
  const result = await validateImportsInFile(file);
@@ -150,15 +216,16 @@ async function main() {
150
216
  }
151
217
  }
152
218
 
153
- // Report results
219
+ // Filter files that have import violations
154
220
  const filesWithErrors = results.filter(r => r.errors.length > 0);
155
221
 
222
+ // Report success if no violations found
156
223
  if (filesWithErrors.length === 0) {
157
224
  DyFM_Log.log('✅ All import validations passed!');
158
-
159
225
  return;
160
226
  }
161
227
 
228
+ // Report detailed error information
162
229
  DyFM_Log.warn(`\n❌ Found ${totalErrors} import validation errors in ${filesWithErrors.length} files:\n`);
163
230
 
164
231
  filesWithErrors.forEach(result => {
@@ -169,9 +236,11 @@ async function main() {
169
236
  DyFM_Log.log('');
170
237
  });
171
238
 
239
+ // Exit with error code to indicate validation failure
172
240
  process.exit(1);
173
241
  }
174
242
 
243
+ // Execute the main function and handle any errors
175
244
  main().catch((err) => {
176
245
  DyFM_Log.error('Validation failed:', err);
177
246
  process.exit(1);