Skip to content

Commit ba00774

Browse files
committed
wip
1 parent c7f2d3a commit ba00774

File tree

3 files changed

+167
-50
lines changed

3 files changed

+167
-50
lines changed

packages/plugin-typescript/src/lib/internal/known-ts-error-codes.ts

+116-30
Original file line numberDiff line numberDiff line change
@@ -4,39 +4,125 @@ import type {AuditSlug} from '../types.js';
44
/**
55
* [src/compiler/types.ts](https://github.com/microsoft/TypeScript/blob/56a08250f3516b3f5bc120d6c7ab4450a9a69352/src/compiler/types.ts) -> compilerOptions 7482
66
* [src/compiler/utilities.ts](https://github.com/microsoft/TypeScript/blob/56a08250f3516b3f5bc120d6c7ab4450a9a69352/src/compiler/types.ts) 9125
7-
*
8-
* strictNullChecks: {
9-
* dependencies: ["strict"],
10-
* computeValue: compilerOptions => {
11-
* return getStrictOptionValue(compilerOptions, "strictNullChecks");
12-
* },
13-
* },
14-
* microsoft/TypeScript/src/compiler/utilities.ts
15-
* src/compiler/utilities.ts
16-
*
17-
* export function getStrictOptionValue(compilerOptions: CompilerOptions, flag: StrictOptionName): boolean {
18-
* return compilerOptions[flag] === undefined ? !!compilerOptions.strict : !!compilerOptions[flag];
19-
* }
20-
*
21-
* Compiler options that are activated by strict: true
22-
*
23-
* strictFunctionTypes?: boolean; // Always combine with strict property
24-
* strictBindCallApply?: boolean; // Always combine with strict property
25-
* strictNullChecks?: boolean; // Always combine with strict property
26-
* strictPropertyInitialization?: boolean; // Always combine with strict property
27-
* strictBuiltinIteratorReturn?: boolean; // Always combine with strict property
28-
* alwaysStrict?: boolean; // Always combine with strict property
29-
* noImplicitAny?: boolean; // Always combine with strict property
30-
* noImplicitThis?: boolean; // Always combine with strict property
31-
*
327
*/
33-
export const NEW_SUPPORTED_TS_ERROR_CODES = {
34-
'strict-types': [
35-
2322, // Type 'X' is not assignable to type 'Y'
36-
]
8+
9+
// Strict checks group
10+
const noImplicitAnyCodes = [7005, 7006, 7008, 7009, 7010, 7011, 7015, 7016, 7017, 7018, 7019, 7031, 7032, 7033];
11+
const noImplicitThisCodes = [2683, 2674];
12+
const alwaysStrictCodes = [1100, 1101, 1102, 1212, 1213, 1214, 1215, 1250, 1251, 1252];
13+
const strictBuiltinIteratorReturn = [1065]; // sussy
14+
const strictPropertyInitializationCodes = [2564, 2565, 1263, 1264];
15+
const strictNullChecksCodes = [2531, 2532, 2533, 2722, 2721, 18047, 18048, 18049];
16+
const strictBindCallApplyCodes = [2677, 2345, 2769];
17+
const strictFunctionTypesCodes = [2344, 2322, 2345, 2411];
18+
19+
// Extras checks group
20+
// Previous groups remain the same...
21+
22+
// Build and Emit Options
23+
const noEmitCodes = [6059];
24+
const noEmitHelpersCodes = [2343];
25+
const noEmitOnErrorCodes = [2318, 2354];
26+
const preserveConstEnumsCodes = [2748];
27+
const removeCommentsCodes = [2728];
28+
const stripInternalCodes = [2680];
29+
const emitBOMCodes = [2427];
30+
const importHelpersCodes = [2343, 2344];
31+
const downlevelIterationCodes = [2569];
32+
const emitDeclarationOnlyCodes = [5069];
33+
34+
// Code Quality
35+
const allowUnreachableCodeCodes = [7027];
36+
const allowUnusedLabelsCodes = [7028];
37+
const noImplicitReturnsInAsyncFunctionsCodes = [7030, 1064];
38+
const noUnusedLabelsCodes = [7028];
39+
const allowUnusedParametersCodes = [6134];
40+
const noFallthroughCasesInSwitchCodes = [7029];
41+
const noImplicitReturnsInGeneratorsCodes = [7030];
42+
const noPropertyAccessFromComputedKeyCodes = [4111];
43+
44+
// Type Checking Behavior
45+
const noErrorTruncationCodes = [2322, 2345]; // This affects error message display rather than triggering specific errors
46+
const exactOptionalPropertyTypesCodes = [2775];
47+
const noFallthroughCasesInSwitchCodes = [7029];
48+
const noUncheckedIndexedAccessCodes = [7061];
49+
const noImplicitOverrideCodes = [4114, 4113];
50+
const noPropertyAccessFromIndexSignatureCodes = [4111];
51+
52+
// Module Resolution
53+
const moduleResolutionNodeCodes = [2307];
54+
const moduleResolutionBundlerCodes = [1479];
55+
const customConditionsCodes = [1378];
56+
const resolvePackageJsonExportsCodes = [1343];
57+
const resolvePackageJsonImportsCodes = [1344];
58+
59+
// Project References
60+
const compositeCodes = [6372];
61+
const disableReferencedProjectLoadCodes = [6371];
62+
const disableSolutionSearchingCodes = [6370];
63+
const disableSourceOfProjectReferenceRedirectCodes = [6374];
64+
65+
// Watch Options
66+
const assumeChangesOnlyAffectDirectDependenciesCodes = [6373];
67+
const preserveWatchOutputCodes = [6379]; // This affects watch mode behavior rather than emitting errors
68+
const watchDirectoryCodes = [6378];
69+
const watchFileCodes = [6377];
70+
71+
// Interop Constraints
72+
const allowSyntheticDefaultImportsCodes = [1192, 1259];
73+
const esModuleInteropCodes = [1202, 1203, 1204, 1259];
74+
const forceConsistentCasingInFileNamesCodes = [1149, 1261];
75+
const isolatedModulesCodes = [18055, 18056, 18057];
76+
const preserveSymlinksCodes = [1421];
77+
78+
// Language and Environment
79+
const experimentalDecorators = [1240, 1241, 1242, 1243, 1244, 1270, 1271, 1272];
80+
const emitDecoratorMetadata = [1240, 1241, 1272];
81+
const jsx = [1341, 18007, 18034, 18035, 18053];
82+
const jsxFactoryCodes = [17004, 17001];
83+
const jsxFragmentFactoryCodes = [17002, 17003];
84+
const jsxImportSourceCodes = [17004];
85+
const libCodes = [2318, 2432];
86+
const moduleDetectionCodes = [1280];
87+
const noLibCodes = [2318, 2354];
88+
const reactNamespaceCodes = [2503, 2504];
89+
const targetCodes = [2322, 2339, 2459];
90+
const useDefineForClassFieldsCodes = [2729, 2730];
91+
92+
const verbatimModuleSyntaxCodes = [1286, 1287, 1288, 1484, 1485];
93+
94+
export const STRICT_CHECKS = {
95+
'no-implicit-any-codes': noImplicitAnyCodes,
96+
'no-implicit-this-codes': noImplicitThisCodes,
97+
'always-strict-codes': alwaysStrictCodes,
98+
'strict-builtin-iterator-return': strictBuiltinIteratorReturn,
99+
'strict-property-initialization-codes': strictPropertyInitializationCodes,
100+
'strict-null-checks-codes': strictNullChecksCodes,
101+
'strict-bind-call-apply-codes': strictBindCallApplyCodes,
102+
'strict-function-types-codes': strictFunctionTypesCodes,
37103
}
38-
export const SUPPORTED_TS_ERROR_CODES = {
39104

105+
/*
106+
* # Audits
107+
*
108+
* - strict-checks - group
109+
* - no-implicit-any-codes - audit
110+
* - 1240 - issue
111+
* - 1241 - issue
112+
* - 1272 - issue
113+
* - no-implicit-this-codes - audit
114+
* - always-strict-codes - audit
115+
* - strict-builtin-iterator-return - audit
116+
* - strict-property-initialization-codes - audit
117+
**/
118+
// Build Reverse Lookup Map
119+
export const AUDIT_LOOKUP = new Map<number, string>();
120+
121+
for (const [slug, codes] of Object.entries(STRICT_CHECKS)) {
122+
codes.forEach((code) => AUDIT_LOOKUP.set(code, slug));
123+
}
124+
125+
export const SUPPORTED_TS_ERROR_CODES = {
40126
2322: 'strict-type-checks-2322', // Type 'X' is not assignable to type 'Y'
41127
2345: 'strict-function-types-2345', // Argument of type 'X' is not assignable to parameter of type 'Y'
42128
2366: 'strict-missing-return-2366', // Function lacks ending return statement and return type does not include 'undefined'

packages/plugin-typescript/src/lib/runner/utils.ts

+9-6
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,18 @@ import {
44
flattenDiagnosticMessageText,
55
} from 'typescript';
66
import type { Issue } from '@code-pushup/models';
7-
import { SUPPORTED_TS_ERROR_CODES } from '../internal/known-ts-error-codes.js';
7+
import {
8+
AUDIT_LOOKUP
9+
} from '../internal/known-ts-error-codes.js';
810
import type { AuditSlug } from '../types.js';
911

10-
export function transformTSErrorCodeToAuditSlug(tscode: number): AuditSlug {
11-
const knownCode =
12-
SUPPORTED_TS_ERROR_CODES[tscode as keyof typeof SUPPORTED_TS_ERROR_CODES];
13-
return knownCode !== undefined ? knownCode : codeToAuditCodeSlug(tscode);
12+
export function transformTSErrorCodeToAuditSlug(code: number): AuditSlug {
13+
const knownCode = AUDIT_LOOKUP.get(code);
14+
if (knownCode === undefined) {
15+
console.info(`Code ${code} not supported.`);
16+
}
17+
return knownCode;
1418
}
15-
1619
export function codeToAuditCodeSlug(tscode: number) {
1720
return `ts-code-${tscode.toString()}` as AuditSlug;
1821
}

tsconfig.base.json

+42-14
Original file line numberDiff line numberDiff line change
@@ -12,32 +12,60 @@
1212
"importHelpers": false,
1313
"target": "es2022",
1414
"module": "esnext",
15-
"lib": ["es2023", "dom"],
15+
"lib": [
16+
"es2023",
17+
"dom"
18+
],
1619
"skipLibCheck": true,
1720
"skipDefaultLibCheck": true,
1821
"baseUrl": ".",
1922
"resolveJsonModule": true,
2023
"allowSyntheticDefaultImports": true,
2124
"verbatimModuleSyntax": true,
2225
"paths": {
23-
"@code-pushup/ci": ["packages/ci/src/index.ts"],
24-
"@code-pushup/cli": ["packages/cli/src/index.ts"],
25-
"@code-pushup/core": ["packages/core/src/index.ts"],
26-
"@code-pushup/coverage-plugin": ["packages/plugin-coverage/src/index.ts"],
27-
"@code-pushup/eslint-plugin": ["packages/plugin-eslint/src/index.ts"],
26+
"@code-pushup/ci": [
27+
"packages/ci/src/index.ts"
28+
],
29+
"@code-pushup/cli": [
30+
"packages/cli/src/index.ts"
31+
],
32+
"@code-pushup/core": [
33+
"packages/core/src/index.ts"
34+
],
35+
"@code-pushup/coverage-plugin": [
36+
"packages/plugin-coverage/src/index.ts"
37+
],
38+
"@code-pushup/eslint-plugin": [
39+
"packages/plugin-eslint/src/index.ts"
40+
],
2841
"@code-pushup/js-packages-plugin": [
2942
"packages/plugin-js-packages/src/index.ts"
3043
],
3144
"@code-pushup/lighthouse-plugin": [
3245
"packages/plugin-lighthouse/src/index.ts"
3346
],
34-
"@code-pushup/models": ["packages/models/src/index.ts"],
35-
"@code-pushup/nx-plugin": ["packages/nx-plugin/src/index.ts"],
36-
"@code-pushup/test-nx-utils": ["testing/test-nx-utils/src/index.ts"],
37-
"@code-pushup/test-setup": ["testing/test-setup/src/index.ts"],
38-
"@code-pushup/test-utils": ["testing/test-utils/src/index.ts"],
39-
"@code-pushup/utils": ["packages/utils/src/index.ts"]
47+
"@code-pushup/models": [
48+
"packages/models/src/index.ts"
49+
],
50+
"@code-pushup/nx-plugin": [
51+
"packages/nx-plugin/src/index.ts"
52+
],
53+
"@code-pushup/test-nx-utils": [
54+
"testing/test-nx-utils/src/index.ts"
55+
],
56+
"@code-pushup/test-setup": [
57+
"testing/test-setup/src/index.ts"
58+
],
59+
"@code-pushup/test-utils": [
60+
"testing/test-utils/src/index.ts"
61+
],
62+
"@code-pushup/utils": [
63+
"packages/utils/src/index.ts"
64+
]
4065
}
4166
},
42-
"exclude": ["node_modules", "tmp"]
43-
}
67+
"exclude": [
68+
"node_modules",
69+
"tmp"
70+
]
71+
}

0 commit comments

Comments
 (0)