@webpieces/dev-config 0.2.94 → 0.2.97

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 (183) hide show
  1. package/config/eslint/base.mjs +1 -1
  2. package/executors.json +6 -91
  3. package/package.json +6 -19
  4. package/{executors → src/executors}/help/executor.d.ts +4 -2
  5. package/src/executors/help/executor.js.map +1 -0
  6. package/{executors → src/executors}/validate-eslint-sync/executor.d.ts +3 -2
  7. package/src/executors/validate-eslint-sync/executor.js.map +1 -0
  8. package/{executors → src/executors}/validate-versions-locked/executor.js +5 -3
  9. package/src/executors/validate-versions-locked/executor.js.map +1 -0
  10. package/src/generators/init/generator.js.map +1 -1
  11. package/src/index.d.ts +1 -1
  12. package/src/index.js +1 -1
  13. package/src/index.js.map +1 -1
  14. package/src/plugin.d.ts +86 -0
  15. package/{plugin.js → src/plugin.js} +31 -15
  16. package/src/plugin.js.map +1 -0
  17. package/src/toError.d.ts +5 -0
  18. package/src/toError.js +37 -0
  19. package/src/toError.js.map +1 -0
  20. package/templates/eslint.webpieces.config.mjs +1 -1
  21. package/templates/webpieces.exceptions.md +15 -15
  22. package/architecture/executors/diff-utils.d.ts +0 -24
  23. package/architecture/executors/diff-utils.js +0 -119
  24. package/architecture/executors/diff-utils.js.map +0 -1
  25. package/architecture/executors/diff-utils.ts +0 -127
  26. package/architecture/executors/generate/executor.d.ts +0 -16
  27. package/architecture/executors/generate/executor.js +0 -44
  28. package/architecture/executors/generate/executor.js.map +0 -1
  29. package/architecture/executors/generate/executor.ts +0 -59
  30. package/architecture/executors/generate/schema.json +0 -14
  31. package/architecture/executors/validate-architecture-unchanged/executor.d.ts +0 -17
  32. package/architecture/executors/validate-architecture-unchanged/executor.js +0 -229
  33. package/architecture/executors/validate-architecture-unchanged/executor.js.map +0 -1
  34. package/architecture/executors/validate-architecture-unchanged/executor.ts +0 -251
  35. package/architecture/executors/validate-architecture-unchanged/schema.json +0 -14
  36. package/architecture/executors/validate-code/executor.d.ts +0 -78
  37. package/architecture/executors/validate-code/executor.js +0 -243
  38. package/architecture/executors/validate-code/executor.js.map +0 -1
  39. package/architecture/executors/validate-code/executor.ts +0 -406
  40. package/architecture/executors/validate-code/schema.json +0 -227
  41. package/architecture/executors/validate-dtos/executor.d.ts +0 -42
  42. package/architecture/executors/validate-dtos/executor.js +0 -561
  43. package/architecture/executors/validate-dtos/executor.js.map +0 -1
  44. package/architecture/executors/validate-dtos/executor.ts +0 -689
  45. package/architecture/executors/validate-dtos/schema.json +0 -33
  46. package/architecture/executors/validate-modified-files/executor.d.ts +0 -25
  47. package/architecture/executors/validate-modified-files/executor.js +0 -501
  48. package/architecture/executors/validate-modified-files/executor.js.map +0 -1
  49. package/architecture/executors/validate-modified-files/executor.ts +0 -571
  50. package/architecture/executors/validate-modified-files/schema.json +0 -25
  51. package/architecture/executors/validate-modified-methods/executor.d.ts +0 -31
  52. package/architecture/executors/validate-modified-methods/executor.js +0 -694
  53. package/architecture/executors/validate-modified-methods/executor.js.map +0 -1
  54. package/architecture/executors/validate-modified-methods/executor.ts +0 -797
  55. package/architecture/executors/validate-modified-methods/schema.json +0 -25
  56. package/architecture/executors/validate-new-methods/executor.d.ts +0 -28
  57. package/architecture/executors/validate-new-methods/executor.js +0 -513
  58. package/architecture/executors/validate-new-methods/executor.js.map +0 -1
  59. package/architecture/executors/validate-new-methods/executor.ts +0 -584
  60. package/architecture/executors/validate-new-methods/schema.json +0 -25
  61. package/architecture/executors/validate-no-any-unknown/executor.d.ts +0 -42
  62. package/architecture/executors/validate-no-any-unknown/executor.js +0 -462
  63. package/architecture/executors/validate-no-any-unknown/executor.js.map +0 -1
  64. package/architecture/executors/validate-no-any-unknown/executor.ts +0 -540
  65. package/architecture/executors/validate-no-any-unknown/schema.json +0 -24
  66. package/architecture/executors/validate-no-architecture-cycles/executor.d.ts +0 -16
  67. package/architecture/executors/validate-no-architecture-cycles/executor.js +0 -48
  68. package/architecture/executors/validate-no-architecture-cycles/executor.js.map +0 -1
  69. package/architecture/executors/validate-no-architecture-cycles/executor.ts +0 -60
  70. package/architecture/executors/validate-no-architecture-cycles/schema.json +0 -8
  71. package/architecture/executors/validate-no-destructure/executor.d.ts +0 -52
  72. package/architecture/executors/validate-no-destructure/executor.js +0 -491
  73. package/architecture/executors/validate-no-destructure/executor.js.map +0 -1
  74. package/architecture/executors/validate-no-destructure/executor.ts +0 -578
  75. package/architecture/executors/validate-no-destructure/schema.json +0 -24
  76. package/architecture/executors/validate-no-direct-api-resolver/executor.d.ts +0 -47
  77. package/architecture/executors/validate-no-direct-api-resolver/executor.js +0 -566
  78. package/architecture/executors/validate-no-direct-api-resolver/executor.js.map +0 -1
  79. package/architecture/executors/validate-no-direct-api-resolver/executor.ts +0 -666
  80. package/architecture/executors/validate-no-direct-api-resolver/schema.json +0 -29
  81. package/architecture/executors/validate-no-inline-types/executor.d.ts +0 -91
  82. package/architecture/executors/validate-no-inline-types/executor.js +0 -669
  83. package/architecture/executors/validate-no-inline-types/executor.js.map +0 -1
  84. package/architecture/executors/validate-no-inline-types/executor.ts +0 -775
  85. package/architecture/executors/validate-no-inline-types/schema.json +0 -24
  86. package/architecture/executors/validate-no-skiplevel-deps/executor.d.ts +0 -19
  87. package/architecture/executors/validate-no-skiplevel-deps/executor.js +0 -227
  88. package/architecture/executors/validate-no-skiplevel-deps/executor.js.map +0 -1
  89. package/architecture/executors/validate-no-skiplevel-deps/executor.ts +0 -267
  90. package/architecture/executors/validate-no-skiplevel-deps/schema.json +0 -8
  91. package/architecture/executors/validate-packagejson/executor.d.ts +0 -16
  92. package/architecture/executors/validate-packagejson/executor.js +0 -57
  93. package/architecture/executors/validate-packagejson/executor.js.map +0 -1
  94. package/architecture/executors/validate-packagejson/executor.ts +0 -74
  95. package/architecture/executors/validate-packagejson/schema.json +0 -8
  96. package/architecture/executors/validate-prisma-converters/executor.d.ts +0 -60
  97. package/architecture/executors/validate-prisma-converters/executor.js +0 -634
  98. package/architecture/executors/validate-prisma-converters/executor.js.map +0 -1
  99. package/architecture/executors/validate-prisma-converters/executor.ts +0 -822
  100. package/architecture/executors/validate-prisma-converters/schema.json +0 -38
  101. package/architecture/executors/validate-return-types/executor.d.ts +0 -29
  102. package/architecture/executors/validate-return-types/executor.js +0 -439
  103. package/architecture/executors/validate-return-types/executor.js.map +0 -1
  104. package/architecture/executors/validate-return-types/executor.ts +0 -524
  105. package/architecture/executors/validate-return-types/schema.json +0 -24
  106. package/architecture/executors/visualize/executor.d.ts +0 -17
  107. package/architecture/executors/visualize/executor.js +0 -49
  108. package/architecture/executors/visualize/executor.js.map +0 -1
  109. package/architecture/executors/visualize/executor.ts +0 -63
  110. package/architecture/executors/visualize/schema.json +0 -14
  111. package/architecture/index.d.ts +0 -19
  112. package/architecture/index.js +0 -23
  113. package/architecture/index.js.map +0 -1
  114. package/architecture/index.ts +0 -20
  115. package/architecture/lib/graph-comparator.d.ts +0 -39
  116. package/architecture/lib/graph-comparator.js +0 -100
  117. package/architecture/lib/graph-comparator.js.map +0 -1
  118. package/architecture/lib/graph-comparator.ts +0 -141
  119. package/architecture/lib/graph-generator.d.ts +0 -19
  120. package/architecture/lib/graph-generator.js +0 -84
  121. package/architecture/lib/graph-generator.js.map +0 -1
  122. package/architecture/lib/graph-generator.ts +0 -97
  123. package/architecture/lib/graph-loader.d.ts +0 -31
  124. package/architecture/lib/graph-loader.js +0 -98
  125. package/architecture/lib/graph-loader.js.map +0 -1
  126. package/architecture/lib/graph-loader.ts +0 -116
  127. package/architecture/lib/graph-sorter.d.ts +0 -37
  128. package/architecture/lib/graph-sorter.js +0 -110
  129. package/architecture/lib/graph-sorter.js.map +0 -1
  130. package/architecture/lib/graph-sorter.ts +0 -137
  131. package/architecture/lib/graph-visualizer.d.ts +0 -29
  132. package/architecture/lib/graph-visualizer.js +0 -217
  133. package/architecture/lib/graph-visualizer.js.map +0 -1
  134. package/architecture/lib/graph-visualizer.ts +0 -231
  135. package/architecture/lib/package-validator.d.ts +0 -38
  136. package/architecture/lib/package-validator.js +0 -126
  137. package/architecture/lib/package-validator.js.map +0 -1
  138. package/architecture/lib/package-validator.ts +0 -170
  139. package/eslint-plugin/__tests__/catch-error-pattern.test.ts +0 -359
  140. package/eslint-plugin/__tests__/max-file-lines.test.ts +0 -207
  141. package/eslint-plugin/__tests__/max-method-lines.test.ts +0 -258
  142. package/eslint-plugin/__tests__/no-unmanaged-exceptions.test.ts +0 -359
  143. package/eslint-plugin/index.d.ts +0 -23
  144. package/eslint-plugin/index.js +0 -30
  145. package/eslint-plugin/index.js.map +0 -1
  146. package/eslint-plugin/index.ts +0 -29
  147. package/eslint-plugin/rules/catch-error-pattern.d.ts +0 -11
  148. package/eslint-plugin/rules/catch-error-pattern.js +0 -196
  149. package/eslint-plugin/rules/catch-error-pattern.js.map +0 -1
  150. package/eslint-plugin/rules/catch-error-pattern.ts +0 -281
  151. package/eslint-plugin/rules/enforce-architecture.d.ts +0 -15
  152. package/eslint-plugin/rules/enforce-architecture.js +0 -476
  153. package/eslint-plugin/rules/enforce-architecture.js.map +0 -1
  154. package/eslint-plugin/rules/enforce-architecture.ts +0 -543
  155. package/eslint-plugin/rules/max-file-lines.d.ts +0 -12
  156. package/eslint-plugin/rules/max-file-lines.js +0 -257
  157. package/eslint-plugin/rules/max-file-lines.js.map +0 -1
  158. package/eslint-plugin/rules/max-file-lines.ts +0 -272
  159. package/eslint-plugin/rules/max-method-lines.d.ts +0 -12
  160. package/eslint-plugin/rules/max-method-lines.js +0 -240
  161. package/eslint-plugin/rules/max-method-lines.js.map +0 -1
  162. package/eslint-plugin/rules/max-method-lines.ts +0 -287
  163. package/eslint-plugin/rules/no-unmanaged-exceptions.d.ts +0 -22
  164. package/eslint-plugin/rules/no-unmanaged-exceptions.js +0 -160
  165. package/eslint-plugin/rules/no-unmanaged-exceptions.js.map +0 -1
  166. package/eslint-plugin/rules/no-unmanaged-exceptions.ts +0 -179
  167. package/executors/help/executor.js.map +0 -1
  168. package/executors/help/executor.ts +0 -61
  169. package/executors/validate-eslint-sync/executor.js.map +0 -1
  170. package/executors/validate-eslint-sync/executor.ts +0 -83
  171. package/executors/validate-versions-locked/executor.js.map +0 -1
  172. package/executors/validate-versions-locked/executor.ts +0 -367
  173. package/plugin/README.md +0 -243
  174. package/plugin/index.d.ts +0 -4
  175. package/plugin/index.js +0 -8
  176. package/plugin/index.js.map +0 -1
  177. package/plugin/index.ts +0 -4
  178. /package/{executors → src/executors}/help/executor.js +0 -0
  179. /package/{executors → src/executors}/help/schema.json +0 -0
  180. /package/{executors → src/executors}/validate-eslint-sync/executor.js +0 -0
  181. /package/{executors → src/executors}/validate-eslint-sync/schema.json +0 -0
  182. /package/{executors → src/executors}/validate-versions-locked/executor.d.ts +0 -0
  183. /package/{executors → src/executors}/validate-versions-locked/schema.json +0 -0
@@ -1,170 +0,0 @@
1
- /**
2
- * Package Validator
3
- *
4
- * Validates that package.json dependencies match the project.json build.dependsOn
5
- * This ensures the two sources of truth don't drift apart.
6
- */
7
-
8
- import * as fs from 'fs';
9
- import * as path from 'path';
10
- import {
11
- createProjectGraphAsync,
12
- readProjectsConfigurationFromProjectGraph,
13
- } from '@nx/devkit';
14
-
15
- /**
16
- * Validation result for a single project
17
- */
18
- export interface ProjectValidationResult {
19
- project: string;
20
- valid: boolean;
21
- missingInPackageJson: string[];
22
- extraInPackageJson: string[];
23
- }
24
-
25
- /**
26
- * Overall validation result
27
- */
28
- export interface ValidationResult {
29
- valid: boolean;
30
- errors: string[];
31
- projectResults: ProjectValidationResult[];
32
- }
33
-
34
- /**
35
- * Read package.json dependencies for a project
36
- * Returns null if package.json doesn't exist (apps often don't have one)
37
- */
38
- function readPackageJsonDeps(workspaceRoot: string, projectRoot: string): string[] | null {
39
- const packageJsonPath = path.join(workspaceRoot, projectRoot, 'package.json');
40
-
41
- if (!fs.existsSync(packageJsonPath)) {
42
- return null; // No package.json - skip validation for this project
43
- }
44
-
45
- try {
46
- const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
47
- const deps: string[] = [];
48
-
49
- // Collect ALL dependencies from package.json
50
- for (const depType of ['dependencies', 'peerDependencies']) {
51
- const depObj = packageJson[depType] || {};
52
- for (const depName of Object.keys(depObj)) {
53
- if (!deps.includes(depName)) {
54
- deps.push(depName);
55
- }
56
- }
57
- }
58
-
59
- return deps.sort();
60
- } catch (err: unknown) {
61
- console.warn(`Could not read package.json at ${packageJsonPath}`);
62
- return [];
63
- }
64
- }
65
-
66
- /**
67
- * Build map of project names to their package names
68
- * e.g., "core-util" → "@webpieces/core-util"
69
- */
70
- function buildProjectToPackageMap(
71
- workspaceRoot: string,
72
- projectsConfig: any
73
- ): Map<string, string> {
74
- const map = new Map<string, string>();
75
-
76
- for (const [projectName, config] of Object.entries<any>(projectsConfig.projects)) {
77
- const packageJsonPath = path.join(workspaceRoot, config.root, 'package.json');
78
- if (fs.existsSync(packageJsonPath)) {
79
- try {
80
- const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
81
- if (packageJson.name) {
82
- map.set(projectName, packageJson.name);
83
- }
84
- } catch {
85
- // Ignore parse errors
86
- }
87
- }
88
- }
89
-
90
- return map;
91
- }
92
-
93
- /**
94
- * Validate that package.json dependencies match the dependency graph
95
- *
96
- * For each project in the graph:
97
- * - Check that all graph dependencies exist in package.json
98
- * - Maps project names to package names for accurate comparison
99
- *
100
- * @param graph - Enhanced graph with project dependencies (uses project names)
101
- * @param workspaceRoot - Absolute path to workspace root
102
- * @returns Validation result with errors if any
103
- */
104
- export async function validatePackageJsonDependencies(
105
- graph: Record<string, { level: number; dependsOn: string[] }>,
106
- workspaceRoot: string
107
- ): Promise<ValidationResult> {
108
- const projectGraph = await createProjectGraphAsync();
109
- const projectsConfig = readProjectsConfigurationFromProjectGraph(projectGraph);
110
-
111
- // Build map: project name → package name
112
- const projectToPackage = buildProjectToPackageMap(workspaceRoot, projectsConfig);
113
-
114
- const errors: string[] = [];
115
- const projectResults: ProjectValidationResult[] = [];
116
-
117
- for (const [projectName, entry] of Object.entries(graph)) {
118
- // Find the project config using project name directly
119
- const projectConfig = projectsConfig.projects[projectName];
120
- if (!projectConfig) {
121
- continue;
122
- }
123
-
124
- const projectRoot = projectConfig.root;
125
- const packageJsonDeps = readPackageJsonDeps(workspaceRoot, projectRoot);
126
-
127
- if (packageJsonDeps === null) {
128
- continue;
129
- }
130
-
131
- // Convert graph dependencies (project names) to package names for comparison
132
- const missingInPackageJson: string[] = [];
133
- for (const depProjectName of entry.dependsOn) {
134
- const depPackageName = projectToPackage.get(depProjectName) || depProjectName;
135
- if (!packageJsonDeps.includes(depPackageName)) {
136
- missingInPackageJson.push(depProjectName);
137
- }
138
- }
139
-
140
- // Check for extra dependencies in package.json (not critical, just informational)
141
- const extraInPackageJson: string[] = [];
142
- for (const dep of packageJsonDeps) {
143
- if (!entry.dependsOn.includes(dep)) {
144
- extraInPackageJson.push(dep);
145
- }
146
- }
147
-
148
- const valid = missingInPackageJson.length === 0;
149
-
150
- if (!valid) {
151
- errors.push(
152
- `Project ${projectName} (${projectRoot}/package.json) is missing dependencies: ${missingInPackageJson.join(', ')}\n` +
153
- ` Fix: Add these to package.json dependencies`
154
- );
155
- }
156
-
157
- projectResults.push({
158
- project: projectName,
159
- valid,
160
- missingInPackageJson,
161
- extraInPackageJson,
162
- });
163
- }
164
-
165
- return {
166
- valid: errors.length === 0,
167
- errors,
168
- projectResults,
169
- };
170
- }
@@ -1,359 +0,0 @@
1
- /**
2
- * Tests for catch-error-pattern ESLint rule
3
- */
4
-
5
- import { RuleTester } from 'eslint';
6
- import rule from '../rules/catch-error-pattern';
7
-
8
- // Use require to load parser at runtime (avoids TypeScript import issues)
9
- const tsParser = require('@typescript-eslint/parser');
10
-
11
- const ruleTester = new RuleTester({
12
- languageOptions: {
13
- parser: tsParser,
14
- parserOptions: {
15
- ecmaVersion: 2020,
16
- sourceType: 'module',
17
- },
18
- },
19
- });
20
-
21
- ruleTester.run('catch-error-pattern', rule, {
22
- valid: [
23
- // Pattern 1: Standard toError usage
24
- {
25
- code: `try {
26
- doSomething();
27
- } catch (err: any) {
28
- const error = toError(err);
29
- }`,
30
- },
31
- // Pattern 1 with additional statements after toError
32
- {
33
- code: `try {
34
- doSomething();
35
- } catch (err: any) {
36
- const error = toError(err);
37
- console.log('Error occurred:', error);
38
- throw error;
39
- }`,
40
- },
41
- // Pattern 2: Explicitly ignored error
42
- {
43
- code: `try {
44
- doSomething();
45
- } catch (err: any) {
46
- //const error = toError(err);
47
- }`,
48
- },
49
- // Pattern 2 with extra whitespace
50
- {
51
- code: `try {
52
- doSomething();
53
- } catch (err: any) {
54
- // const error = toError(err);
55
- }`,
56
- },
57
- // Pattern 3: Nested catch blocks
58
- {
59
- code: `try {
60
- doSomething();
61
- } catch (err: any) {
62
- const error = toError(err);
63
- try {
64
- cleanup();
65
- } catch (err2: any) {
66
- const error2 = toError(err2);
67
- }
68
- }`,
69
- },
70
- // Triple nested
71
- {
72
- code: `try {
73
- operation1();
74
- } catch (err: any) {
75
- const error = toError(err);
76
- try {
77
- operation2();
78
- } catch (err2: any) {
79
- const error2 = toError(err2);
80
- try {
81
- operation3();
82
- } catch (err3: any) {
83
- const error3 = toError(err3);
84
- }
85
- }
86
- }`,
87
- },
88
- // With finally block
89
- {
90
- code: `try {
91
- doSomething();
92
- } catch (err: any) {
93
- const error = toError(err);
94
- } finally {
95
- cleanup();
96
- }`,
97
- },
98
- // Re-throwing after toError
99
- {
100
- code: `try {
101
- doSomething();
102
- } catch (err: any) {
103
- const error = toError(err);
104
- logger.error(error);
105
- throw error;
106
- }`,
107
- },
108
- ],
109
-
110
- invalid: [
111
- // Wrong parameter name (e instead of err)
112
- {
113
- code: `
114
- try {
115
- doSomething();
116
- } catch (e: any) {
117
- const error = toError(e);
118
- }
119
- `,
120
- errors: [
121
- {
122
- messageId: 'wrongParameterName',
123
- data: { actual: 'e' },
124
- },
125
- ],
126
- },
127
- // Wrong parameter name (error instead of err) AND wrong variable name
128
- {
129
- code: `
130
- try {
131
- doSomething();
132
- } catch (error: any) {
133
- const error2 = toError(error);
134
- }
135
- `,
136
- errors: [
137
- {
138
- messageId: 'wrongParameterName',
139
- data: { actual: 'error' },
140
- },
141
- {
142
- messageId: 'wrongVariableName',
143
- data: { expected: 'error', actual: 'error2' },
144
- },
145
- ],
146
- },
147
- // Missing type annotation
148
- {
149
- code: `
150
- try {
151
- doSomething();
152
- } catch (err) {
153
- const error = toError(err);
154
- }
155
- `,
156
- errors: [
157
- {
158
- messageId: 'missingTypeAnnotation',
159
- },
160
- ],
161
- },
162
- // Wrong type annotation (Error instead of any)
163
- {
164
- code: `
165
- try {
166
- doSomething();
167
- } catch (err: Error) {
168
- const error = toError(err);
169
- }
170
- `,
171
- errors: [
172
- {
173
- messageId: 'missingTypeAnnotation',
174
- },
175
- ],
176
- },
177
- // Empty catch block
178
- {
179
- code: `
180
- try {
181
- doSomething();
182
- } catch (err: any) {
183
- }
184
- `,
185
- errors: [
186
- {
187
- messageId: 'missingToError',
188
- },
189
- ],
190
- },
191
- // Missing toError call
192
- {
193
- code: `
194
- try {
195
- doSomething();
196
- } catch (err: any) {
197
- console.log(err);
198
- }
199
- `,
200
- errors: [
201
- {
202
- messageId: 'missingToError',
203
- },
204
- ],
205
- },
206
- // Wrong variable name (e instead of error)
207
- {
208
- code: `
209
- try {
210
- doSomething();
211
- } catch (err: any) {
212
- const e = toError(err);
213
- }
214
- `,
215
- errors: [
216
- {
217
- messageId: 'wrongVariableName',
218
- data: { expected: 'error', actual: 'e' },
219
- },
220
- ],
221
- },
222
- // Wrong variable name (myError instead of error)
223
- {
224
- code: `
225
- try {
226
- doSomething();
227
- } catch (err: any) {
228
- const myError = toError(err);
229
- }
230
- `,
231
- errors: [
232
- {
233
- messageId: 'wrongVariableName',
234
- data: { expected: 'error', actual: 'myError' },
235
- },
236
- ],
237
- },
238
- // toError not first statement
239
- {
240
- code: `
241
- try {
242
- doSomething();
243
- } catch (err: any) {
244
- console.log('caught error');
245
- const error = toError(err);
246
- }
247
- `,
248
- errors: [
249
- {
250
- messageId: 'missingToError',
251
- },
252
- ],
253
- },
254
- // Using wrong function (not toError)
255
- {
256
- code: `
257
- try {
258
- doSomething();
259
- } catch (err: any) {
260
- const error = handleError(err);
261
- }
262
- `,
263
- errors: [
264
- {
265
- messageId: 'missingToError',
266
- },
267
- ],
268
- },
269
- // Nested: wrong parameter name for err2
270
- {
271
- code: `
272
- try {
273
- operation1();
274
- } catch (err: any) {
275
- const error = toError(err);
276
- try {
277
- operation2();
278
- } catch (e: any) {
279
- const error2 = toError(e);
280
- }
281
- }
282
- `,
283
- errors: [
284
- {
285
- messageId: 'wrongParameterName',
286
- data: { actual: 'e' },
287
- },
288
- ],
289
- },
290
- // Nested: wrong variable name for error2
291
- {
292
- code: `
293
- try {
294
- operation1();
295
- } catch (err: any) {
296
- const error = toError(err);
297
- try {
298
- operation2();
299
- } catch (err2: any) {
300
- const err = toError(err2);
301
- }
302
- }
303
- `,
304
- errors: [
305
- {
306
- messageId: 'wrongVariableName',
307
- data: { expected: 'error2', actual: 'err' },
308
- },
309
- ],
310
- },
311
- // No parameter at all
312
- {
313
- code: `
314
- try {
315
- doSomething();
316
- } catch {
317
- console.log('error');
318
- }
319
- `,
320
- errors: [
321
- {
322
- messageId: 'missingTypeAnnotation',
323
- },
324
- ],
325
- },
326
- // Variable declared but not initialized
327
- {
328
- code: `
329
- try {
330
- doSomething();
331
- } catch (err: any) {
332
- const error;
333
- }
334
- `,
335
- errors: [
336
- {
337
- messageId: 'missingToError',
338
- },
339
- ],
340
- },
341
- // Using new Error instead of toError
342
- {
343
- code: `
344
- try {
345
- doSomething();
346
- } catch (err: any) {
347
- const error = new Error(err.message);
348
- }
349
- `,
350
- errors: [
351
- {
352
- messageId: 'missingToError',
353
- },
354
- ],
355
- },
356
- ],
357
- });
358
-
359
- console.log('✅ All catch-error-pattern rule tests passed!');