@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.
Files changed (62) hide show
  1. package/.eslintrc.json +4 -0
  2. package/.vscode/settings.json +13 -0
  3. package/README.md +17 -2
  4. package/build/configs/base.js +2 -1
  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 +165 -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/no-import-type.d.ts.map +1 -1
  19. package/build/plugin/rules/import/no-import-type.js +23 -12
  20. package/build/plugin/rules/import/no-import-type.js.map +1 -1
  21. package/build/plugin/rules/import/no-js-import.d.ts.map +1 -1
  22. package/build/plugin/rules/import/no-js-import.js +22 -11
  23. package/build/plugin/rules/import/no-js-import.js.map +1 -1
  24. package/build/plugin/rules/naming-patterns.d.ts.map +1 -1
  25. package/build/plugin/rules/naming-patterns.js +7 -2
  26. package/build/plugin/rules/naming-patterns.js.map +1 -1
  27. package/build/scripts/dynamo-fix.d.ts +24 -0
  28. package/build/scripts/dynamo-fix.d.ts.map +1 -1
  29. package/build/scripts/dynamo-fix.js +57 -2
  30. package/build/scripts/dynamo-fix.js.map +1 -1
  31. package/build/scripts/eslintrc-audit.d.ts +24 -0
  32. package/build/scripts/eslintrc-audit.d.ts.map +1 -1
  33. package/build/scripts/eslintrc-audit.js +65 -0
  34. package/build/scripts/eslintrc-audit.js.map +1 -1
  35. package/build/scripts/fix-return-types.d.ts +25 -0
  36. package/build/scripts/fix-return-types.d.ts.map +1 -1
  37. package/build/scripts/fix-return-types.js +80 -9
  38. package/build/scripts/fix-return-types.js.map +1 -1
  39. package/build/scripts/validate-imports.d.ts +24 -0
  40. package/build/scripts/validate-imports.d.ts.map +1 -1
  41. package/build/scripts/validate-imports.js +62 -1
  42. package/build/scripts/validate-imports.js.map +1 -1
  43. package/build/scripts/validate-naming.d.ts +24 -0
  44. package/build/scripts/validate-naming.d.ts.map +1 -1
  45. package/build/scripts/validate-naming.js +72 -9
  46. package/build/scripts/validate-naming.js.map +1 -1
  47. package/eslint.config.js +9 -49
  48. package/futdevpro-dynamo-eslint-01.14.4.tgz +0 -0
  49. package/package.json +1 -1
  50. package/src/configs/base.ts +2 -1
  51. package/src/plugin/index.ts +3 -0
  52. package/src/plugin/rules/explicit-types.spec.ts +190 -0
  53. package/src/plugin/rules/explicit-types.ts +169 -0
  54. package/src/plugin/rules/import/no-import-type.ts +21 -12
  55. package/src/plugin/rules/import/no-js-import.ts +21 -13
  56. package/src/plugin/rules/naming-patterns.ts +6 -2
  57. package/src/scripts/dynamo-fix.ts +66 -2
  58. package/src/scripts/eslintrc-audit.ts +73 -2
  59. package/src/scripts/fix-return-types.ts +91 -9
  60. package/src/scripts/validate-imports.ts +71 -2
  61. package/src/scripts/validate-naming.ts +108 -17
  62. package/futdevpro-dynamo-eslint-01.14.3.tgz +0 -0
@@ -0,0 +1,169 @@
1
+ import { Rule } from 'eslint';
2
+
3
+ const rule: Rule.RuleModule = {
4
+ meta: {
5
+ type: 'suggestion',
6
+ docs: {
7
+ description: 'Enforce explicit type annotations on all TypeScript declarations',
8
+ recommended: true,
9
+ },
10
+ schema: [],
11
+ messages: {
12
+ missingReturnType: 'Function "{{name}}" must have an explicit return type annotation.',
13
+ missingArrowReturnType: 'Arrow function must have an explicit return type annotation.',
14
+ missingVariableType: 'Variable "{{name}}" must have an explicit type annotation.',
15
+ missingParameterType: 'Parameter "{{name}}" must have an explicit type annotation.',
16
+ missingPropertyType: 'Class property "{{name}}" must have an explicit type annotation.',
17
+ missingDestructuringType: 'Destructuring assignment must have explicit type annotations.',
18
+ },
19
+ },
20
+ create(context) {
21
+ return {
22
+ // Function declarations
23
+ FunctionDeclaration(node: any) {
24
+ try {
25
+ // Check return type
26
+ if (!node.returnType) {
27
+ context.report({
28
+ node,
29
+ messageId: 'missingReturnType',
30
+ data: { name: node.id?.name || 'anonymous' },
31
+ });
32
+ }
33
+
34
+ // Check function parameters with defensive checks
35
+ if (node.params && Array.isArray(node.params)) {
36
+ node.params.forEach((param: any) => {
37
+ try {
38
+ if (param && param.type === 'Identifier' && !param.typeAnnotation) {
39
+ context.report({
40
+ node: param,
41
+ messageId: 'missingParameterType',
42
+ data: { name: param.name || 'unknown' },
43
+ });
44
+ }
45
+ } catch (paramError) {
46
+ console.error('[explicit-types] Error processing function parameter:', paramError);
47
+ }
48
+ });
49
+ }
50
+ } catch (error) {
51
+ console.error('[explicit-types] Error in FunctionDeclaration visitor:', error);
52
+ }
53
+ },
54
+
55
+ // Arrow functions
56
+ ArrowFunctionExpression(node: any) {
57
+ try {
58
+ // Check return type
59
+ if (!node.returnType) {
60
+ context.report({
61
+ node,
62
+ messageId: 'missingArrowReturnType',
63
+ });
64
+ }
65
+
66
+ // Check arrow function parameters with defensive checks
67
+ if (node.params && Array.isArray(node.params)) {
68
+ node.params.forEach((param: any) => {
69
+ try {
70
+ if (param && param.type === 'Identifier' && !param.typeAnnotation) {
71
+ context.report({
72
+ node: param,
73
+ messageId: 'missingParameterType',
74
+ data: { name: param.name || 'unknown' },
75
+ });
76
+ }
77
+ } catch (paramError) {
78
+ console.error('[explicit-types] Error processing arrow function parameter:', paramError);
79
+ }
80
+ });
81
+ }
82
+ } catch (error) {
83
+ console.error('[explicit-types] Error in ArrowFunctionExpression visitor:', error);
84
+ }
85
+ },
86
+
87
+ // Variable declarations
88
+ VariableDeclarator(node: any) {
89
+ try {
90
+ // Defensive check for node.id
91
+ if (!node.id) {
92
+ return;
93
+ }
94
+
95
+ if (!node.id.typeAnnotation) {
96
+ // Skip if variable is initialized with a typed value that can be inferred
97
+ const hasTypedInitializer = node.init && (
98
+ node.init.type === 'CallExpression' ||
99
+ node.init.type === 'NewExpression' ||
100
+ node.init.type === 'ArrayExpression' ||
101
+ node.init.type === 'ObjectExpression' ||
102
+ node.init.type === 'Literal'
103
+ );
104
+
105
+ if (!hasTypedInitializer) {
106
+ context.report({
107
+ node: node.id,
108
+ messageId: 'missingVariableType',
109
+ data: { name: (node.id as any)?.name || 'destructured' },
110
+ });
111
+ }
112
+ }
113
+ } catch (error) {
114
+ console.error('[explicit-types] Error in VariableDeclarator visitor:', error);
115
+ }
116
+ },
117
+
118
+ // Class properties
119
+ PropertyDefinition(node: any) {
120
+ try {
121
+ // Defensive check for node.key
122
+ if (!node.key) {
123
+ return;
124
+ }
125
+
126
+ if (!node.typeAnnotation && !node.value) {
127
+ context.report({
128
+ node: node.key,
129
+ messageId: 'missingPropertyType',
130
+ data: { name: (node.key as any)?.name || 'computed' },
131
+ });
132
+ }
133
+ } catch (error) {
134
+ console.error('[explicit-types] Error in PropertyDefinition visitor:', error);
135
+ }
136
+ },
137
+
138
+ // Object destructuring
139
+ ObjectPattern(node: any) {
140
+ try {
141
+ if (!node.typeAnnotation) {
142
+ context.report({
143
+ node,
144
+ messageId: 'missingDestructuringType',
145
+ });
146
+ }
147
+ } catch (error) {
148
+ console.error('[explicit-types] Error in ObjectPattern visitor:', error);
149
+ }
150
+ },
151
+
152
+ // Array destructuring
153
+ ArrayPattern(node: any) {
154
+ try {
155
+ if (!node.typeAnnotation) {
156
+ context.report({
157
+ node,
158
+ messageId: 'missingDestructuringType',
159
+ });
160
+ }
161
+ } catch (error) {
162
+ console.error('[explicit-types] Error in ArrayPattern visitor:', error);
163
+ }
164
+ },
165
+ };
166
+ },
167
+ };
168
+
169
+ export default rule;
@@ -15,19 +15,28 @@ const rule: Rule.RuleModule = {
15
15
 
16
16
  return {
17
17
  ImportDeclaration(node: any) {
18
- // Check for import type usage
19
- if (node.importKind === 'type') {
20
- context.report({
21
- node,
22
- messageId: 'forbiddenImportType',
23
- fix(fixer) {
24
- // Remove 'type' keyword
25
- const importText = sourceCode.getText(node);
26
- const newImportText = importText.replace(/import\s+type\s+/, 'import ');
18
+ try {
19
+ // Check for import type usage
20
+ if (node.importKind === 'type') {
21
+ context.report({
22
+ node,
23
+ messageId: 'forbiddenImportType',
24
+ fix(fixer) {
25
+ try {
26
+ // Remove 'type' keyword
27
+ const importText = sourceCode.getText(node);
28
+ const newImportText = importText.replace(/import\s+type\s+/, 'import ');
27
29
 
28
- return fixer.replaceText(node, newImportText);
29
- },
30
- });
30
+ return fixer.replaceText(node, newImportText);
31
+ } catch (fixError) {
32
+ console.error('[no-import-type] Error in fix function:', fixError);
33
+ return null;
34
+ }
35
+ },
36
+ });
37
+ }
38
+ } catch (error) {
39
+ console.error('[no-import-type] Error in ImportDeclaration visitor:', error);
31
40
  }
32
41
  },
33
42
  };
@@ -13,19 +13,27 @@ const rule: Rule.RuleModule = {
13
13
  create(context) {
14
14
  return {
15
15
  ImportDeclaration(node: any) {
16
- const source = node.source.value as string;
17
-
18
- if (source.endsWith('.js')) {
19
- context.report({
20
- node: node.source,
21
- messageId: 'forbiddenJsExtension',
22
- fix(fixer) {
23
- // Remove .js extension
24
- const newSource = source.replace(/\.js$/, '');
25
-
26
- return fixer.replaceText(node.source, `'${newSource}'`);
27
- },
28
- });
16
+ try {
17
+ const source = node.source?.value as string;
18
+
19
+ if (source && source.endsWith('.js')) {
20
+ context.report({
21
+ node: node.source,
22
+ messageId: 'forbiddenJsExtension',
23
+ fix(fixer) {
24
+ try {
25
+ // Remove .js extension
26
+ const newSource = source.replace(/\.js$/, '');
27
+ return fixer.replaceText(node.source, `'${newSource}'`);
28
+ } catch (fixError) {
29
+ console.error('[no-js-import] Error in fix function:', fixError);
30
+ return null;
31
+ }
32
+ },
33
+ });
34
+ }
35
+ } catch (error) {
36
+ console.error('[no-js-import] Error in ImportDeclaration visitor:', error);
29
37
  }
30
38
  },
31
39
  };
@@ -13,8 +13,12 @@ const rule: Rule.RuleModule = {
13
13
  create(context) {
14
14
  return {
15
15
  Identifier(node) {
16
- // Future: use dyfmUtils naming patterns to validate identifiers
17
- void node;
16
+ try {
17
+ // Future: use dyfmUtils naming patterns to validate identifiers
18
+ void node;
19
+ } catch (error) {
20
+ console.error('[naming-patterns] Error in Identifier visitor:', error);
21
+ }
18
22
  },
19
23
  };
20
24
  },
@@ -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,114 @@
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
 
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
+ */
17
76
  async function main() {
77
+ // Find all ESLint configuration files, excluding node_modules
18
78
  const files = await fg([ '**/.eslintrc.json' ], { ignore: [ '**/node_modules/**' ] });
19
79
  const ruleCounts: Record<string, number> = {};
20
80
  const total = 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
 
95
+ // Sort rules by usage count (most used first)
32
96
  const entries = Object.entries(ruleCounts).sort((a, b) => b[1] - a[1]);
33
97
 
98
+ // Display results
34
99
  console.log(`[dynamo-eslintrc-audit] analyzed ${total} files`);
35
100
  console.table(entries.slice(0, 50).map(([ rule, count ]) => ({ rule, count })));
36
101
  }
37
102
 
103
+ // Execute the main function and handle any errors
38
104
  main().catch((err) => {
39
105
  console.error(err);
40
106
  process.exit(1);
41
107
  });
42
108
 
43
109
 
110
+
111
+
112
+
113
+
114
+