|
1 | | -/* eslint-disable @typescript-eslint/no-magic-numbers, unicorn/numeric-separators-style */ |
2 | | - |
3 | | -/** The TypeScript compiler emits diagnostic objects maintaniing a `category` an error code and a `textMessage` we can use to map to audits. |
4 | | - * The following shape has different levels: group -> audit -> diagnostic code |
5 | | - * |
6 | | - * Diagnostic Messages Source: |
7 | | - * https://github.com/microsoft/TypeScript/blob/56a08250f3516b3f5bc120d6c7ab4450a9a69352/src/compiler/diagnosticMessages.json |
8 | | - */ |
9 | | -export const TS_ERROR_CODES = { |
10 | | - languageAndEnvironment: { |
11 | | - experimentalDecorators: [1240, 1241, 1242, 1243, 1244, 1270, 1271, 1272], |
12 | | - emitDecoratorMetadata: [1240, 1241, 1272], |
13 | | - jsx: [1341, 18007, 18034, 18035, 18053], |
14 | | - jsxFactory: [17004, 17001], |
15 | | - jsxFragmentFactory: [17002, 17003], |
16 | | - jsxImportSource: [17004], |
17 | | - lib: [2318, 2432], |
18 | | - moduleDetection: [1280], |
19 | | - noLib: [2318, 2354], |
20 | | - reactNamespace: [2503, 2504], |
21 | | - target: [2322, 2339, 2459], |
22 | | - useDefineForClassFields: [2729, 2730], |
23 | | - } as const, |
24 | | - interopConstraints: { |
25 | | - allowSyntheticDefaultImports: [1192, 1259], |
26 | | - esModuleInterop: [1202, 1203, 1204, 1259], |
27 | | - forceConsistentCasingInFileNames: [1149, 1261], |
28 | | - isolatedModules: [18055, 18056, 18057], |
29 | | - preserveSymlinks: [1421], |
30 | | - } as const, |
31 | | - /* |
32 | | - watchOptions: { |
33 | | - assumeChangesOnlyAffectDirectDependencies: [6373], |
34 | | - preserveWatchOutput: [6379], // This affects watch mode behavior rather than emitting errors |
35 | | - watchDirectory: [6378], |
36 | | - watchFile: [6377], |
37 | | - } as const, |
38 | | - projectReferences: { |
39 | | - composite: [6372], |
40 | | - disableReferencedProjectLoad: [6371], |
41 | | - disableSolutionSearching: [6370], |
42 | | - disableSourceOfProjectReferenceRedirect: [6374], |
43 | | - } as const,*/ |
44 | | - moduleResolution: { |
45 | | - moduleResolution: [2307, 1479, 2792], |
46 | | - customConditions: [1378], |
47 | | - resolvePackageJsonExports: [1343], |
48 | | - resolvePackageJsonImports: [1344], |
49 | | - verbatimModuleSyntax: [1286, 1287, 1288, 1484, 1485], |
50 | | - } as const, |
51 | | - typeCheckingBehavior: { |
52 | | - // noErrorTruncation: [2322, 2345], // This affects error message display rather than triggering specific errors |
53 | | - exactOptionalPropertyTypes: [2775], |
54 | | - noUncheckedIndexedAccess: [7061, 2536], |
55 | | - noImplicitOverride: [4114, 4113], |
56 | | - noPropertyAccessFromIndexSignature: [4111], |
57 | | - } as const, |
58 | | - controlFlowOptions: { |
59 | | - allowUnreachableCode: [7027], |
60 | | - noImplicitReturns: [7030, 1064], |
61 | | - noFallthroughCasesInSwitch: [7029], |
62 | | - } as const, |
63 | | - buildEmitOptions: { |
64 | | - noEmit: [6059], |
65 | | - noEmitHelpers: [2343], |
66 | | - noEmitOnError: [2318, 2354], |
67 | | - preserveConstEnums: [2748], |
68 | | - removeComments: [2728], |
69 | | - stripInternal: [2680], |
70 | | - emitBOM: [2427], |
71 | | - importHelpers: [2343, 2344], |
72 | | - downlevelIteration: [2569], |
73 | | - emitDeclarationOnly: [5069], |
74 | | - } as const, |
75 | | - strict: { |
76 | | - noImplicitAny: [ |
77 | | - 7005, 7006, 7008, 7009, 7010, 7011, 7015, 7016, 7017, 7018, 7019, 7031, |
78 | | - 7032, 7033, |
79 | | - ], |
80 | | - noImplicitThis: [2683, 2674], |
81 | | - alwaysStrict: [1100, 1101, 1102, 1212, 1213, 1214, 1215, 1250, 1251, 1252], |
82 | | - strictBuiltinIteratorReturn: [1065], |
83 | | - strictPropertyInitialization: [2564, 2565, 1263, 1264], |
84 | | - strictNullChecks: [2532, 2533, 2722, 2721, 18047, 18048, 18049], |
85 | | - strictBindCallApply: [2677, 2345, 2769], |
86 | | - strictFunctionTypes: [2349, 2344, 2322, 2345, 2411], |
87 | | - } as const, |
88 | | -} as const; |
89 | | - |
90 | 1 | /** |
91 | 2 | * # Diagnostic Code Ranges and Their Grouping |
92 | 3 | * |
93 | 4 | * TypeScript diagnostic codes are grouped into ranges based on their source and purpose. Here's how they are categorized: |
94 | 5 | * |
95 | | - * | Code Range | Type | Description | |
96 | | - * |------------|-----------------------------|-----------------------------------------------------------| |
97 | | - * | 1XXX | Syntax Errors | Structural issues detected during parsing. | |
98 | | - * | 2XXX | Semantic Errors | Type-checking and type-system violations. | |
99 | | - * | 3XXX | Suggestions | Optional improvements (e.g., unused variables). | |
100 | | - * | 4XXX | Language Service Diagnostics | Used by editors (e.g., VSCode) for IntelliSense. | |
101 | | - * | 5XXX | Internal Compiler Errors | Rare, unexpected failures in the compiler. | |
102 | | - * | 6XXX | Configuration/Options Errors| Issues with tsconfig.json or compiler options. | |
| 6 | + * | Code Range | Type | Description | |
| 7 | + * |------------|---------------------------------|--------------------------------------------------| |
| 8 | + * | 1XXX | Syntax Errors | Structural issues detected during parsing. | |
| 9 | + * | 2XXX | Semantic Errors | Type-checking and type-system violations. | |
| 10 | + * | 3XXX | Suggestions | Optional improvements (e.g., unused variables). | |
| 11 | + * | 4XXX | Declaration & Language Service | Used by editors (e.g., VSCode) for IntelliSense. | |
| 12 | + * | 5XXX | Internal Compiler Errors | Rare, unexpected failures in the compiler. | |
| 13 | + * | 6XXX | Configuration/Options Errors | Issues with `tsconfig.json` or compiler options. | |
| 14 | + * | 7XXX | noImplicitAny Errors | Issues with commandline compiler options. | |
| 15 | + * |
| 16 | + * The diagnostic messages are exposed over a undocumented and undiscoverable const names `Diagnostics`. |
| 17 | + * Additional information is derived from [TypeScript's own guidelines on diagnostic code ranges](https://github.com/microsoft/TypeScript/wiki/Coding-guidelines#diagnostic-message-codes) |
103 | 18 | * |
104 | | - * *Note:* 3XXX Diagnostics are not emitted by tsc. They are only available through the Language Service API. |
105 | | - * If you want to measure them use the eslint plugin `@typescript-eslint/eslint-plugin`. |
106 | 19 | */ |
107 | 20 | export const TS_CODE_RANGE_NAMES = { |
108 | 21 | '1': 'syntax-errors', |
109 | 22 | '2': 'semantic-errors', |
110 | 23 | // '3': 'suggestions', |
111 | | - '4': 'language-service-errors', |
| 24 | + '4': 'declaration-and-language-service-errors', |
112 | 25 | '5': 'internal-errors', |
113 | 26 | '6': 'configuration-errors', |
| 27 | + '7': 'no-implicit-any-errors', |
114 | 28 | '9': 'unknown-codes', |
115 | 29 | } as const; |
0 commit comments