@futdevpro/dynamo-eslint 1.14.3 → 1.14.4
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.
- package/.eslintrc.json +4 -0
- package/.vscode/settings.json +13 -0
- package/README.md +17 -2
- package/build/configs/base.js +2 -1
- package/build/configs/base.js.map +1 -1
- package/build/plugin/index.d.ts +2 -0
- package/build/plugin/index.d.ts.map +1 -1
- package/build/plugin/index.js +3 -0
- package/build/plugin/index.js.map +1 -1
- package/build/plugin/rules/explicit-types.d.ts +4 -0
- package/build/plugin/rules/explicit-types.d.ts.map +1 -0
- package/build/plugin/rules/explicit-types.js +165 -0
- package/build/plugin/rules/explicit-types.js.map +1 -0
- package/build/plugin/rules/explicit-types.spec.d.ts +2 -0
- package/build/plugin/rules/explicit-types.spec.d.ts.map +1 -0
- package/build/plugin/rules/explicit-types.spec.js +162 -0
- package/build/plugin/rules/explicit-types.spec.js.map +1 -0
- package/build/plugin/rules/import/no-import-type.d.ts.map +1 -1
- package/build/plugin/rules/import/no-import-type.js +23 -12
- package/build/plugin/rules/import/no-import-type.js.map +1 -1
- package/build/plugin/rules/import/no-js-import.d.ts.map +1 -1
- package/build/plugin/rules/import/no-js-import.js +22 -11
- package/build/plugin/rules/import/no-js-import.js.map +1 -1
- package/build/plugin/rules/naming-patterns.d.ts.map +1 -1
- package/build/plugin/rules/naming-patterns.js +7 -2
- package/build/plugin/rules/naming-patterns.js.map +1 -1
- package/build/scripts/dynamo-fix.d.ts +24 -0
- package/build/scripts/dynamo-fix.d.ts.map +1 -1
- package/build/scripts/dynamo-fix.js +57 -2
- package/build/scripts/dynamo-fix.js.map +1 -1
- package/build/scripts/eslintrc-audit.d.ts +24 -0
- package/build/scripts/eslintrc-audit.d.ts.map +1 -1
- package/build/scripts/eslintrc-audit.js +65 -0
- package/build/scripts/eslintrc-audit.js.map +1 -1
- package/build/scripts/fix-return-types.d.ts +25 -0
- package/build/scripts/fix-return-types.d.ts.map +1 -1
- package/build/scripts/fix-return-types.js +80 -9
- package/build/scripts/fix-return-types.js.map +1 -1
- package/build/scripts/validate-imports.d.ts +24 -0
- package/build/scripts/validate-imports.d.ts.map +1 -1
- package/build/scripts/validate-imports.js +62 -1
- package/build/scripts/validate-imports.js.map +1 -1
- package/build/scripts/validate-naming.d.ts +24 -0
- package/build/scripts/validate-naming.d.ts.map +1 -1
- package/build/scripts/validate-naming.js +72 -9
- package/build/scripts/validate-naming.js.map +1 -1
- package/eslint.config.js +9 -49
- package/futdevpro-dynamo-eslint-01.14.4.tgz +0 -0
- package/package.json +1 -1
- package/src/configs/base.ts +2 -1
- package/src/plugin/index.ts +3 -0
- package/src/plugin/rules/explicit-types.spec.ts +190 -0
- package/src/plugin/rules/explicit-types.ts +169 -0
- package/src/plugin/rules/import/no-import-type.ts +21 -12
- package/src/plugin/rules/import/no-js-import.ts +21 -13
- package/src/plugin/rules/naming-patterns.ts +6 -2
- package/src/scripts/dynamo-fix.ts +66 -2
- package/src/scripts/eslintrc-audit.ts +73 -2
- package/src/scripts/fix-return-types.ts +91 -9
- package/src/scripts/validate-imports.ts +71 -2
- package/src/scripts/validate-naming.ts +108 -17
- package/futdevpro-dynamo-eslint-01.14.3.tgz +0 -0
|
@@ -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
|
-
|
|
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-
|
|
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 =
|
|
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}
|
|
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
|
|
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
|
|
218
|
+
DyFM_Log.log(`🎉 Successfully added type annotations to ${totalFixed} files!`);
|
|
140
219
|
} else {
|
|
141
|
-
DyFM_Log.log('✅ No files needed
|
|
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
|
-
//
|
|
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);
|
|
@@ -1,31 +1,95 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview Naming Convention Validation Script
|
|
4
|
+
*
|
|
5
|
+
* This script validates naming conventions across all TypeScript files in the project
|
|
6
|
+
* using the Dynamo naming-patterns ESLint rule. It scans files, runs ESLint validation,
|
|
7
|
+
* and reports any naming convention violations.
|
|
8
|
+
*
|
|
9
|
+
* @usage
|
|
10
|
+
* ```bash
|
|
11
|
+
* dynamo-validate-naming
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```bash
|
|
16
|
+
* # Validate naming conventions in all TypeScript files
|
|
17
|
+
* npx dynamo-validate-naming
|
|
18
|
+
*
|
|
19
|
+
* # Or run via npm script
|
|
20
|
+
* npm run validate:naming
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* @author Future Development Program Ltd.
|
|
24
|
+
* @version 1.14.3
|
|
25
|
+
*/
|
|
26
|
+
|
|
2
27
|
import fg from 'fast-glob';
|
|
3
|
-
import { readFileSync } from 'fs';
|
|
4
28
|
import { ESLint } from 'eslint';
|
|
5
29
|
|
|
6
30
|
import { DyFM_Log } from '@futdevpro/fsm-dynamo';
|
|
7
31
|
|
|
32
|
+
/**
|
|
33
|
+
* Result of validating naming conventions in a single file
|
|
34
|
+
*/
|
|
8
35
|
interface NamingValidationResult {
|
|
36
|
+
/** Path to the file that was validated */
|
|
9
37
|
file: string;
|
|
38
|
+
/** Array of naming validation errors found in the file */
|
|
10
39
|
errors: Array<{
|
|
40
|
+
/** Line number where the error occurred */
|
|
11
41
|
line: number;
|
|
42
|
+
/** Column number where the error occurred */
|
|
12
43
|
column: number;
|
|
44
|
+
/** Error message describing the violation */
|
|
13
45
|
message: string;
|
|
46
|
+
/** ID of the ESLint rule that was violated */
|
|
14
47
|
ruleId: string;
|
|
15
48
|
}>;
|
|
16
49
|
}
|
|
17
50
|
|
|
51
|
+
/**
|
|
52
|
+
* Validates naming conventions in a single TypeScript file
|
|
53
|
+
*
|
|
54
|
+
* Uses ESLint with the Dynamo naming-patterns rule to check for naming convention
|
|
55
|
+
* violations and returns detailed error information.
|
|
56
|
+
*
|
|
57
|
+
* @param filePath - Path to the TypeScript file to validate
|
|
58
|
+
* @returns Promise that resolves to a NamingValidationResult object
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```typescript
|
|
62
|
+
* const result = await validateNamingInFile('./src/components/Button.tsx');
|
|
63
|
+
* if (result.errors.length > 0) {
|
|
64
|
+
* console.log(`Found ${result.errors.length} naming violations`);
|
|
65
|
+
* }
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
18
68
|
async function validateNamingInFile(filePath: string): Promise<NamingValidationResult> {
|
|
69
|
+
// Configure ESLint using the main Dynamo configuration
|
|
19
70
|
const eslint = new ESLint({
|
|
20
|
-
|
|
71
|
+
// Use the main config object from flat config array
|
|
72
|
+
baseConfig: require('../eslint.config.js')[1],
|
|
21
73
|
});
|
|
22
74
|
|
|
23
|
-
|
|
24
|
-
const
|
|
75
|
+
// Run ESLint on the file
|
|
76
|
+
const results: ESLint.LintResult[] = await eslint.lintFiles([ filePath ]);
|
|
77
|
+
const result: ESLint.LintResult = results[0];
|
|
25
78
|
|
|
79
|
+
// Transform ESLint messages into our result format
|
|
26
80
|
return {
|
|
27
81
|
file: filePath,
|
|
28
|
-
errors: result.messages.map(msg
|
|
82
|
+
errors: result.messages.map((msg: {
|
|
83
|
+
line: number;
|
|
84
|
+
column: number;
|
|
85
|
+
message: string;
|
|
86
|
+
ruleId?: string;
|
|
87
|
+
}): {
|
|
88
|
+
line: number;
|
|
89
|
+
column: number;
|
|
90
|
+
message: string;
|
|
91
|
+
ruleId: string;
|
|
92
|
+
} => ({
|
|
29
93
|
line: msg.line,
|
|
30
94
|
column: msg.column,
|
|
31
95
|
message: msg.message,
|
|
@@ -34,8 +98,20 @@ async function validateNamingInFile(filePath: string): Promise<NamingValidationR
|
|
|
34
98
|
};
|
|
35
99
|
}
|
|
36
100
|
|
|
37
|
-
|
|
38
|
-
|
|
101
|
+
/**
|
|
102
|
+
* Main function that validates naming conventions across all TypeScript files
|
|
103
|
+
*
|
|
104
|
+
* Scans for all .ts and .tsx files in the project, validates naming conventions
|
|
105
|
+
* using the Dynamo naming-patterns rule, and provides detailed reporting on any
|
|
106
|
+
* violations found.
|
|
107
|
+
*
|
|
108
|
+
* @returns Promise that resolves when all files have been validated
|
|
109
|
+
*
|
|
110
|
+
* @throws {Error} When validation fails and process exits with code 1
|
|
111
|
+
*/
|
|
112
|
+
async function main(): Promise<void> {
|
|
113
|
+
// Find all TypeScript files, excluding common directories and test files
|
|
114
|
+
const files: string[] = await fg([ '**/*.{ts,tsx}' ], {
|
|
39
115
|
ignore: [ '**/node_modules/**', '**/build/**', '**/dist/**', '**/*.spec.ts', '**/*.test.ts' ],
|
|
40
116
|
});
|
|
41
117
|
|
|
@@ -44,42 +120,57 @@ async function main() {
|
|
|
44
120
|
const results: NamingValidationResult[] = [];
|
|
45
121
|
let totalErrors = 0;
|
|
46
122
|
|
|
47
|
-
|
|
123
|
+
// Process each file individually
|
|
124
|
+
for (let i = 0; i < files.length; i++) {
|
|
125
|
+
const filePath: string = files[i];
|
|
126
|
+
|
|
48
127
|
try {
|
|
49
|
-
const result = await validateNamingInFile(
|
|
128
|
+
const result: NamingValidationResult = await validateNamingInFile(filePath);
|
|
50
129
|
|
|
51
130
|
results.push(result);
|
|
52
131
|
totalErrors += result.errors.length;
|
|
53
132
|
} catch (error) {
|
|
54
|
-
DyFM_Log.error(`Error processing ${
|
|
133
|
+
DyFM_Log.error(`Error processing ${filePath}:`, error);
|
|
55
134
|
}
|
|
56
135
|
}
|
|
57
136
|
|
|
58
|
-
//
|
|
59
|
-
const filesWithErrors = results.filter(
|
|
137
|
+
// Filter files that have naming violations
|
|
138
|
+
const filesWithErrors: NamingValidationResult[] = results.filter(
|
|
139
|
+
(r: NamingValidationResult): boolean => r.errors.length > 0
|
|
140
|
+
);
|
|
60
141
|
|
|
142
|
+
// Report success if no violations found
|
|
61
143
|
if (filesWithErrors.length === 0) {
|
|
62
144
|
DyFM_Log.log('✅ All naming validations passed!');
|
|
63
145
|
|
|
64
146
|
return;
|
|
65
147
|
}
|
|
66
148
|
|
|
67
|
-
|
|
149
|
+
// Report detailed error information
|
|
150
|
+
DyFM_Log.warn(
|
|
151
|
+
`\n❌ Found ${totalErrors} naming validation errors in ${filesWithErrors.length} files:\n`
|
|
152
|
+
);
|
|
68
153
|
|
|
69
|
-
filesWithErrors.forEach(result => {
|
|
154
|
+
filesWithErrors.forEach((result: NamingValidationResult): void => {
|
|
70
155
|
DyFM_Log.log(`📁 ${result.file}:`);
|
|
71
|
-
result.errors.forEach(error
|
|
156
|
+
result.errors.forEach((error: {
|
|
157
|
+
line: number;
|
|
158
|
+
column: number;
|
|
159
|
+
message: string;
|
|
160
|
+
ruleId: string;
|
|
161
|
+
}): void => {
|
|
72
162
|
DyFM_Log.log(` ${error.line}:${error.column} - ${error.message}`);
|
|
73
163
|
});
|
|
74
164
|
DyFM_Log.log('');
|
|
75
165
|
});
|
|
76
166
|
|
|
167
|
+
// Exit with error code to indicate validation failure
|
|
77
168
|
process.exit(1);
|
|
78
169
|
}
|
|
79
170
|
|
|
80
|
-
main
|
|
171
|
+
// Execute the main function and handle any errors
|
|
172
|
+
main().catch((err: Error): void => {
|
|
81
173
|
DyFM_Log.error('Validation failed:', err);
|
|
82
174
|
process.exit(1);
|
|
83
175
|
});
|
|
84
176
|
|
|
85
|
-
|
|
Binary file
|