@futdevpro/dynamo-eslint 1.14.2 → 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 +279 -29
- package/build/configs/base.d.ts +6 -81
- package/build/configs/base.d.ts.map +1 -1
- package/build/configs/base.js +90 -54
- package/build/configs/base.js.map +1 -1
- package/build/configs/fsm.d.ts +1 -85
- package/build/configs/fsm.d.ts.map +1 -1
- package/build/configs/fsm.js +3 -6
- package/build/configs/fsm.js.map +1 -1
- package/build/configs/ngx-package.d.ts +1 -85
- package/build/configs/ngx-package.d.ts.map +1 -1
- package/build/configs/ngx-package.js +3 -6
- package/build/configs/ngx-package.js.map +1 -1
- package/build/configs/ngx.d.ts +4 -85
- package/build/configs/ngx.d.ts.map +1 -1
- package/build/configs/ngx.js +67 -11
- package/build/configs/ngx.js.map +1 -1
- package/build/configs/nts-package.d.ts +1 -87
- package/build/configs/nts-package.d.ts.map +1 -1
- package/build/configs/nts-package.js +12 -10
- package/build/configs/nts-package.js.map +1 -1
- package/build/configs/nts.d.ts +1 -86
- package/build/configs/nts.d.ts.map +1 -1
- package/build/configs/nts.js +26 -11
- package/build/configs/nts.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/samples/.vscode/settings.json +13 -0
- package/samples/base/eslint.config.js +3 -0
- package/samples/fsm/.eslintrc.json +4 -0
- package/samples/fsm/eslint.config.js +3 -0
- package/samples/ngx/eslint.config.js +3 -0
- package/samples/ngx-package/.eslintrc.json +4 -0
- package/samples/ngx-package/eslint.config.js +3 -0
- package/samples/nts/eslint.config.js +3 -0
- package/samples/nts-package/.eslintrc.json +4 -0
- package/samples/nts-package/eslint.config.js +3 -0
- package/samples/package.json.example +26 -0
- package/src/configs/base.ts +90 -54
- package/src/configs/fsm.ts +3 -6
- package/src/configs/ngx-package.ts +3 -6
- package/src/configs/ngx.ts +67 -11
- package/src/configs/nts-package.ts +12 -10
- package/src/configs/nts.ts +26 -11
- 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 +93 -9
- package/src/scripts/validate-imports.ts +71 -2
- package/src/scripts/validate-naming.ts +108 -17
- package/futdevpro-dynamo-eslint-01.14.2.tgz +0 -0
|
@@ -1,11 +1,48 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
|
+
/**
|
|
4
|
+
* @fileoverview Dynamo ESLint Auto-Fix Script
|
|
5
|
+
*
|
|
6
|
+
* This script runs ESLint with auto-fix capabilities on TypeScript files across the project.
|
|
7
|
+
* It processes all .ts and .tsx files, applies Dynamo-specific rules, and automatically
|
|
8
|
+
* fixes issues where possible.
|
|
9
|
+
*
|
|
10
|
+
* @usage
|
|
11
|
+
* ```bash
|
|
12
|
+
* dynamo-fix
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```bash
|
|
17
|
+
* # Fix all TypeScript files in the project
|
|
18
|
+
* npx dynamo-fix
|
|
19
|
+
*
|
|
20
|
+
* # Or run via npm script
|
|
21
|
+
* npm run fix
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @author Future Development Program Ltd.
|
|
25
|
+
* @version 1.14.3
|
|
26
|
+
*/
|
|
3
27
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
28
|
const tslib_1 = require("tslib");
|
|
5
29
|
const fast_glob_1 = tslib_1.__importDefault(require("fast-glob"));
|
|
6
30
|
const eslint_1 = require("eslint");
|
|
7
31
|
const fs_1 = require("fs");
|
|
32
|
+
/**
|
|
33
|
+
* Fixes a single TypeScript file using ESLint with auto-fix capabilities
|
|
34
|
+
*
|
|
35
|
+
* @param filePath - Path to the TypeScript file to fix
|
|
36
|
+
* @returns Promise that resolves to a FixResult object containing fix statistics
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```typescript
|
|
40
|
+
* const result = await fixFile('./src/components/Button.tsx');
|
|
41
|
+
* console.log(`Fixed ${result.fixes} issues in ${result.file}`);
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
8
44
|
async function fixFile(filePath) {
|
|
45
|
+
// Configure ESLint with Dynamo-specific rules and auto-fix enabled
|
|
9
46
|
const eslint = new eslint_1.ESLint({
|
|
10
47
|
baseConfig: [
|
|
11
48
|
{ ignores: ['build/**', 'dist/**', 'node_modules/**'] },
|
|
@@ -31,12 +68,14 @@ async function fixFile(filePath) {
|
|
|
31
68
|
],
|
|
32
69
|
fix: true, // Enable auto-fixing
|
|
33
70
|
});
|
|
71
|
+
// Run ESLint on the file
|
|
34
72
|
const results = await eslint.lintFiles([filePath]);
|
|
35
73
|
const result = results[0];
|
|
74
|
+
// Write the fixed content back to the file if changes were made
|
|
36
75
|
if (result && result.output) {
|
|
37
|
-
// Write the fixed content back to the file
|
|
38
76
|
(0, fs_1.writeFileSync)(filePath, result.output);
|
|
39
77
|
}
|
|
78
|
+
// Return comprehensive fix statistics
|
|
40
79
|
return {
|
|
41
80
|
file: filePath,
|
|
42
81
|
fixed: result && result.output !== undefined,
|
|
@@ -45,7 +84,18 @@ async function fixFile(filePath) {
|
|
|
45
84
|
fixes: result.fixableErrorCount + result.fixableWarningCount,
|
|
46
85
|
};
|
|
47
86
|
}
|
|
87
|
+
/**
|
|
88
|
+
* Main function that processes all TypeScript files in the project
|
|
89
|
+
*
|
|
90
|
+
* Scans for all .ts and .tsx files, applies ESLint fixes, and provides
|
|
91
|
+
* comprehensive reporting on the results.
|
|
92
|
+
*
|
|
93
|
+
* @returns Promise that resolves when all files have been processed
|
|
94
|
+
*
|
|
95
|
+
* @throws {Error} When file processing fails
|
|
96
|
+
*/
|
|
48
97
|
async function main() {
|
|
98
|
+
// Find all TypeScript files, excluding common directories and test files
|
|
49
99
|
const files = await (0, fast_glob_1.default)(['**/*.{ts,tsx}'], {
|
|
50
100
|
ignore: ['**/node_modules/**', '**/build/**', '**/dist/**', '**/*.spec.ts', '**/*.test.ts'],
|
|
51
101
|
});
|
|
@@ -55,14 +105,17 @@ async function main() {
|
|
|
55
105
|
let totalErrors = 0;
|
|
56
106
|
let totalWarnings = 0;
|
|
57
107
|
let totalFixes = 0;
|
|
108
|
+
// Process each file individually
|
|
58
109
|
for (const file of files) {
|
|
59
110
|
try {
|
|
60
111
|
const result = await fixFile(file);
|
|
61
112
|
results.push(result);
|
|
113
|
+
// Track successful fixes
|
|
62
114
|
if (result.fixed) {
|
|
63
115
|
totalFixed++;
|
|
64
116
|
console.log(`✅ Fixed: ${result.file}`);
|
|
65
117
|
}
|
|
118
|
+
// Accumulate statistics
|
|
66
119
|
totalErrors += result.errors;
|
|
67
120
|
totalWarnings += result.warnings;
|
|
68
121
|
totalFixes += result.fixes;
|
|
@@ -71,13 +124,14 @@ async function main() {
|
|
|
71
124
|
console.error(`❌ Error processing ${file}:`, error);
|
|
72
125
|
}
|
|
73
126
|
}
|
|
74
|
-
//
|
|
127
|
+
// Generate comprehensive summary report
|
|
75
128
|
console.log(`\n📊 Fix Summary:`);
|
|
76
129
|
console.log(` Files processed: ${files.length}`);
|
|
77
130
|
console.log(` Files fixed: ${totalFixed}`);
|
|
78
131
|
console.log(` Total errors: ${totalErrors}`);
|
|
79
132
|
console.log(` Total warnings: ${totalWarnings}`);
|
|
80
133
|
console.log(` Total fixes applied: ${totalFixes}`);
|
|
134
|
+
// Provide appropriate success/failure message
|
|
81
135
|
if (totalFixed === 0) {
|
|
82
136
|
console.log('✅ No files needed fixing!');
|
|
83
137
|
}
|
|
@@ -85,6 +139,7 @@ async function main() {
|
|
|
85
139
|
console.log(`\n🎉 Successfully fixed ${totalFixed} files!`);
|
|
86
140
|
}
|
|
87
141
|
}
|
|
142
|
+
// Execute the main function and handle any errors
|
|
88
143
|
main().catch((err) => {
|
|
89
144
|
console.error('Fix failed:', err);
|
|
90
145
|
process.exit(1);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dynamo-fix.js","sourceRoot":"","sources":["../../src/scripts/dynamo-fix.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"dynamo-fix.js","sourceRoot":"","sources":["../../src/scripts/dynamo-fix.ts"],"names":[],"mappings":";;AACA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;;;AAEH,kEAA2B;AAC3B,mCAAgC;AAChC,2BAAmC;AAkBnC;;;;;;;;;;;GAWG;AACH,KAAK,UAAU,OAAO,CAAC,QAAgB;IACrC,mEAAmE;IACnE,MAAM,MAAM,GAAG,IAAI,eAAM,CAAC;QACxB,UAAU,EAAE;YACV,EAAE,OAAO,EAAE,CAAE,UAAU,EAAE,SAAS,EAAE,iBAAiB,CAAE,EAAE;YACzD;gBACE,KAAK,EAAE,CAAE,eAAe,CAAE;gBAC1B,eAAe,EAAE;oBACf,MAAM,EAAE,OAAO,CAAC,2BAA2B,CAAC;oBAC5C,aAAa,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE;iBAC3D;gBACD,OAAO,EAAE;oBACP,mBAAmB,EAAE;wBACnB,KAAK,EAAE;4BACL,cAAc,EAAE,OAAO,CAAC,8BAA8B,CAAC,CAAC,OAAO;4BAC/D,iBAAiB,EAAE,OAAO,CAAC,iCAAiC,CAAC,CAAC,OAAO;yBACtE;qBACF;iBACF;gBACD,KAAK,EAAE;oBACL,gCAAgC,EAAE,OAAO;oBACzC,mCAAmC,EAAE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CAAC,CAAC;IAC3C,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,GAAG,CAAC,2BAA2B,UAAU,SAAS,CAAC,CAAC;IAC9D,CAAC;AACH,CAAC;AAED,kDAAkD;AAClD,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;IACnB,OAAO,CAAC,KAAK,CAAC,aAAa,EAAE,GAAG,CAAC,CAAC;IAClC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
|
@@ -1,3 +1,27 @@
|
|
|
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
|
+
*/
|
|
2
26
|
export {};
|
|
3
27
|
//# sourceMappingURL=eslintrc-audit.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"eslintrc-audit.d.ts","sourceRoot":"","sources":["../../src/scripts/eslintrc-audit.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"eslintrc-audit.d.ts","sourceRoot":"","sources":["../../src/scripts/eslintrc-audit.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;;;;;;;;;;;GAuBG"}
|
|
@@ -1,34 +1,99 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
|
+
/**
|
|
4
|
+
* @fileoverview ESLint Configuration Audit Script
|
|
5
|
+
*
|
|
6
|
+
* This script analyzes ESLint configuration files (.eslintrc.json) across the project
|
|
7
|
+
* to provide statistics on rule usage. It helps identify commonly used rules and
|
|
8
|
+
* potential configuration inconsistencies.
|
|
9
|
+
*
|
|
10
|
+
* @usage
|
|
11
|
+
* ```bash
|
|
12
|
+
* dynamo-eslintrc-audit
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```bash
|
|
17
|
+
* # Audit all ESLint configurations in the project
|
|
18
|
+
* npx dynamo-eslintrc-audit
|
|
19
|
+
*
|
|
20
|
+
* # Or run via npm script
|
|
21
|
+
* npm run audit:eslintrc
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @author Future Development Program Ltd.
|
|
25
|
+
* @version 1.14.3
|
|
26
|
+
*/
|
|
3
27
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
28
|
const tslib_1 = require("tslib");
|
|
5
29
|
const fast_glob_1 = tslib_1.__importDefault(require("fast-glob"));
|
|
6
30
|
const fs_1 = require("fs");
|
|
31
|
+
/**
|
|
32
|
+
* Safely parses a JSON file and returns the parsed object or null if parsing fails
|
|
33
|
+
*
|
|
34
|
+
* @param jsonPath - Path to the JSON file to parse
|
|
35
|
+
* @returns Parsed JSON object or null if parsing fails
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```typescript
|
|
39
|
+
* const config = safeParse('./.eslintrc.json');
|
|
40
|
+
* if (config) {
|
|
41
|
+
* console.log('Rules:', Object.keys(config.rules || {}));
|
|
42
|
+
* }
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
7
45
|
function safeParse(jsonPath) {
|
|
8
46
|
try {
|
|
9
47
|
const content = (0, fs_1.readFileSync)(jsonPath, 'utf8');
|
|
10
48
|
return JSON.parse(content);
|
|
11
49
|
}
|
|
12
50
|
catch {
|
|
51
|
+
// Return null for any parsing errors (malformed JSON, file not found, etc.)
|
|
13
52
|
return null;
|
|
14
53
|
}
|
|
15
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* Main function that analyzes ESLint configuration files and generates rule usage statistics
|
|
57
|
+
*
|
|
58
|
+
* Scans for all .eslintrc.json files in the project, extracts rule configurations,
|
|
59
|
+
* and provides a sorted table of the most commonly used rules.
|
|
60
|
+
*
|
|
61
|
+
* @returns Promise that resolves when analysis is complete
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```typescript
|
|
65
|
+
* // The function will output a table like:
|
|
66
|
+
* // ┌─────────┬─────────────────────────┬───────┐
|
|
67
|
+
* // │ (index) │ rule │ count │
|
|
68
|
+
* // ├─────────┼─────────────────────────┼───────┤
|
|
69
|
+
* // │ 0 │ 'no-unused-vars' │ 5 │
|
|
70
|
+
* // │ 1 │ 'semi' │ 4 │
|
|
71
|
+
* // └─────────┴─────────────────────────┴───────┘
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
16
74
|
async function main() {
|
|
75
|
+
// Find all ESLint configuration files, excluding node_modules
|
|
17
76
|
const files = await (0, fast_glob_1.default)(['**/.eslintrc.json'], { ignore: ['**/node_modules/**'] });
|
|
18
77
|
const ruleCounts = {};
|
|
19
78
|
const total = files.length;
|
|
79
|
+
// Process each configuration file
|
|
20
80
|
for (const p of files) {
|
|
21
81
|
const cfg = safeParse(p);
|
|
82
|
+
// Skip files without rules configuration
|
|
22
83
|
if (!cfg?.rules)
|
|
23
84
|
continue;
|
|
85
|
+
// Count each rule occurrence
|
|
24
86
|
for (const key of Object.keys(cfg.rules)) {
|
|
25
87
|
ruleCounts[key] = (ruleCounts[key] ?? 0) + 1;
|
|
26
88
|
}
|
|
27
89
|
}
|
|
90
|
+
// Sort rules by usage count (most used first)
|
|
28
91
|
const entries = Object.entries(ruleCounts).sort((a, b) => b[1] - a[1]);
|
|
92
|
+
// Display results
|
|
29
93
|
console.log(`[dynamo-eslintrc-audit] analyzed ${total} files`);
|
|
30
94
|
console.table(entries.slice(0, 50).map(([rule, count]) => ({ rule, count })));
|
|
31
95
|
}
|
|
96
|
+
// Execute the main function and handle any errors
|
|
32
97
|
main().catch((err) => {
|
|
33
98
|
console.error(err);
|
|
34
99
|
process.exit(1);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"eslintrc-audit.js","sourceRoot":"","sources":["../../src/scripts/eslintrc-audit.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"eslintrc-audit.js","sourceRoot":"","sources":["../../src/scripts/eslintrc-audit.ts"],"names":[],"mappings":";;AACA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;;;AAEH,kEAA2B;AAC3B,2BAAkC;AAIlC;;;;;;;;;;;;;GAaG;AACH,SAAS,SAAS,CAAC,QAAgB;IACjC,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,IAAA,iBAAY,EAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QAE/C,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAC7B,CAAC;IAAC,MAAM,CAAC;QACP,4EAA4E;QAC5E,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,KAAK,UAAU,IAAI;IACjB,8DAA8D;IAC9D,MAAM,KAAK,GAAG,MAAM,IAAA,mBAAE,EAAC,CAAE,mBAAmB,CAAE,EAAE,EAAE,MAAM,EAAE,CAAE,oBAAoB,CAAE,EAAE,CAAC,CAAC;IACtF,MAAM,UAAU,GAA2B,EAAE,CAAC;IAC9C,MAAM,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC;IAE3B,kCAAkC;IAClC,KAAK,MAAM,CAAC,IAAI,KAAK,EAAE,CAAC;QACtB,MAAM,GAAG,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;QAEzB,yCAAyC;QACzC,IAAI,CAAC,GAAG,EAAE,KAAK;YAAE,SAAS;QAE1B,6BAA6B;QAC7B,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;YACzC,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;QAC/C,CAAC;IACH,CAAC;IAED,8CAA8C;IAC9C,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAEvE,kBAAkB;IAClB,OAAO,CAAC,GAAG,CAAC,oCAAoC,KAAK,QAAQ,CAAC,CAAC;IAC/D,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAE,IAAI,EAAE,KAAK,CAAE,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC;AAClF,CAAC;AAED,kDAAkD;AAClD,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;IACnB,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACnB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
|
@@ -1,3 +1,28 @@
|
|
|
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
|
+
*/
|
|
2
27
|
export {};
|
|
3
28
|
//# sourceMappingURL=fix-return-types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fix-return-types.d.ts","sourceRoot":"","sources":["../../src/scripts/fix-return-types.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"fix-return-types.d.ts","sourceRoot":"","sources":["../../src/scripts/fix-return-types.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG"}
|
|
@@ -1,14 +1,56 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
|
+
/**
|
|
4
|
+
* @fileoverview TypeScript Type Annotation Fix Script
|
|
5
|
+
*
|
|
6
|
+
* This script uses TypeScript's AST (Abstract Syntax Tree) to automatically add
|
|
7
|
+
* type annotations to functions and arrow functions. It analyzes TypeScript files,
|
|
8
|
+
* infers return types using the TypeScript compiler, and adds explicit type
|
|
9
|
+
* annotations where missing.
|
|
10
|
+
*
|
|
11
|
+
* @usage
|
|
12
|
+
* ```bash
|
|
13
|
+
* dynamo-fix-return-types
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```bash
|
|
18
|
+
* # Fix type annotations in all TypeScript files
|
|
19
|
+
* npx dynamo-fix-return-types
|
|
20
|
+
*
|
|
21
|
+
* # Or run via npm script
|
|
22
|
+
* npm run fix:types
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @author Future Development Program Ltd.
|
|
26
|
+
* @version 1.14.3
|
|
27
|
+
*/
|
|
3
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
29
|
const tslib_1 = require("tslib");
|
|
5
30
|
const ts = tslib_1.__importStar(require("typescript"));
|
|
6
31
|
const fs = tslib_1.__importStar(require("fs"));
|
|
7
32
|
const fast_glob_1 = tslib_1.__importDefault(require("fast-glob"));
|
|
8
33
|
const fsm_dynamo_1 = require("@futdevpro/fsm-dynamo");
|
|
9
|
-
|
|
34
|
+
/**
|
|
35
|
+
* Adds type annotations to functions and arrow functions in a TypeScript file
|
|
36
|
+
*
|
|
37
|
+
* Uses TypeScript's compiler API to analyze the file, infer return types,
|
|
38
|
+
* and automatically add explicit type annotations where missing.
|
|
39
|
+
*
|
|
40
|
+
* @param filePath - Path to the TypeScript file to process
|
|
41
|
+
* @returns FixResult object containing statistics about the changes made
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```typescript
|
|
45
|
+
* const result = addTypesToFile('./src/utils.ts');
|
|
46
|
+
* console.log(`Added ${result.changes} type annotations to ${result.file}`);
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
function addTypesToFile(filePath) {
|
|
50
|
+
// Read and parse the source file
|
|
10
51
|
const sourceCode = fs.readFileSync(filePath, 'utf8');
|
|
11
52
|
const sourceFile = ts.createSourceFile(filePath, sourceCode, ts.ScriptTarget.Latest, true);
|
|
53
|
+
// Create TypeScript program for type checking
|
|
12
54
|
const program = ts.createProgram([filePath], {
|
|
13
55
|
target: ts.ScriptTarget.Latest,
|
|
14
56
|
module: ts.ModuleKind.ESNext,
|
|
@@ -18,13 +60,20 @@ function addReturnTypesToFile(filePath) {
|
|
|
18
60
|
const checker = program.getTypeChecker();
|
|
19
61
|
let changes = 0;
|
|
20
62
|
let hasChanges = false;
|
|
63
|
+
/**
|
|
64
|
+
* Recursively visits AST nodes and adds type annotations where needed
|
|
65
|
+
*
|
|
66
|
+
* @param node - The current AST node being visited
|
|
67
|
+
* @returns The potentially modified AST node
|
|
68
|
+
*/
|
|
21
69
|
function visit(node) {
|
|
22
|
-
// Handle function declarations
|
|
70
|
+
// Handle function declarations without return types
|
|
23
71
|
if (ts.isFunctionDeclaration(node) && !node.type) {
|
|
24
72
|
const signature = checker.getSignatureFromDeclaration(node);
|
|
25
73
|
if (signature) {
|
|
26
74
|
const returnType = checker.getReturnTypeOfSignature(signature);
|
|
27
75
|
const typeString = checker.typeToString(returnType);
|
|
76
|
+
// Add type annotation if it's not void or any
|
|
28
77
|
if (typeString !== 'void' && typeString !== 'any') {
|
|
29
78
|
const newType = ts.factory.createTypeReferenceNode(typeString);
|
|
30
79
|
const updatedNode = ts.factory.updateFunctionDeclaration(node, node.modifiers, node.asteriskToken, node.name, node.typeParameters, node.parameters, newType, node.body);
|
|
@@ -34,12 +83,13 @@ function addReturnTypesToFile(filePath) {
|
|
|
34
83
|
}
|
|
35
84
|
}
|
|
36
85
|
}
|
|
37
|
-
// Handle arrow functions
|
|
86
|
+
// Handle arrow functions without return types
|
|
38
87
|
if (ts.isArrowFunction(node) && !node.type) {
|
|
39
88
|
const signature = checker.getSignatureFromDeclaration(node);
|
|
40
89
|
if (signature) {
|
|
41
90
|
const returnType = checker.getReturnTypeOfSignature(signature);
|
|
42
91
|
const typeString = checker.typeToString(returnType);
|
|
92
|
+
// Add type annotation if it's not void or any
|
|
43
93
|
if (typeString !== 'void' && typeString !== 'any') {
|
|
44
94
|
const newType = ts.factory.createTypeReferenceNode(typeString);
|
|
45
95
|
const updatedNode = ts.factory.updateArrowFunction(node, node.modifiers, node.typeParameters, node.parameters, newType, node.equalsGreaterThanToken, node.body);
|
|
@@ -49,9 +99,14 @@ function addReturnTypesToFile(filePath) {
|
|
|
49
99
|
}
|
|
50
100
|
}
|
|
51
101
|
}
|
|
102
|
+
// Note: Variable declarations, parameters, and class properties
|
|
103
|
+
// are handled by the existing @typescript-eslint/typedef rule
|
|
104
|
+
// and can be auto-fixed with eslint --fix
|
|
52
105
|
return ts.visitEachChild(node, visit, {});
|
|
53
106
|
}
|
|
107
|
+
// Transform the AST and apply changes
|
|
54
108
|
const result = ts.visitEachChild(sourceFile, visit, {});
|
|
109
|
+
// Write the modified code back to the file if changes were made
|
|
55
110
|
if (hasChanges) {
|
|
56
111
|
const printer = ts.createPrinter();
|
|
57
112
|
const newSourceCode = printer.printFile(result);
|
|
@@ -63,7 +118,18 @@ function addReturnTypesToFile(filePath) {
|
|
|
63
118
|
changes,
|
|
64
119
|
};
|
|
65
120
|
}
|
|
121
|
+
/**
|
|
122
|
+
* Main function that processes all TypeScript files and adds type annotations
|
|
123
|
+
*
|
|
124
|
+
* Scans for all .ts and .tsx files in the project, processes each file to add
|
|
125
|
+
* missing type annotations, and provides comprehensive reporting on the results.
|
|
126
|
+
*
|
|
127
|
+
* @returns Promise that resolves when all files have been processed
|
|
128
|
+
*
|
|
129
|
+
* @throws {Error} When file processing fails
|
|
130
|
+
*/
|
|
66
131
|
async function main() {
|
|
132
|
+
// Find all TypeScript files, excluding common directories and test files
|
|
67
133
|
const files = await (0, fast_glob_1.default)(['**/*.{ts,tsx}'], {
|
|
68
134
|
ignore: [
|
|
69
135
|
'**/node_modules/**',
|
|
@@ -73,35 +139,40 @@ async function main() {
|
|
|
73
139
|
'**/*.test.ts',
|
|
74
140
|
],
|
|
75
141
|
});
|
|
76
|
-
fsm_dynamo_1.DyFM_Log.log(`[fix-
|
|
142
|
+
fsm_dynamo_1.DyFM_Log.log(`[fix-types] Processing ${files.length} files...`);
|
|
77
143
|
const results = [];
|
|
78
144
|
let totalFixed = 0;
|
|
79
145
|
let totalChanges = 0;
|
|
146
|
+
// Process each file individually
|
|
80
147
|
for (const file of files) {
|
|
81
148
|
try {
|
|
82
|
-
const result =
|
|
149
|
+
const result = addTypesToFile(file);
|
|
83
150
|
results.push(result);
|
|
151
|
+
// Track successful fixes
|
|
84
152
|
if (result.fixed) {
|
|
85
153
|
totalFixed++;
|
|
86
154
|
totalChanges += result.changes;
|
|
87
|
-
fsm_dynamo_1.DyFM_Log.log(`✅ Fixed ${result.changes}
|
|
155
|
+
fsm_dynamo_1.DyFM_Log.log(`✅ Fixed ${result.changes} type annotations in ${file}`);
|
|
88
156
|
}
|
|
89
157
|
}
|
|
90
158
|
catch (error) {
|
|
91
159
|
fsm_dynamo_1.DyFM_Log.error(`❌ Error processing ${file}:`, error);
|
|
92
160
|
}
|
|
93
161
|
}
|
|
162
|
+
// Generate comprehensive summary report
|
|
94
163
|
fsm_dynamo_1.DyFM_Log.log(`\n📊 Fix Summary:`);
|
|
95
164
|
fsm_dynamo_1.DyFM_Log.log(` Files processed: ${files.length}`);
|
|
96
165
|
fsm_dynamo_1.DyFM_Log.log(` Files fixed: ${totalFixed}`);
|
|
97
|
-
fsm_dynamo_1.DyFM_Log.log(` Total
|
|
166
|
+
fsm_dynamo_1.DyFM_Log.log(` Total type annotations added: ${totalChanges}`);
|
|
167
|
+
// Provide appropriate success/failure message
|
|
98
168
|
if (totalFixed > 0) {
|
|
99
|
-
fsm_dynamo_1.DyFM_Log.log(`🎉 Successfully added
|
|
169
|
+
fsm_dynamo_1.DyFM_Log.log(`🎉 Successfully added type annotations to ${totalFixed} files!`);
|
|
100
170
|
}
|
|
101
171
|
else {
|
|
102
|
-
fsm_dynamo_1.DyFM_Log.log('✅ No files needed
|
|
172
|
+
fsm_dynamo_1.DyFM_Log.log('✅ No files needed type annotation fixes!');
|
|
103
173
|
}
|
|
104
174
|
}
|
|
175
|
+
// Execute the main function and handle any errors
|
|
105
176
|
main().catch((err) => {
|
|
106
177
|
fsm_dynamo_1.DyFM_Log.error('Fix script failed:', err);
|
|
107
178
|
process.exit(1);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fix-return-types.js","sourceRoot":"","sources":["../../src/scripts/fix-return-types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"fix-return-types.js","sourceRoot":"","sources":["../../src/scripts/fix-return-types.ts"],"names":[],"mappings":";;AACA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;;;AAEH,uDAAiC;AACjC,+CAAyB;AAEzB,kEAA2B;AAC3B,sDAAiD;AAcjD;;;;;;;;;;;;;;GAcG;AACH,SAAS,cAAc,CAAC,QAAgB;IACtC,iCAAiC;IACjC,MAAM,UAAU,GAAG,EAAE,CAAC,YAAY,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IACrD,MAAM,UAAU,GAAG,EAAE,CAAC,gBAAgB,CAAC,QAAQ,EAAE,UAAU,EAAE,EAAE,CAAC,YAAY,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAE3F,8CAA8C;IAC9C,MAAM,OAAO,GAAG,EAAE,CAAC,aAAa,CAAC,CAAC,QAAQ,CAAC,EAAE;QAC3C,MAAM,EAAE,EAAE,CAAC,YAAY,CAAC,MAAM;QAC9B,MAAM,EAAE,EAAE,CAAC,UAAU,CAAC,MAAM;QAC5B,MAAM,EAAE,IAAI;QACZ,YAAY,EAAE,IAAI;KACnB,CAAC,CAAC;IAEH,MAAM,OAAO,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC;IACzC,IAAI,OAAO,GAAG,CAAC,CAAC;IAChB,IAAI,UAAU,GAAG,KAAK,CAAC;IAEvB;;;;;OAKG;IACH,SAAS,KAAK,CAAC,IAAa;QAC1B,oDAAoD;QACpD,IAAI,EAAE,CAAC,qBAAqB,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;YACjD,MAAM,SAAS,GAAG,OAAO,CAAC,2BAA2B,CAAC,IAAI,CAAC,CAAC;YAE5D,IAAI,SAAS,EAAE,CAAC;gBACd,MAAM,UAAU,GAAG,OAAO,CAAC,wBAAwB,CAAC,SAAS,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oB,EAAE,GAAG,CAAC,CAAC;IAC1C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
|
@@ -1,3 +1,27 @@
|
|
|
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
|
export {};
|
|
3
27
|
//# sourceMappingURL=validate-imports.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate-imports.d.ts","sourceRoot":"","sources":["../../src/scripts/validate-imports.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"validate-imports.d.ts","sourceRoot":"","sources":["../../src/scripts/validate-imports.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;;;;;;;;;;;GAuBG"}
|
|
@@ -1,11 +1,53 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
|
+
/**
|
|
4
|
+
* @fileoverview Import Validation Script
|
|
5
|
+
*
|
|
6
|
+
* This script validates import ordering across all TypeScript files in the project
|
|
7
|
+
* using the Dynamo import-order ESLint rule. It scans files, runs ESLint validation,
|
|
8
|
+
* and reports any import ordering violations.
|
|
9
|
+
*
|
|
10
|
+
* @usage
|
|
11
|
+
* ```bash
|
|
12
|
+
* dynamo-validate-imports
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```bash
|
|
17
|
+
* # Validate import ordering in all TypeScript files
|
|
18
|
+
* npx dynamo-validate-imports
|
|
19
|
+
*
|
|
20
|
+
* # Or run via npm script
|
|
21
|
+
* npm run validate:imports
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @author Future Development Program Ltd.
|
|
25
|
+
* @version 1.14.3
|
|
26
|
+
*/
|
|
3
27
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
28
|
const tslib_1 = require("tslib");
|
|
5
29
|
const fsm_dynamo_1 = require("@futdevpro/fsm-dynamo");
|
|
6
30
|
const fast_glob_1 = tslib_1.__importDefault(require("fast-glob"));
|
|
7
31
|
const eslint_1 = require("eslint");
|
|
32
|
+
/**
|
|
33
|
+
* Validates import ordering in a single TypeScript file
|
|
34
|
+
*
|
|
35
|
+
* Uses ESLint with the Dynamo import-order rule to check for import ordering
|
|
36
|
+
* violations and returns detailed error information.
|
|
37
|
+
*
|
|
38
|
+
* @param filePath - Path to the TypeScript file to validate
|
|
39
|
+
* @returns Promise that resolves to an ImportValidationResult object
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```typescript
|
|
43
|
+
* const result = await validateImportsInFile('./src/components/Button.tsx');
|
|
44
|
+
* if (result.errors.length > 0) {
|
|
45
|
+
* console.log(`Found ${result.errors.length} import violations`);
|
|
46
|
+
* }
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
8
49
|
async function validateImportsInFile(filePath) {
|
|
50
|
+
// Configure ESLint with Dynamo import-order rule
|
|
9
51
|
const eslint = new eslint_1.ESLint({
|
|
10
52
|
baseConfig: {
|
|
11
53
|
parser: '@typescript-eslint/parser',
|
|
@@ -25,8 +67,10 @@ async function validateImportsInFile(filePath) {
|
|
|
25
67
|
},
|
|
26
68
|
},
|
|
27
69
|
});
|
|
70
|
+
// Run ESLint on the file
|
|
28
71
|
const results = await eslint.lintFiles([filePath]);
|
|
29
72
|
const result = results[0];
|
|
73
|
+
// Transform ESLint messages into our result format
|
|
30
74
|
return {
|
|
31
75
|
file: filePath,
|
|
32
76
|
errors: result.messages.map(msg => ({
|
|
@@ -37,13 +81,26 @@ async function validateImportsInFile(filePath) {
|
|
|
37
81
|
})),
|
|
38
82
|
};
|
|
39
83
|
}
|
|
84
|
+
/**
|
|
85
|
+
* Main function that validates import ordering across all TypeScript files
|
|
86
|
+
*
|
|
87
|
+
* Scans for all .ts and .tsx files in the project, validates import ordering
|
|
88
|
+
* using the Dynamo import-order rule, and provides detailed reporting on any
|
|
89
|
+
* violations found.
|
|
90
|
+
*
|
|
91
|
+
* @returns Promise that resolves when all files have been validated
|
|
92
|
+
*
|
|
93
|
+
* @throws {Error} When validation fails and process exits with code 1
|
|
94
|
+
*/
|
|
40
95
|
async function main() {
|
|
96
|
+
// Find all TypeScript files, excluding common directories and test files
|
|
41
97
|
const files = await (0, fast_glob_1.default)(['**/*.{ts,tsx}'], {
|
|
42
98
|
ignore: ['**/node_modules/**', '**/build/**', '**/dist/**', '**/*.spec.ts', '**/*.test.ts'],
|
|
43
99
|
});
|
|
44
100
|
fsm_dynamo_1.DyFM_Log.log(`[dynamo-validate-imports] Scanning ${files.length} files...`);
|
|
45
101
|
const results = [];
|
|
46
102
|
let totalErrors = 0;
|
|
103
|
+
// Process each file individually
|
|
47
104
|
for (const file of files) {
|
|
48
105
|
try {
|
|
49
106
|
const result = await validateImportsInFile(file);
|
|
@@ -54,12 +111,14 @@ async function main() {
|
|
|
54
111
|
fsm_dynamo_1.DyFM_Log.error(`Error processing ${file}:`, error);
|
|
55
112
|
}
|
|
56
113
|
}
|
|
57
|
-
//
|
|
114
|
+
// Filter files that have import violations
|
|
58
115
|
const filesWithErrors = results.filter(r => r.errors.length > 0);
|
|
116
|
+
// Report success if no violations found
|
|
59
117
|
if (filesWithErrors.length === 0) {
|
|
60
118
|
fsm_dynamo_1.DyFM_Log.log('✅ All import validations passed!');
|
|
61
119
|
return;
|
|
62
120
|
}
|
|
121
|
+
// Report detailed error information
|
|
63
122
|
fsm_dynamo_1.DyFM_Log.warn(`\n❌ Found ${totalErrors} import validation errors in ${filesWithErrors.length} files:\n`);
|
|
64
123
|
filesWithErrors.forEach(result => {
|
|
65
124
|
fsm_dynamo_1.DyFM_Log.log(`📁 ${result.file}:`);
|
|
@@ -68,8 +127,10 @@ async function main() {
|
|
|
68
127
|
});
|
|
69
128
|
fsm_dynamo_1.DyFM_Log.log('');
|
|
70
129
|
});
|
|
130
|
+
// Exit with error code to indicate validation failure
|
|
71
131
|
process.exit(1);
|
|
72
132
|
}
|
|
133
|
+
// Execute the main function and handle any errors
|
|
73
134
|
main().catch((err) => {
|
|
74
135
|
fsm_dynamo_1.DyFM_Log.error('Validation failed:', err);
|
|
75
136
|
process.exit(1);
|