Skip to content

Commit 80b1fbc

Browse files
committed
adjust ranges
1 parent 56531e9 commit 80b1fbc

File tree

3 files changed

+58
-144
lines changed

3 files changed

+58
-144
lines changed

code-pushup.preset.ts

Lines changed: 5 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
type TypescriptPluginOptions,
1818
typescriptPlugin,
1919
} from './packages/plugin-typescript/src/index.js';
20-
import { getCategoryRefsFromGroups } from './packages/plugin-typescript/src/lib/utils.js';
20+
import { CATEGORY_MAP } from './packages/plugin-typescript/src/lib/constants';
2121

2222
export const jsPackagesCategories: CategoryConfig[] = [
2323
{
@@ -136,46 +136,10 @@ export const eslintCoreConfigNx = async (
136136

137137
export const typescriptPluginConfigNx = async (
138138
options?: TypescriptPluginOptions,
139-
): Promise<CoreConfig> => {
140-
return {
141-
plugins: [await typescriptPlugin(options)],
142-
categories: [
143-
{
144-
slug: 'typescript',
145-
title: 'Typescript - All Groups',
146-
refs: await getCategoryRefsFromGroups(options),
147-
},
148-
{
149-
slug: 'bug-prevention',
150-
title: 'Bug prevention',
151-
refs: await getCategoryRefsFromGroups({
152-
onlyAudits: [
153-
'syntax-errors',
154-
'semantic-errors',
155-
'internal-errors',
156-
'configuration-errors',
157-
],
158-
}),
159-
},
160-
{
161-
slug: 'code-style',
162-
title: 'Code style',
163-
description:
164-
'TypeScript & Lint rules that promote **good practices** and consistency in your code.',
165-
refs: await getCategoryRefsFromGroups({ onlyAudits: ['suggestions'] }),
166-
},
167-
{
168-
slug: 'miscellaneous',
169-
title: 'Miscellaneous',
170-
description:
171-
'Errors that do not bring any specific value to the developer, but are still useful to know.',
172-
refs: await getCategoryRefsFromGroups({
173-
onlyAudits: ['unknown-codes', 'language-service-errors'],
174-
}),
175-
},
176-
],
177-
};
178-
};
139+
): Promise<CoreConfig> => ({
140+
plugins: [await typescriptPlugin(options)],
141+
categories: Object.values(CATEGORY_MAP),
142+
});
179143

180144
export const coverageCoreConfigNx = async (
181145
projectName?: string,

packages/plugin-typescript/src/lib/constants.ts

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import type { Audit, Group } from '@code-pushup/models';
1+
import type { Audit, CategoryConfig, Group } from '@code-pushup/models';
22
import { camelCaseToSentence, slugify } from '@code-pushup/utils';
33
import { TS_CODE_RANGE_NAMES } from './runner/ts-error-codes.js';
44
import type { AuditSlug } from './types.js';
5+
import { getCategoryRefsFromGroups } from './utils.js';
56

67
export const TYPESCRIPT_PLUGIN_SLUG = 'typescript';
78
export const DEFAULT_TS_CONFIG = 'tsconfig.json';
@@ -13,9 +14,10 @@ const AUDIT_DESCRIPTIONS: Record<AuditSlug, string> = {
1314
'Errors that occur during parsing and lexing of TypeScript source code',
1415
'configuration-errors':
1516
'Errors that occur when parsing TypeScript configuration files',
16-
'language-service-errors':
17+
'declaration-and-language-service-errors':
1718
'Errors that occur during TypeScript language service operations',
1819
'internal-errors': 'Errors that occur during TypeScript internal operations',
20+
'no-implicit-any-errors': 'Errors related to no implicit any compiler option',
1921
'unknown-codes': 'Errors that do not match any known TypeScript error code',
2022
};
2123
export const AUDITS: (Audit & { slug: AuditSlug })[] = Object.values(
@@ -45,6 +47,7 @@ export const GROUPS: Group[] = [
4547
'syntax-errors',
4648
'semantic-errors',
4749
'internal-errors',
50+
'no-implicit-any-errors',
4851
] satisfies AuditSlug[]
4952
).map(slug => ({
5053
slug,
@@ -67,10 +70,43 @@ export const GROUPS: Group[] = [
6770
description:
6871
'Errors that do not bring any specific value to the developer, but are still useful to know.',
6972
refs: (
70-
['unknown-codes', 'language-service-errors'] satisfies AuditSlug[]
73+
[
74+
'unknown-codes',
75+
'declaration-and-language-service-errors',
76+
] satisfies AuditSlug[]
7177
).map(slug => ({
7278
slug,
7379
weight: 1,
7480
})),
7581
},
7682
];
83+
84+
export const CATEGORY_MAP: Record<string, CategoryConfig> = {
85+
typescript: {
86+
slug: 'type-safety',
87+
title: 'Type Safety',
88+
refs: await getCategoryRefsFromGroups(),
89+
},
90+
'bug-prevention': {
91+
slug: 'bug-prevention',
92+
title: 'Bug prevention',
93+
refs: await getCategoryRefsFromGroups({
94+
onlyAudits: [
95+
'syntax-errors',
96+
'semantic-errors',
97+
'internal-errors',
98+
'configuration-errors',
99+
'no-implicit-any-errors',
100+
],
101+
}),
102+
},
103+
miscellaneous: {
104+
slug: 'miscellaneous',
105+
title: 'Miscellaneous',
106+
description:
107+
'Errors that do not bring any specific value to the developer, but are still useful to know.',
108+
refs: await getCategoryRefsFromGroups({
109+
onlyAudits: ['unknown-codes', 'declaration-and-language-service-errors'],
110+
}),
111+
},
112+
};
Lines changed: 14 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -1,115 +1,29 @@
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-
901
/**
912
* # Diagnostic Code Ranges and Their Grouping
923
*
934
* TypeScript diagnostic codes are grouped into ranges based on their source and purpose. Here's how they are categorized:
945
*
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)
10318
*
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`.
10619
*/
10720
export const TS_CODE_RANGE_NAMES = {
10821
'1': 'syntax-errors',
10922
'2': 'semantic-errors',
11023
// '3': 'suggestions',
111-
'4': 'language-service-errors',
24+
'4': 'declaration-and-language-service-errors',
11225
'5': 'internal-errors',
11326
'6': 'configuration-errors',
27+
'7': 'no-implicit-any-errors',
11428
'9': 'unknown-codes',
11529
} as const;

0 commit comments

Comments
 (0)