@webpieces/dev-config 0.2.95 → 0.2.98
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/config/eslint/base.mjs +1 -1
- package/executors.json +6 -91
- package/package.json +6 -19
- package/{executors → src/executors}/help/executor.d.ts +4 -2
- package/src/executors/help/executor.js.map +1 -0
- package/src/executors/validate-eslint-sync/executor.js.map +1 -0
- package/{executors → src/executors}/validate-versions-locked/executor.js +2 -1
- package/src/executors/validate-versions-locked/executor.js.map +1 -0
- package/src/index.d.ts +1 -1
- package/src/index.js +1 -1
- package/src/index.js.map +1 -1
- package/src/plugin.d.ts +86 -0
- package/{plugin.js → src/plugin.js} +31 -15
- package/src/plugin.js.map +1 -0
- package/src/toError.d.ts +5 -0
- package/src/toError.js +37 -0
- package/src/toError.js.map +1 -0
- package/templates/eslint.webpieces.config.mjs +1 -1
- package/architecture/executors/diff-utils.d.ts +0 -24
- package/architecture/executors/diff-utils.js +0 -119
- package/architecture/executors/diff-utils.js.map +0 -1
- package/architecture/executors/diff-utils.ts +0 -127
- package/architecture/executors/generate/executor.d.ts +0 -16
- package/architecture/executors/generate/executor.js +0 -44
- package/architecture/executors/generate/executor.js.map +0 -1
- package/architecture/executors/generate/executor.ts +0 -59
- package/architecture/executors/generate/schema.json +0 -14
- package/architecture/executors/validate-architecture-unchanged/executor.d.ts +0 -17
- package/architecture/executors/validate-architecture-unchanged/executor.js +0 -229
- package/architecture/executors/validate-architecture-unchanged/executor.js.map +0 -1
- package/architecture/executors/validate-architecture-unchanged/executor.ts +0 -251
- package/architecture/executors/validate-architecture-unchanged/schema.json +0 -14
- package/architecture/executors/validate-code/executor.d.ts +0 -78
- package/architecture/executors/validate-code/executor.js +0 -243
- package/architecture/executors/validate-code/executor.js.map +0 -1
- package/architecture/executors/validate-code/executor.ts +0 -406
- package/architecture/executors/validate-code/schema.json +0 -227
- package/architecture/executors/validate-dtos/executor.d.ts +0 -42
- package/architecture/executors/validate-dtos/executor.js +0 -561
- package/architecture/executors/validate-dtos/executor.js.map +0 -1
- package/architecture/executors/validate-dtos/executor.ts +0 -689
- package/architecture/executors/validate-dtos/schema.json +0 -33
- package/architecture/executors/validate-modified-files/executor.d.ts +0 -25
- package/architecture/executors/validate-modified-files/executor.js +0 -501
- package/architecture/executors/validate-modified-files/executor.js.map +0 -1
- package/architecture/executors/validate-modified-files/executor.ts +0 -571
- package/architecture/executors/validate-modified-files/schema.json +0 -25
- package/architecture/executors/validate-modified-methods/executor.d.ts +0 -31
- package/architecture/executors/validate-modified-methods/executor.js +0 -694
- package/architecture/executors/validate-modified-methods/executor.js.map +0 -1
- package/architecture/executors/validate-modified-methods/executor.ts +0 -797
- package/architecture/executors/validate-modified-methods/schema.json +0 -25
- package/architecture/executors/validate-new-methods/executor.d.ts +0 -28
- package/architecture/executors/validate-new-methods/executor.js +0 -513
- package/architecture/executors/validate-new-methods/executor.js.map +0 -1
- package/architecture/executors/validate-new-methods/executor.ts +0 -584
- package/architecture/executors/validate-new-methods/schema.json +0 -25
- package/architecture/executors/validate-no-any-unknown/executor.d.ts +0 -42
- package/architecture/executors/validate-no-any-unknown/executor.js +0 -462
- package/architecture/executors/validate-no-any-unknown/executor.js.map +0 -1
- package/architecture/executors/validate-no-any-unknown/executor.ts +0 -540
- package/architecture/executors/validate-no-any-unknown/schema.json +0 -24
- package/architecture/executors/validate-no-architecture-cycles/executor.d.ts +0 -16
- package/architecture/executors/validate-no-architecture-cycles/executor.js +0 -48
- package/architecture/executors/validate-no-architecture-cycles/executor.js.map +0 -1
- package/architecture/executors/validate-no-architecture-cycles/executor.ts +0 -60
- package/architecture/executors/validate-no-architecture-cycles/schema.json +0 -8
- package/architecture/executors/validate-no-destructure/executor.d.ts +0 -52
- package/architecture/executors/validate-no-destructure/executor.js +0 -491
- package/architecture/executors/validate-no-destructure/executor.js.map +0 -1
- package/architecture/executors/validate-no-destructure/executor.ts +0 -578
- package/architecture/executors/validate-no-destructure/schema.json +0 -24
- package/architecture/executors/validate-no-direct-api-resolver/executor.d.ts +0 -47
- package/architecture/executors/validate-no-direct-api-resolver/executor.js +0 -566
- package/architecture/executors/validate-no-direct-api-resolver/executor.js.map +0 -1
- package/architecture/executors/validate-no-direct-api-resolver/executor.ts +0 -666
- package/architecture/executors/validate-no-direct-api-resolver/schema.json +0 -29
- package/architecture/executors/validate-no-inline-types/executor.d.ts +0 -91
- package/architecture/executors/validate-no-inline-types/executor.js +0 -669
- package/architecture/executors/validate-no-inline-types/executor.js.map +0 -1
- package/architecture/executors/validate-no-inline-types/executor.ts +0 -775
- package/architecture/executors/validate-no-inline-types/schema.json +0 -24
- package/architecture/executors/validate-no-skiplevel-deps/executor.d.ts +0 -19
- package/architecture/executors/validate-no-skiplevel-deps/executor.js +0 -227
- package/architecture/executors/validate-no-skiplevel-deps/executor.js.map +0 -1
- package/architecture/executors/validate-no-skiplevel-deps/executor.ts +0 -267
- package/architecture/executors/validate-no-skiplevel-deps/schema.json +0 -8
- package/architecture/executors/validate-packagejson/executor.d.ts +0 -16
- package/architecture/executors/validate-packagejson/executor.js +0 -57
- package/architecture/executors/validate-packagejson/executor.js.map +0 -1
- package/architecture/executors/validate-packagejson/executor.ts +0 -74
- package/architecture/executors/validate-packagejson/schema.json +0 -8
- package/architecture/executors/validate-prisma-converters/executor.d.ts +0 -60
- package/architecture/executors/validate-prisma-converters/executor.js +0 -634
- package/architecture/executors/validate-prisma-converters/executor.js.map +0 -1
- package/architecture/executors/validate-prisma-converters/executor.ts +0 -822
- package/architecture/executors/validate-prisma-converters/schema.json +0 -38
- package/architecture/executors/validate-return-types/executor.d.ts +0 -29
- package/architecture/executors/validate-return-types/executor.js +0 -439
- package/architecture/executors/validate-return-types/executor.js.map +0 -1
- package/architecture/executors/validate-return-types/executor.ts +0 -524
- package/architecture/executors/validate-return-types/schema.json +0 -24
- package/architecture/executors/visualize/executor.d.ts +0 -17
- package/architecture/executors/visualize/executor.js +0 -49
- package/architecture/executors/visualize/executor.js.map +0 -1
- package/architecture/executors/visualize/executor.ts +0 -63
- package/architecture/executors/visualize/schema.json +0 -14
- package/architecture/index.d.ts +0 -19
- package/architecture/index.js +0 -23
- package/architecture/index.js.map +0 -1
- package/architecture/index.ts +0 -20
- package/architecture/lib/graph-comparator.d.ts +0 -39
- package/architecture/lib/graph-comparator.js +0 -100
- package/architecture/lib/graph-comparator.js.map +0 -1
- package/architecture/lib/graph-comparator.ts +0 -141
- package/architecture/lib/graph-generator.d.ts +0 -19
- package/architecture/lib/graph-generator.js +0 -84
- package/architecture/lib/graph-generator.js.map +0 -1
- package/architecture/lib/graph-generator.ts +0 -97
- package/architecture/lib/graph-loader.d.ts +0 -31
- package/architecture/lib/graph-loader.js +0 -98
- package/architecture/lib/graph-loader.js.map +0 -1
- package/architecture/lib/graph-loader.ts +0 -116
- package/architecture/lib/graph-sorter.d.ts +0 -37
- package/architecture/lib/graph-sorter.js +0 -110
- package/architecture/lib/graph-sorter.js.map +0 -1
- package/architecture/lib/graph-sorter.ts +0 -137
- package/architecture/lib/graph-visualizer.d.ts +0 -29
- package/architecture/lib/graph-visualizer.js +0 -217
- package/architecture/lib/graph-visualizer.js.map +0 -1
- package/architecture/lib/graph-visualizer.ts +0 -231
- package/architecture/lib/package-validator.d.ts +0 -38
- package/architecture/lib/package-validator.js +0 -126
- package/architecture/lib/package-validator.js.map +0 -1
- package/architecture/lib/package-validator.ts +0 -170
- package/eslint-plugin/__tests__/catch-error-pattern.test.ts +0 -374
- package/eslint-plugin/__tests__/max-file-lines.test.ts +0 -207
- package/eslint-plugin/__tests__/max-method-lines.test.ts +0 -258
- package/eslint-plugin/__tests__/no-unmanaged-exceptions.test.ts +0 -359
- package/eslint-plugin/index.d.ts +0 -23
- package/eslint-plugin/index.js +0 -30
- package/eslint-plugin/index.js.map +0 -1
- package/eslint-plugin/index.ts +0 -29
- package/eslint-plugin/rules/catch-error-pattern.d.ts +0 -11
- package/eslint-plugin/rules/catch-error-pattern.js +0 -143
- package/eslint-plugin/rules/catch-error-pattern.js.map +0 -1
- package/eslint-plugin/rules/catch-error-pattern.ts +0 -246
- package/eslint-plugin/rules/enforce-architecture.d.ts +0 -15
- package/eslint-plugin/rules/enforce-architecture.js +0 -476
- package/eslint-plugin/rules/enforce-architecture.js.map +0 -1
- package/eslint-plugin/rules/enforce-architecture.ts +0 -543
- package/eslint-plugin/rules/max-file-lines.d.ts +0 -12
- package/eslint-plugin/rules/max-file-lines.js +0 -257
- package/eslint-plugin/rules/max-file-lines.js.map +0 -1
- package/eslint-plugin/rules/max-file-lines.ts +0 -272
- package/eslint-plugin/rules/max-method-lines.d.ts +0 -12
- package/eslint-plugin/rules/max-method-lines.js +0 -240
- package/eslint-plugin/rules/max-method-lines.js.map +0 -1
- package/eslint-plugin/rules/max-method-lines.ts +0 -287
- package/eslint-plugin/rules/no-unmanaged-exceptions.d.ts +0 -22
- package/eslint-plugin/rules/no-unmanaged-exceptions.js +0 -160
- package/eslint-plugin/rules/no-unmanaged-exceptions.js.map +0 -1
- package/eslint-plugin/rules/no-unmanaged-exceptions.ts +0 -179
- package/executors/help/executor.js.map +0 -1
- package/executors/help/executor.ts +0 -61
- package/executors/validate-eslint-sync/executor.js.map +0 -1
- package/executors/validate-eslint-sync/executor.ts +0 -87
- package/executors/validate-versions-locked/executor.js.map +0 -1
- package/executors/validate-versions-locked/executor.ts +0 -368
- package/plugin/README.md +0 -243
- package/plugin/index.d.ts +0 -4
- package/plugin/index.js +0 -8
- package/plugin/index.js.map +0 -1
- package/plugin/index.ts +0 -4
- /package/{executors → src/executors}/help/executor.js +0 -0
- /package/{executors → src/executors}/help/schema.json +0 -0
- /package/{executors → src/executors}/validate-eslint-sync/executor.d.ts +0 -0
- /package/{executors → src/executors}/validate-eslint-sync/executor.js +0 -0
- /package/{executors → src/executors}/validate-eslint-sync/schema.json +0 -0
- /package/{executors → src/executors}/validate-versions-locked/executor.d.ts +0 -0
- /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!');
|