@webpieces/dev-config 0.2.95 → 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 (181) 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/src/executors/validate-eslint-sync/executor.js.map +1 -0
  7. package/{executors → src/executors}/validate-versions-locked/executor.js +2 -1
  8. package/src/executors/validate-versions-locked/executor.js.map +1 -0
  9. package/src/index.d.ts +1 -1
  10. package/src/index.js +1 -1
  11. package/src/index.js.map +1 -1
  12. package/src/plugin.d.ts +86 -0
  13. package/{plugin.js → src/plugin.js} +31 -15
  14. package/src/plugin.js.map +1 -0
  15. package/src/toError.d.ts +5 -0
  16. package/src/toError.js +37 -0
  17. package/src/toError.js.map +1 -0
  18. package/templates/eslint.webpieces.config.mjs +1 -1
  19. package/architecture/executors/diff-utils.d.ts +0 -24
  20. package/architecture/executors/diff-utils.js +0 -119
  21. package/architecture/executors/diff-utils.js.map +0 -1
  22. package/architecture/executors/diff-utils.ts +0 -127
  23. package/architecture/executors/generate/executor.d.ts +0 -16
  24. package/architecture/executors/generate/executor.js +0 -44
  25. package/architecture/executors/generate/executor.js.map +0 -1
  26. package/architecture/executors/generate/executor.ts +0 -59
  27. package/architecture/executors/generate/schema.json +0 -14
  28. package/architecture/executors/validate-architecture-unchanged/executor.d.ts +0 -17
  29. package/architecture/executors/validate-architecture-unchanged/executor.js +0 -229
  30. package/architecture/executors/validate-architecture-unchanged/executor.js.map +0 -1
  31. package/architecture/executors/validate-architecture-unchanged/executor.ts +0 -251
  32. package/architecture/executors/validate-architecture-unchanged/schema.json +0 -14
  33. package/architecture/executors/validate-code/executor.d.ts +0 -78
  34. package/architecture/executors/validate-code/executor.js +0 -243
  35. package/architecture/executors/validate-code/executor.js.map +0 -1
  36. package/architecture/executors/validate-code/executor.ts +0 -406
  37. package/architecture/executors/validate-code/schema.json +0 -227
  38. package/architecture/executors/validate-dtos/executor.d.ts +0 -42
  39. package/architecture/executors/validate-dtos/executor.js +0 -561
  40. package/architecture/executors/validate-dtos/executor.js.map +0 -1
  41. package/architecture/executors/validate-dtos/executor.ts +0 -689
  42. package/architecture/executors/validate-dtos/schema.json +0 -33
  43. package/architecture/executors/validate-modified-files/executor.d.ts +0 -25
  44. package/architecture/executors/validate-modified-files/executor.js +0 -501
  45. package/architecture/executors/validate-modified-files/executor.js.map +0 -1
  46. package/architecture/executors/validate-modified-files/executor.ts +0 -571
  47. package/architecture/executors/validate-modified-files/schema.json +0 -25
  48. package/architecture/executors/validate-modified-methods/executor.d.ts +0 -31
  49. package/architecture/executors/validate-modified-methods/executor.js +0 -694
  50. package/architecture/executors/validate-modified-methods/executor.js.map +0 -1
  51. package/architecture/executors/validate-modified-methods/executor.ts +0 -797
  52. package/architecture/executors/validate-modified-methods/schema.json +0 -25
  53. package/architecture/executors/validate-new-methods/executor.d.ts +0 -28
  54. package/architecture/executors/validate-new-methods/executor.js +0 -513
  55. package/architecture/executors/validate-new-methods/executor.js.map +0 -1
  56. package/architecture/executors/validate-new-methods/executor.ts +0 -584
  57. package/architecture/executors/validate-new-methods/schema.json +0 -25
  58. package/architecture/executors/validate-no-any-unknown/executor.d.ts +0 -42
  59. package/architecture/executors/validate-no-any-unknown/executor.js +0 -462
  60. package/architecture/executors/validate-no-any-unknown/executor.js.map +0 -1
  61. package/architecture/executors/validate-no-any-unknown/executor.ts +0 -540
  62. package/architecture/executors/validate-no-any-unknown/schema.json +0 -24
  63. package/architecture/executors/validate-no-architecture-cycles/executor.d.ts +0 -16
  64. package/architecture/executors/validate-no-architecture-cycles/executor.js +0 -48
  65. package/architecture/executors/validate-no-architecture-cycles/executor.js.map +0 -1
  66. package/architecture/executors/validate-no-architecture-cycles/executor.ts +0 -60
  67. package/architecture/executors/validate-no-architecture-cycles/schema.json +0 -8
  68. package/architecture/executors/validate-no-destructure/executor.d.ts +0 -52
  69. package/architecture/executors/validate-no-destructure/executor.js +0 -491
  70. package/architecture/executors/validate-no-destructure/executor.js.map +0 -1
  71. package/architecture/executors/validate-no-destructure/executor.ts +0 -578
  72. package/architecture/executors/validate-no-destructure/schema.json +0 -24
  73. package/architecture/executors/validate-no-direct-api-resolver/executor.d.ts +0 -47
  74. package/architecture/executors/validate-no-direct-api-resolver/executor.js +0 -566
  75. package/architecture/executors/validate-no-direct-api-resolver/executor.js.map +0 -1
  76. package/architecture/executors/validate-no-direct-api-resolver/executor.ts +0 -666
  77. package/architecture/executors/validate-no-direct-api-resolver/schema.json +0 -29
  78. package/architecture/executors/validate-no-inline-types/executor.d.ts +0 -91
  79. package/architecture/executors/validate-no-inline-types/executor.js +0 -669
  80. package/architecture/executors/validate-no-inline-types/executor.js.map +0 -1
  81. package/architecture/executors/validate-no-inline-types/executor.ts +0 -775
  82. package/architecture/executors/validate-no-inline-types/schema.json +0 -24
  83. package/architecture/executors/validate-no-skiplevel-deps/executor.d.ts +0 -19
  84. package/architecture/executors/validate-no-skiplevel-deps/executor.js +0 -227
  85. package/architecture/executors/validate-no-skiplevel-deps/executor.js.map +0 -1
  86. package/architecture/executors/validate-no-skiplevel-deps/executor.ts +0 -267
  87. package/architecture/executors/validate-no-skiplevel-deps/schema.json +0 -8
  88. package/architecture/executors/validate-packagejson/executor.d.ts +0 -16
  89. package/architecture/executors/validate-packagejson/executor.js +0 -57
  90. package/architecture/executors/validate-packagejson/executor.js.map +0 -1
  91. package/architecture/executors/validate-packagejson/executor.ts +0 -74
  92. package/architecture/executors/validate-packagejson/schema.json +0 -8
  93. package/architecture/executors/validate-prisma-converters/executor.d.ts +0 -60
  94. package/architecture/executors/validate-prisma-converters/executor.js +0 -634
  95. package/architecture/executors/validate-prisma-converters/executor.js.map +0 -1
  96. package/architecture/executors/validate-prisma-converters/executor.ts +0 -822
  97. package/architecture/executors/validate-prisma-converters/schema.json +0 -38
  98. package/architecture/executors/validate-return-types/executor.d.ts +0 -29
  99. package/architecture/executors/validate-return-types/executor.js +0 -439
  100. package/architecture/executors/validate-return-types/executor.js.map +0 -1
  101. package/architecture/executors/validate-return-types/executor.ts +0 -524
  102. package/architecture/executors/validate-return-types/schema.json +0 -24
  103. package/architecture/executors/visualize/executor.d.ts +0 -17
  104. package/architecture/executors/visualize/executor.js +0 -49
  105. package/architecture/executors/visualize/executor.js.map +0 -1
  106. package/architecture/executors/visualize/executor.ts +0 -63
  107. package/architecture/executors/visualize/schema.json +0 -14
  108. package/architecture/index.d.ts +0 -19
  109. package/architecture/index.js +0 -23
  110. package/architecture/index.js.map +0 -1
  111. package/architecture/index.ts +0 -20
  112. package/architecture/lib/graph-comparator.d.ts +0 -39
  113. package/architecture/lib/graph-comparator.js +0 -100
  114. package/architecture/lib/graph-comparator.js.map +0 -1
  115. package/architecture/lib/graph-comparator.ts +0 -141
  116. package/architecture/lib/graph-generator.d.ts +0 -19
  117. package/architecture/lib/graph-generator.js +0 -84
  118. package/architecture/lib/graph-generator.js.map +0 -1
  119. package/architecture/lib/graph-generator.ts +0 -97
  120. package/architecture/lib/graph-loader.d.ts +0 -31
  121. package/architecture/lib/graph-loader.js +0 -98
  122. package/architecture/lib/graph-loader.js.map +0 -1
  123. package/architecture/lib/graph-loader.ts +0 -116
  124. package/architecture/lib/graph-sorter.d.ts +0 -37
  125. package/architecture/lib/graph-sorter.js +0 -110
  126. package/architecture/lib/graph-sorter.js.map +0 -1
  127. package/architecture/lib/graph-sorter.ts +0 -137
  128. package/architecture/lib/graph-visualizer.d.ts +0 -29
  129. package/architecture/lib/graph-visualizer.js +0 -217
  130. package/architecture/lib/graph-visualizer.js.map +0 -1
  131. package/architecture/lib/graph-visualizer.ts +0 -231
  132. package/architecture/lib/package-validator.d.ts +0 -38
  133. package/architecture/lib/package-validator.js +0 -126
  134. package/architecture/lib/package-validator.js.map +0 -1
  135. package/architecture/lib/package-validator.ts +0 -170
  136. package/eslint-plugin/__tests__/catch-error-pattern.test.ts +0 -374
  137. package/eslint-plugin/__tests__/max-file-lines.test.ts +0 -207
  138. package/eslint-plugin/__tests__/max-method-lines.test.ts +0 -258
  139. package/eslint-plugin/__tests__/no-unmanaged-exceptions.test.ts +0 -359
  140. package/eslint-plugin/index.d.ts +0 -23
  141. package/eslint-plugin/index.js +0 -30
  142. package/eslint-plugin/index.js.map +0 -1
  143. package/eslint-plugin/index.ts +0 -29
  144. package/eslint-plugin/rules/catch-error-pattern.d.ts +0 -11
  145. package/eslint-plugin/rules/catch-error-pattern.js +0 -143
  146. package/eslint-plugin/rules/catch-error-pattern.js.map +0 -1
  147. package/eslint-plugin/rules/catch-error-pattern.ts +0 -246
  148. package/eslint-plugin/rules/enforce-architecture.d.ts +0 -15
  149. package/eslint-plugin/rules/enforce-architecture.js +0 -476
  150. package/eslint-plugin/rules/enforce-architecture.js.map +0 -1
  151. package/eslint-plugin/rules/enforce-architecture.ts +0 -543
  152. package/eslint-plugin/rules/max-file-lines.d.ts +0 -12
  153. package/eslint-plugin/rules/max-file-lines.js +0 -257
  154. package/eslint-plugin/rules/max-file-lines.js.map +0 -1
  155. package/eslint-plugin/rules/max-file-lines.ts +0 -272
  156. package/eslint-plugin/rules/max-method-lines.d.ts +0 -12
  157. package/eslint-plugin/rules/max-method-lines.js +0 -240
  158. package/eslint-plugin/rules/max-method-lines.js.map +0 -1
  159. package/eslint-plugin/rules/max-method-lines.ts +0 -287
  160. package/eslint-plugin/rules/no-unmanaged-exceptions.d.ts +0 -22
  161. package/eslint-plugin/rules/no-unmanaged-exceptions.js +0 -160
  162. package/eslint-plugin/rules/no-unmanaged-exceptions.js.map +0 -1
  163. package/eslint-plugin/rules/no-unmanaged-exceptions.ts +0 -179
  164. package/executors/help/executor.js.map +0 -1
  165. package/executors/help/executor.ts +0 -61
  166. package/executors/validate-eslint-sync/executor.js.map +0 -1
  167. package/executors/validate-eslint-sync/executor.ts +0 -87
  168. package/executors/validate-versions-locked/executor.js.map +0 -1
  169. package/executors/validate-versions-locked/executor.ts +0 -368
  170. package/plugin/README.md +0 -243
  171. package/plugin/index.d.ts +0 -4
  172. package/plugin/index.js +0 -8
  173. package/plugin/index.js.map +0 -1
  174. package/plugin/index.ts +0 -4
  175. /package/{executors → src/executors}/help/executor.js +0 -0
  176. /package/{executors → src/executors}/help/schema.json +0 -0
  177. /package/{executors → src/executors}/validate-eslint-sync/executor.d.ts +0 -0
  178. /package/{executors → src/executors}/validate-eslint-sync/executor.js +0 -0
  179. /package/{executors → src/executors}/validate-eslint-sync/schema.json +0 -0
  180. /package/{executors → src/executors}/validate-versions-locked/executor.d.ts +0 -0
  181. /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,374 +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: unknown) {
28
- const error = toError(err);
29
- }`,
30
- },
31
- // Pattern 1 with additional statements after toError
32
- {
33
- code: `try {
34
- doSomething();
35
- } catch (err: unknown) {
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: unknown) {
46
- //const error = toError(err);
47
- }`,
48
- },
49
- // Pattern 2 with extra whitespace
50
- {
51
- code: `try {
52
- doSomething();
53
- } catch (err: unknown) {
54
- // const error = toError(err);
55
- }`,
56
- },
57
- // Pattern 3: Nested catch blocks
58
- {
59
- code: `try {
60
- doSomething();
61
- } catch (err: unknown) {
62
- const error = toError(err);
63
- try {
64
- cleanup();
65
- } catch (err2: unknown) {
66
- const error2 = toError(err2);
67
- }
68
- }`,
69
- },
70
- // Triple nested
71
- {
72
- code: `try {
73
- operation1();
74
- } catch (err: unknown) {
75
- const error = toError(err);
76
- try {
77
- operation2();
78
- } catch (err2: unknown) {
79
- const error2 = toError(err2);
80
- try {
81
- operation3();
82
- } catch (err3: unknown) {
83
- const error3 = toError(err3);
84
- }
85
- }
86
- }`,
87
- },
88
- // With finally block
89
- {
90
- code: `try {
91
- doSomething();
92
- } catch (err: unknown) {
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: unknown) {
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: unknown) {
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: unknown) {
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 unknown)
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
- // Wrong type annotation (any instead of unknown)
178
- {
179
- code: `
180
- try {
181
- doSomething();
182
- } catch (err: any) {
183
- const error = toError(err);
184
- }
185
- `,
186
- errors: [
187
- {
188
- messageId: 'missingTypeAnnotation',
189
- },
190
- ],
191
- },
192
- // Empty catch block
193
- {
194
- code: `
195
- try {
196
- doSomething();
197
- } catch (err: unknown) {
198
- }
199
- `,
200
- errors: [
201
- {
202
- messageId: 'missingToError',
203
- },
204
- ],
205
- },
206
- // Missing toError call
207
- {
208
- code: `
209
- try {
210
- doSomething();
211
- } catch (err: unknown) {
212
- console.log(err);
213
- }
214
- `,
215
- errors: [
216
- {
217
- messageId: 'missingToError',
218
- },
219
- ],
220
- },
221
- // Wrong variable name (e instead of error)
222
- {
223
- code: `
224
- try {
225
- doSomething();
226
- } catch (err: unknown) {
227
- const e = toError(err);
228
- }
229
- `,
230
- errors: [
231
- {
232
- messageId: 'wrongVariableName',
233
- data: { expected: 'error', actual: 'e' },
234
- },
235
- ],
236
- },
237
- // Wrong variable name (myError instead of error)
238
- {
239
- code: `
240
- try {
241
- doSomething();
242
- } catch (err: unknown) {
243
- const myError = toError(err);
244
- }
245
- `,
246
- errors: [
247
- {
248
- messageId: 'wrongVariableName',
249
- data: { expected: 'error', actual: 'myError' },
250
- },
251
- ],
252
- },
253
- // toError not first statement
254
- {
255
- code: `
256
- try {
257
- doSomething();
258
- } catch (err: unknown) {
259
- console.log('caught error');
260
- const error = toError(err);
261
- }
262
- `,
263
- errors: [
264
- {
265
- messageId: 'missingToError',
266
- },
267
- ],
268
- },
269
- // Using wrong function (not toError)
270
- {
271
- code: `
272
- try {
273
- doSomething();
274
- } catch (err: unknown) {
275
- const error = handleError(err);
276
- }
277
- `,
278
- errors: [
279
- {
280
- messageId: 'missingToError',
281
- },
282
- ],
283
- },
284
- // Nested: wrong parameter name for err2
285
- {
286
- code: `
287
- try {
288
- operation1();
289
- } catch (err: unknown) {
290
- const error = toError(err);
291
- try {
292
- operation2();
293
- } catch (e: unknown) {
294
- const error2 = toError(e);
295
- }
296
- }
297
- `,
298
- errors: [
299
- {
300
- messageId: 'wrongParameterName',
301
- data: { actual: 'e' },
302
- },
303
- ],
304
- },
305
- // Nested: wrong variable name for error2
306
- {
307
- code: `
308
- try {
309
- operation1();
310
- } catch (err: unknown) {
311
- const error = toError(err);
312
- try {
313
- operation2();
314
- } catch (err2: unknown) {
315
- const err = toError(err2);
316
- }
317
- }
318
- `,
319
- errors: [
320
- {
321
- messageId: 'wrongVariableName',
322
- data: { expected: 'error2', actual: 'err' },
323
- },
324
- ],
325
- },
326
- // No parameter at all
327
- {
328
- code: `
329
- try {
330
- doSomething();
331
- } catch {
332
- console.log('error');
333
- }
334
- `,
335
- errors: [
336
- {
337
- messageId: 'missingTypeAnnotation',
338
- },
339
- ],
340
- },
341
- // Variable declared but not initialized
342
- {
343
- code: `
344
- try {
345
- doSomething();
346
- } catch (err: unknown) {
347
- const error;
348
- }
349
- `,
350
- errors: [
351
- {
352
- messageId: 'missingToError',
353
- },
354
- ],
355
- },
356
- // Using new Error instead of toError
357
- {
358
- code: `
359
- try {
360
- doSomething();
361
- } catch (err: unknown) {
362
- const error = new Error(err.message);
363
- }
364
- `,
365
- errors: [
366
- {
367
- messageId: 'missingToError',
368
- },
369
- ],
370
- },
371
- ],
372
- });
373
-
374
- console.log('✅ All catch-error-pattern rule tests passed!');