@code-pushup/typescript-plugin 0.66.0

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/README.md ADDED
@@ -0,0 +1,164 @@
1
+ # @code-pushup/typescript-plugin
2
+
3
+ [![npm](https://img.shields.io/npm/v/%40code-pushup%2Ftypescript-plugin.svg)](https://www.npmjs.com/package/@code-pushup/typescript-plugin)
4
+ [![downloads](https://img.shields.io/npm/dm/%40code-pushup%2Ftypescript-plugin)](https://npmtrends.com/@code-pushup/typescript-plugin)
5
+ [![dependencies](https://img.shields.io/librariesio/release/npm/%40code-pushup/typescript-plugin)](https://www.npmjs.com/package/@code-pushup/typescript-plugin?activeTab=dependencies)
6
+
7
+ 🕵️ **Code PushUp plugin for measuring TypeScript quality with compiler diagnostics.** 🔥
8
+
9
+ This plugin allows you to **incrementally adopt strict compilation flags in TypeScript projects**.
10
+ It analyzes your codebase using the TypeScript compiler to detect potential issues and configuration problems.
11
+
12
+ TypeScript compiler diagnostics are mapped to Code PushUp audits in the following way:
13
+
14
+ - `value`: The number of issues found for a specific TypeScript configuration option (e.g. 3)
15
+ - `displayValue`: The number of issues found (e.g. "3 issues")
16
+ - `score`: Binary scoring - 1 if no issues are found, 0 if any issues exist
17
+ - Issues are mapped to audit details, containing:
18
+ - Source file location
19
+ - Error message from TypeScript compiler
20
+ - Code reference where the issue was found
21
+
22
+ ## Getting started
23
+
24
+ 1. If you haven't already, install [@code-pushup/cli](../cli/README.md) and create a configuration file.
25
+
26
+ 2. Install as a dev dependency with your package manager:
27
+
28
+ ```sh
29
+ npm install --save-dev @code-pushup/typescript-plugin
30
+ ```
31
+
32
+ ```sh
33
+ yarn add --dev @code-pushup/typescript-plugin
34
+ ```
35
+
36
+ ```sh
37
+ pnpm add --save-dev @code-pushup/typescript-plugin
38
+ ```
39
+
40
+ 3. Add this plugin to the `plugins` array in your Code PushUp CLI config file (e.g. `code-pushup.config.ts`).
41
+
42
+ By default, a root `tsconfig.json` is used to compile your codebase. Based on those compiler options, the plugin will generate audits.
43
+
44
+ ```ts
45
+ import typescriptPlugin from '@code-pushup/typescript-plugin';
46
+
47
+ export default {
48
+ // ...
49
+ plugins: [
50
+ // ...
51
+ await typescriptPlugin(),
52
+ ],
53
+ };
54
+ ```
55
+
56
+ 4. Run the CLI with `npx code-pushup collect` and view or upload the report (refer to [CLI docs](../cli/README.md)).
57
+
58
+ ## About TypeScript checks
59
+
60
+ The TypeScript plugin analyzes your codebase using the TypeScript compiler to identify potential issues and enforce best practices.
61
+ It helps ensure type safety and maintainability of your TypeScript code.
62
+
63
+ The plugin provides multiple audits grouped into different sets:
64
+
65
+ - _Semantic Errors_: `semantic-errors` - Errors that occur during type checking and type inference
66
+ - _Syntax Errors_: `syntax-errors` - Errors that occur during parsing and lexing of TypeScript source code
67
+ - _Configuration Errors_: `configuration-errors` - Errors that occur when parsing TypeScript configuration files
68
+ - _Declaration and Language Service Errors_: `declaration-and-language-service-errors` - Errors that occur during TypeScript language service operations
69
+ - _Internal Errors_: `internal-errors` - Errors that occur during TypeScript internal operations
70
+ - _No Implicit Any Errors_: `no-implicit-any-errors` - Errors related to `noImplicitAny` compiler option
71
+ - _Unknown Codes_: `unknown-codes` - Errors that do not match any known TypeScript error code
72
+
73
+ Each audit:
74
+
75
+ - Checks for specific TypeScript compiler errors and warnings
76
+ - Provides a score based on the number of issues found
77
+ - Includes detailed error messages and locations
78
+
79
+ Each set is also available as group in the plugin. See more under [Audits and Groups](./docs/audits-and-groups.md).
80
+
81
+ ## Plugin architecture
82
+
83
+ ### Plugin configuration specification
84
+
85
+ The plugin accepts the following parameters:
86
+
87
+ | Option | Type | Default | Description |
88
+ | ---------- | -------- | --------------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
89
+ | tsconfig | string | `tsconfig.json` | A string that defines the path to your `tsconfig.json` file |
90
+ | onlyAudits | string[] | undefined | An array of audit slugs to specify which documentation types you want to measure. Only the specified audits will be included in the results |
91
+
92
+ #### `tsconfig`
93
+
94
+ Optional parameter. The `tsconfig` option accepts a string that defines the path to your config file and defaults to `tsconfig.json`.
95
+
96
+ ```js
97
+ await typescriptPlugin({
98
+ tsconfig: './tsconfig.json',
99
+ });
100
+ ```
101
+
102
+ #### `onlyAudits`
103
+
104
+ The `onlyAudits` option allows you to specify which documentation types you want to measure. Only the specified audits will be included in the results. All audits are included by default. Example:
105
+
106
+ ```js
107
+ await typescriptPlugin({
108
+ onlyAudits: ['no-implicit-any'],
109
+ });
110
+ ```
111
+
112
+ ### Optionally set up categories
113
+
114
+ Reference audits (or groups) which you wish to include in custom categories (use `npx code-pushup print-config` to list audits and groups).
115
+
116
+ Assign weights based on what influence each TypeScript checks should have on the overall category score (assign weight 0 to only include as extra info, without influencing category score).
117
+
118
+ ```ts
119
+ // ...
120
+ categories: [
121
+ {
122
+ slug: 'typescript',
123
+ title: 'TypeScript',
124
+ refs: [
125
+ {
126
+ type: 'audit',
127
+ plugin: 'typescript',
128
+ slug: 'semantic-errors',
129
+ weight: 2,
130
+ },
131
+ {
132
+ type: 'audit',
133
+ plugin: 'typescript',
134
+ slug: 'syntax-errors',
135
+ weight: 1,
136
+ },
137
+ // ...
138
+ ],
139
+ },
140
+ // ...
141
+ ];
142
+ ```
143
+
144
+ Also groups can be used:
145
+
146
+ ```ts
147
+ // ...
148
+ categories: [
149
+ {
150
+ slug: 'typescript',
151
+ title: 'TypeScript',
152
+ refs: [
153
+ {
154
+ slug: 'language-and-environment',
155
+ weight: 1,
156
+ type: 'group',
157
+ plugin: 'typescript',
158
+ },
159
+ // ...
160
+ ],
161
+ },
162
+ // ...
163
+ ];
164
+ ```
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "@code-pushup/typescript-plugin",
3
+ "version": "0.66.0",
4
+ "license": "MIT",
5
+ "description": "Code PushUp plugin for incrementally adopting strict compilation flags in TypeScript projects",
6
+ "homepage": "https://github.com/code-pushup/cli/tree/main/packages/plugin-typescript#readme",
7
+ "bugs": {
8
+ "url": "https://github.com/code-pushup/cli/issues?q=is%3Aissue%20state%3Aopen%20type%3ABug%20label%3A\"🧩%20typescript-plugin\""
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/code-pushup/cli.git",
13
+ "directory": "packages/plugin-typescript"
14
+ },
15
+ "keywords": [
16
+ "CLI",
17
+ "Code PushUp",
18
+ "plugin",
19
+ "typescript"
20
+ ],
21
+ "publishConfig": {
22
+ "access": "public"
23
+ },
24
+ "type": "module",
25
+ "dependencies": {
26
+ "@code-pushup/models": "0.66.0",
27
+ "@code-pushup/utils": "0.66.0",
28
+ "zod": "^3.23.8"
29
+ },
30
+ "peerDependencies": {
31
+ "typescript": ">=4.0.0"
32
+ },
33
+ "scripts": {},
34
+ "module": "./src/index.js",
35
+ "main": "./src/index.js",
36
+ "types": "./src/index.d.ts"
37
+ }
package/src/index.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ export { TYPESCRIPT_PLUGIN_SLUG } from './lib/constants.js';
2
+ export { typescriptPlugin } from './lib/typescript-plugin.js';
3
+ export { getCategories, getCategoryRefsFromGroups } from './lib/utils.js';
4
+ export { type TypescriptPluginConfig, type TypescriptPluginOptions, typescriptPluginConfigSchema, } from './lib/schema.js';
package/src/index.js ADDED
@@ -0,0 +1,5 @@
1
+ export { TYPESCRIPT_PLUGIN_SLUG } from './lib/constants.js';
2
+ export { typescriptPlugin } from './lib/typescript-plugin.js';
3
+ export { getCategories, getCategoryRefsFromGroups } from './lib/utils.js';
4
+ export { typescriptPluginConfigSchema, } from './lib/schema.js';
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/plugin-typescript/src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,EAAE,aAAa,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;AAC1E,OAAO,EAGL,4BAA4B,GAC7B,MAAM,iBAAiB,CAAC"}
@@ -0,0 +1,8 @@
1
+ import type { Audit, Group } from '@code-pushup/models';
2
+ import type { AuditSlug } from './types.js';
3
+ export declare const TYPESCRIPT_PLUGIN_SLUG = "typescript";
4
+ export declare const DEFAULT_TS_CONFIG = "tsconfig.json";
5
+ export declare const AUDITS: (Audit & {
6
+ slug: AuditSlug;
7
+ })[];
8
+ export declare const GROUPS: Group[];
@@ -0,0 +1,56 @@
1
+ import { toSentenceCase } from '@code-pushup/utils';
2
+ import { TS_CODE_RANGE_NAMES } from './runner/ts-error-codes.js';
3
+ export const TYPESCRIPT_PLUGIN_SLUG = 'typescript';
4
+ export const DEFAULT_TS_CONFIG = 'tsconfig.json';
5
+ const AUDIT_DESCRIPTIONS = {
6
+ 'semantic-errors': 'Errors that occur during type checking and type inference',
7
+ 'syntax-errors': 'Errors that occur during parsing and lexing of TypeScript source code',
8
+ 'configuration-errors': 'Errors that occur when parsing TypeScript configuration files',
9
+ 'declaration-and-language-service-errors': 'Errors that occur during TypeScript language service operations',
10
+ 'internal-errors': 'Errors that occur during TypeScript internal operations',
11
+ 'no-implicit-any-errors': 'Errors related to no implicit any compiler option',
12
+ 'unknown-codes': 'Errors that do not match any known TypeScript error code',
13
+ };
14
+ export const AUDITS = Object.values(TS_CODE_RANGE_NAMES).map(slug => ({
15
+ slug,
16
+ title: toSentenceCase(slug),
17
+ description: AUDIT_DESCRIPTIONS[slug],
18
+ }));
19
+ export const GROUPS = [
20
+ {
21
+ slug: 'problems',
22
+ title: 'Problems',
23
+ description: 'Syntax, semantic, and internal compiler errors are critical for identifying and preventing bugs.',
24
+ refs: [
25
+ 'syntax-errors',
26
+ 'semantic-errors',
27
+ 'no-implicit-any-errors',
28
+ ].map(slug => ({
29
+ slug,
30
+ weight: 1,
31
+ })),
32
+ },
33
+ {
34
+ slug: 'ts-configuration',
35
+ title: 'Configuration',
36
+ description: 'TypeScript configuration and options errors ensure correct project setup, reducing risks from misconfiguration.',
37
+ refs: ['configuration-errors'].map(slug => ({
38
+ slug,
39
+ weight: 1,
40
+ })),
41
+ },
42
+ {
43
+ slug: 'miscellaneous',
44
+ title: 'Miscellaneous',
45
+ description: 'Errors that do not bring any specific value to the developer, but are still useful to know.',
46
+ refs: [
47
+ 'unknown-codes',
48
+ 'internal-errors',
49
+ 'declaration-and-language-service-errors',
50
+ ].map(slug => ({
51
+ slug,
52
+ weight: 1,
53
+ })),
54
+ },
55
+ ];
56
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../../packages/plugin-typescript/src/lib/constants.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAGjE,MAAM,CAAC,MAAM,sBAAsB,GAAG,YAAY,CAAC;AACnD,MAAM,CAAC,MAAM,iBAAiB,GAAG,eAAe,CAAC;AAEjD,MAAM,kBAAkB,GAA8B;IACpD,iBAAiB,EACf,2DAA2D;IAC7D,eAAe,EACb,uEAAuE;IACzE,sBAAsB,EACpB,+DAA+D;IACjE,yCAAyC,EACvC,iEAAiE;IACnE,iBAAiB,EAAE,yDAAyD;IAC5E,wBAAwB,EAAE,mDAAmD;IAC7E,eAAe,EAAE,0DAA0D;CAC5E,CAAC;AACF,MAAM,CAAC,MAAM,MAAM,GAAoC,MAAM,CAAC,MAAM,CAClE,mBAAmB,CACpB,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACb,IAAI;IACJ,KAAK,EAAE,cAAc,CAAC,IAAI,CAAC;IAC3B,WAAW,EAAE,kBAAkB,CAAC,IAAI,CAAC;CACtC,CAAC,CAAC,CAAC;AAEJ,MAAM,CAAC,MAAM,MAAM,GAAY;IAC7B;QACE,IAAI,EAAE,UAAU;QAChB,KAAK,EAAE,UAAU;QACjB,WAAW,EACT,kGAAkG;QACpG,IAAI,EACF;YACE,eAAe;YACf,iBAAiB;YACjB,wBAAwB;SAE3B,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YACb,IAAI;YACJ,MAAM,EAAE,CAAC;SACV,CAAC,CAAC;KACJ;IACD;QACE,IAAI,EAAE,kBAAkB;QACxB,KAAK,EAAE,eAAe;QACtB,WAAW,EACT,iHAAiH;QACnH,IAAI,EAAG,CAAC,sBAAsB,CAAwB,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YAClE,IAAI;YACJ,MAAM,EAAE,CAAC;SACV,CAAC,CAAC;KACJ;IACD;QACE,IAAI,EAAE,eAAe;QACrB,KAAK,EAAE,eAAe;QACtB,WAAW,EACT,6FAA6F;QAC/F,IAAI,EACF;YACE,eAAe;YACf,iBAAiB;YACjB,yCAAyC;SAE5C,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YACb,IAAI;YACJ,MAAM,EAAE,CAAC;SACV,CAAC,CAAC;KACJ;CACF,CAAC"}
@@ -0,0 +1,9 @@
1
+ import type { RunnerFunction } from '@code-pushup/models';
2
+ import type { AuditSlug } from '../types.js';
3
+ import { type DiagnosticsOptions } from './ts-runner.js';
4
+ export type RunnerOptions = DiagnosticsOptions & {
5
+ expectedAudits: {
6
+ slug: AuditSlug;
7
+ }[];
8
+ };
9
+ export declare function createRunnerFunction(options: RunnerOptions): RunnerFunction;
@@ -0,0 +1,34 @@
1
+ import { pluralize } from '@code-pushup/utils';
2
+ import { getTypeScriptDiagnostics, } from './ts-runner.js';
3
+ import { getIssueFromDiagnostic, tsCodeToAuditSlug } from './utils.js';
4
+ export function createRunnerFunction(options) {
5
+ const { tsconfig, expectedAudits } = options;
6
+ return async () => {
7
+ const diagnostics = await getTypeScriptDiagnostics({ tsconfig });
8
+ const result = diagnostics.reduce((acc, diag) => {
9
+ const slug = tsCodeToAuditSlug(diag.code);
10
+ const existingIssues = acc[slug]?.details?.issues ?? [];
11
+ return {
12
+ ...acc,
13
+ [slug]: {
14
+ slug,
15
+ details: {
16
+ issues: [...existingIssues, getIssueFromDiagnostic(diag)],
17
+ },
18
+ },
19
+ };
20
+ }, {});
21
+ return expectedAudits.map(({ slug }) => {
22
+ const { details } = result[slug] ?? {};
23
+ const issues = details?.issues ?? [];
24
+ return {
25
+ slug,
26
+ score: issues.length === 0 ? 1 : 0,
27
+ value: issues.length,
28
+ displayValue: `${issues.length} ${pluralize('issue', issues.length)}`,
29
+ ...(issues.length > 0 ? { details } : {}),
30
+ };
31
+ });
32
+ };
33
+ }
34
+ //# sourceMappingURL=runner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runner.js","sourceRoot":"","sources":["../../../../../../packages/plugin-typescript/src/lib/runner/runner.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAE/C,OAAO,EAEL,wBAAwB,GACzB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAMvE,MAAM,UAAU,oBAAoB,CAAC,OAAsB;IACzD,MAAM,EAAE,QAAQ,EAAE,cAAc,EAAE,GAAG,OAAO,CAAC;IAC7C,OAAO,KAAK,IAA2B,EAAE;QACvC,MAAM,WAAW,GAAG,MAAM,wBAAwB,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC;QACjE,MAAM,MAAM,GAAG,WAAW,CAAC,MAAM,CAE/B,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE;YACd,MAAM,IAAI,GAAG,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAC1C,MAAM,cAAc,GAAY,GAAG,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,MAAM,IAAI,EAAE,CAAC;YACjE,OAAO;gBACL,GAAG,GAAG;gBACN,CAAC,IAAI,CAAC,EAAE;oBACN,IAAI;oBACJ,OAAO,EAAE;wBACP,MAAM,EAAE,CAAC,GAAG,cAAc,EAAE,sBAAsB,CAAC,IAAI,CAAC,CAAC;qBAC1D;iBACF;aACF,CAAC;QACJ,CAAC,EAAE,EAAE,CAAC,CAAC;QAEP,OAAO,cAAc,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE;YACrC,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;YAEvC,MAAM,MAAM,GAAG,OAAO,EAAE,MAAM,IAAI,EAAE,CAAC;YACrC,OAAO;gBACL,IAAI;gBACJ,KAAK,EAAE,MAAM,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;gBAClC,KAAK,EAAE,MAAM,CAAC,MAAM;gBACpB,YAAY,EAAE,GAAG,MAAM,CAAC,MAAM,IAAI,SAAS,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE;gBACrE,GAAG,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;aACpB,CAAC;QAC1B,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * # Diagnostic Code Ranges and Their Grouping
3
+ *
4
+ * TypeScript diagnostic codes are grouped into ranges based on their source and purpose. Here's how they are categorized:
5
+ *
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)
18
+ *
19
+ */
20
+ export declare const TS_CODE_RANGE_NAMES: {
21
+ readonly '1': "syntax-errors";
22
+ readonly '2': "semantic-errors";
23
+ readonly '4': "declaration-and-language-service-errors";
24
+ readonly '5': "internal-errors";
25
+ readonly '6': "configuration-errors";
26
+ readonly '7': "no-implicit-any-errors";
27
+ readonly '9': "unknown-codes";
28
+ };
@@ -0,0 +1,30 @@
1
+ /**
2
+ * # Diagnostic Code Ranges and Their Grouping
3
+ *
4
+ * TypeScript diagnostic codes are grouped into ranges based on their source and purpose. Here's how they are categorized:
5
+ *
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)
18
+ *
19
+ */
20
+ export const TS_CODE_RANGE_NAMES = {
21
+ '1': 'syntax-errors',
22
+ '2': 'semantic-errors',
23
+ // '3': 'suggestions',
24
+ '4': 'declaration-and-language-service-errors',
25
+ '5': 'internal-errors',
26
+ '6': 'configuration-errors',
27
+ '7': 'no-implicit-any-errors',
28
+ '9': 'unknown-codes',
29
+ };
30
+ //# sourceMappingURL=ts-error-codes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ts-error-codes.js","sourceRoot":"","sources":["../../../../../../packages/plugin-typescript/src/lib/runner/ts-error-codes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,GAAG,EAAE,eAAe;IACpB,GAAG,EAAE,iBAAiB;IACtB,sBAAsB;IACtB,GAAG,EAAE,yCAAyC;IAC9C,GAAG,EAAE,iBAAiB;IACtB,GAAG,EAAE,sBAAsB;IAC3B,GAAG,EAAE,wBAAwB;IAC7B,GAAG,EAAE,eAAe;CACZ,CAAC"}
@@ -0,0 +1,5 @@
1
+ import { type Diagnostic } from 'typescript';
2
+ export type DiagnosticsOptions = {
3
+ tsconfig: string;
4
+ };
5
+ export declare function getTypeScriptDiagnostics({ tsconfig, }: DiagnosticsOptions): Promise<readonly Diagnostic[]>;
@@ -0,0 +1,14 @@
1
+ import { createProgram, getPreEmitDiagnostics, } from 'typescript';
2
+ import { stringifyError } from '@code-pushup/utils';
3
+ import { loadTargetConfig } from './utils.js';
4
+ export async function getTypeScriptDiagnostics({ tsconfig, }) {
5
+ const { fileNames, options } = await loadTargetConfig(tsconfig);
6
+ try {
7
+ const program = createProgram(fileNames, options);
8
+ return getPreEmitDiagnostics(program);
9
+ }
10
+ catch (error) {
11
+ throw new Error(`Can't create TS program in getDiagnostics. \n ${stringifyError(error)}`);
12
+ }
13
+ }
14
+ //# sourceMappingURL=ts-runner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ts-runner.js","sourceRoot":"","sources":["../../../../../../packages/plugin-typescript/src/lib/runner/ts-runner.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,aAAa,EACb,qBAAqB,GACtB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAM9C,MAAM,CAAC,KAAK,UAAU,wBAAwB,CAAC,EAC7C,QAAQ,GACW;IACnB,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,GAAG,MAAM,gBAAgB,CAAC,QAAQ,CAAC,CAAC;IAChE,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,aAAa,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;QAClD,OAAO,qBAAqB,CAAC,OAAO,CAAC,CAAC;IACxC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CACb,iDAAiD,cAAc,CAAC,KAAK,CAAC,EAAE,CACzE,CAAC;IACJ,CAAC;AACH,CAAC"}
@@ -0,0 +1,5 @@
1
+ import { TS_CODE_RANGE_NAMES } from './ts-error-codes.js';
2
+ type TsCodeRanges = typeof TS_CODE_RANGE_NAMES;
3
+ export type CodeRangeName = TsCodeRanges[keyof TsCodeRanges];
4
+ export type SemVerString = `${number}.${number}.${number}`;
5
+ export {};
@@ -0,0 +1,2 @@
1
+ import { TS_CODE_RANGE_NAMES } from './ts-error-codes.js';
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../../packages/plugin-typescript/src/lib/runner/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC"}
@@ -0,0 +1,46 @@
1
+ import { type Diagnostic, DiagnosticCategory } from 'typescript';
2
+ import type { Issue } from '@code-pushup/models';
3
+ import type { CodeRangeName } from './types.js';
4
+ /**
5
+ * Transform the TypeScript error code to the audit slug.
6
+ * @param code - The TypeScript error code.
7
+ * @returns The audit slug.
8
+ * @throws Error if the code is not supported.
9
+ */
10
+ export declare function tsCodeToAuditSlug(code: number): CodeRangeName;
11
+ /**
12
+ * Get the severity of the issue based on the TypeScript diagnostic category.
13
+ * - ts.DiagnosticCategory.Warning (1)
14
+ * - ts.DiagnosticCategory.Error (2)
15
+ * - ts.DiagnosticCategory.Suggestion (3)
16
+ * - ts.DiagnosticCategory.Message (4)
17
+ * @param category - The TypeScript diagnostic category.
18
+ * @returns The severity of the issue.
19
+ */
20
+ export declare function getSeverity(category: DiagnosticCategory): Issue['severity'];
21
+ /**
22
+ * Format issue message from the TypeScript diagnostic.
23
+ * @param diag - The TypeScript diagnostic.
24
+ * @returns The issue message.
25
+ */
26
+ export declare function getMessage(diag: Diagnostic): string;
27
+ /**
28
+ * Get the issue from the TypeScript diagnostic.
29
+ * @param diag - The TypeScript diagnostic.
30
+ * @returns The issue.
31
+ * @throws Error if the diagnostic is global (e.g., invalid compiler option).
32
+ */
33
+ export declare function getIssueFromDiagnostic(diag: Diagnostic): {
34
+ message: string;
35
+ severity: "info" | "warning" | "error";
36
+ source?: {
37
+ file: string;
38
+ position?: {
39
+ startLine: number;
40
+ startColumn?: number | undefined;
41
+ endLine?: number | undefined;
42
+ endColumn?: number | undefined;
43
+ } | undefined;
44
+ } | undefined;
45
+ };
46
+ export declare function loadTargetConfig(tsConfigPath: string): Promise<import("typescript").ParsedCommandLine>;
@@ -0,0 +1,89 @@
1
+ // eslint-disable-next-line unicorn/import-style
2
+ import { dirname } from 'node:path';
3
+ import { DiagnosticCategory, flattenDiagnosticMessageText, parseConfigFileTextToJson, parseJsonConfigFileContent, sys, } from 'typescript';
4
+ import { readTextFile, truncateIssueMessage } from '@code-pushup/utils';
5
+ import { TS_CODE_RANGE_NAMES } from './ts-error-codes.js';
6
+ /**
7
+ * Transform the TypeScript error code to the audit slug.
8
+ * @param code - The TypeScript error code.
9
+ * @returns The audit slug.
10
+ * @throws Error if the code is not supported.
11
+ */
12
+ export function tsCodeToAuditSlug(code) {
13
+ const rangeNumber = code
14
+ .toString()
15
+ .slice(0, 1);
16
+ return TS_CODE_RANGE_NAMES[rangeNumber] ?? 'unknown-code';
17
+ }
18
+ /**
19
+ * Get the severity of the issue based on the TypeScript diagnostic category.
20
+ * - ts.DiagnosticCategory.Warning (1)
21
+ * - ts.DiagnosticCategory.Error (2)
22
+ * - ts.DiagnosticCategory.Suggestion (3)
23
+ * - ts.DiagnosticCategory.Message (4)
24
+ * @param category - The TypeScript diagnostic category.
25
+ * @returns The severity of the issue.
26
+ */
27
+ export function getSeverity(category) {
28
+ switch (category) {
29
+ case DiagnosticCategory.Error:
30
+ return 'error';
31
+ case DiagnosticCategory.Warning:
32
+ return 'warning';
33
+ default:
34
+ return 'info';
35
+ }
36
+ }
37
+ /**
38
+ * Format issue message from the TypeScript diagnostic.
39
+ * @param diag - The TypeScript diagnostic.
40
+ * @returns The issue message.
41
+ */
42
+ export function getMessage(diag) {
43
+ const flattened = flattenDiagnosticMessageText(diag.messageText, '\n');
44
+ const text = flattened
45
+ .replace(process.cwd(), '.')
46
+ .replace(process.cwd().replace(/\\/g, '/'), '.');
47
+ return truncateIssueMessage(`TS${diag.code}: ${text}`);
48
+ }
49
+ /**
50
+ * Get the issue from the TypeScript diagnostic.
51
+ * @param diag - The TypeScript diagnostic.
52
+ * @returns The issue.
53
+ * @throws Error if the diagnostic is global (e.g., invalid compiler option).
54
+ */
55
+ export function getIssueFromDiagnostic(diag) {
56
+ const issue = {
57
+ severity: getSeverity(diag.category),
58
+ message: getMessage(diag),
59
+ };
60
+ // If undefined, the error might be global (e.g., invalid compiler option).
61
+ if (diag.file === undefined) {
62
+ return issue;
63
+ }
64
+ const startLine = diag.start === undefined
65
+ ? undefined
66
+ : diag.file.getLineAndCharacterOfPosition(diag.start).line + 1;
67
+ return {
68
+ ...issue,
69
+ source: {
70
+ file: diag.file.fileName,
71
+ ...(startLine
72
+ ? {
73
+ position: {
74
+ startLine,
75
+ },
76
+ }
77
+ : {}),
78
+ },
79
+ };
80
+ }
81
+ export async function loadTargetConfig(tsConfigPath) {
82
+ const { config } = parseConfigFileTextToJson(tsConfigPath, await readTextFile(tsConfigPath));
83
+ const parsedConfig = parseJsonConfigFileContent(config, sys, dirname(tsConfigPath));
84
+ if (parsedConfig.fileNames.length === 0) {
85
+ throw new Error('No files matched by the TypeScript configuration. Check your "include", "exclude" or "files" settings.');
86
+ }
87
+ return parsedConfig;
88
+ }
89
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../../../packages/plugin-typescript/src/lib/runner/utils.ts"],"names":[],"mappings":"AAAA,gDAAgD;AAChD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAEL,kBAAkB,EAClB,4BAA4B,EAC5B,yBAAyB,EACzB,0BAA0B,EAC1B,GAAG,GACJ,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AACxE,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAG1D;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,IAAY;IAC5C,MAAM,WAAW,GAAG,IAAI;SACrB,QAAQ,EAAE;SACV,KAAK,CAAC,CAAC,EAAE,CAAC,CAAqC,CAAC;IACnD,OAAO,mBAAmB,CAAC,WAAW,CAAC,IAAI,cAAc,CAAC;AAC5D,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,WAAW,CAAC,QAA4B;IACtD,QAAQ,QAAQ,EAAE,CAAC;QACjB,KAAK,kBAAkB,CAAC,KAAK;YAC3B,OAAO,OAAO,CAAC;QACjB,KAAK,kBAAkB,CAAC,OAAO;YAC7B,OAAO,SAAS,CAAC;QACnB;YACE,OAAO,MAAM,CAAC;IAClB,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,UAAU,CAAC,IAAgB;IACzC,MAAM,SAAS,GAAG,4BAA4B,CAAC,IAAI,CAAC,WAAW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,MAAM,EACN,GAAG,EACH,OAAO,CAAC,YAAY,CAAC,CACtB,CAAC;IAEF,IAAI,YAAY,CAAC,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACxC,MAAM,IAAI,KAAK,CACb,wGAAwG,CACzG,CAAC;IACJ,CAAC;IAED,OAAO,YAAY,CAAC;AACtB,CAAC"}
@@ -0,0 +1,13 @@
1
+ import { z } from 'zod';
2
+ export declare const typescriptPluginConfigSchema: z.ZodObject<{
3
+ tsconfig: z.ZodDefault<z.ZodString>;
4
+ onlyAudits: z.ZodOptional<z.ZodArray<z.ZodEnum<[import("./runner/types.js").CodeRangeName, ...import("./runner/types.js").CodeRangeName[]]>, "many">>;
5
+ }, "strip", z.ZodTypeAny, {
6
+ tsconfig: string;
7
+ onlyAudits?: import("./runner/types.js").CodeRangeName[] | undefined;
8
+ }, {
9
+ tsconfig?: string | undefined;
10
+ onlyAudits?: import("./runner/types.js").CodeRangeName[] | undefined;
11
+ }>;
12
+ export type TypescriptPluginOptions = z.input<typeof typescriptPluginConfigSchema>;
13
+ export type TypescriptPluginConfig = z.infer<typeof typescriptPluginConfigSchema>;
@@ -0,0 +1,16 @@
1
+ import { z } from 'zod';
2
+ import { AUDITS, DEFAULT_TS_CONFIG } from './constants.js';
3
+ const auditSlugs = AUDITS.map(({ slug }) => slug);
4
+ export const typescriptPluginConfigSchema = z.object({
5
+ tsconfig: z
6
+ .string({
7
+ description: 'Path to a tsconfig file (default is tsconfig.json)',
8
+ })
9
+ .default(DEFAULT_TS_CONFIG),
10
+ onlyAudits: z
11
+ .array(z.enum(auditSlugs), {
12
+ description: 'Filters TypeScript compiler errors by diagnostic codes',
13
+ })
14
+ .optional(),
15
+ });
16
+ //# sourceMappingURL=schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../../../packages/plugin-typescript/src/lib/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAG3D,MAAM,UAAU,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,IAAI,CAG/C,CAAC;AACF,MAAM,CAAC,MAAM,4BAA4B,GAAG,CAAC,CAAC,MAAM,CAAC;IACnD,QAAQ,EAAE,CAAC;SACR,MAAM,CAAC;QACN,WAAW,EAAE,oDAAoD;KAClE,CAAC;SACD,OAAO,CAAC,iBAAiB,CAAC;IAC7B,UAAU,EAAE,CAAC;SACV,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE;QACzB,WAAW,EAAE,wDAAwD;KACtE,CAAC;SACD,QAAQ,EAAE;CACd,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ import type { CodeRangeName } from './runner/types.js';
2
+ export type AuditSlug = CodeRangeName;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../packages/plugin-typescript/src/lib/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ import type { PluginConfig } from '@code-pushup/models';
2
+ import { type TypescriptPluginOptions } from './schema.js';
3
+ export declare function typescriptPlugin(options?: TypescriptPluginOptions): Promise<PluginConfig>;
@@ -0,0 +1,37 @@
1
+ import { createRequire } from 'node:module';
2
+ import { stringifyError } from '@code-pushup/utils';
3
+ import { DEFAULT_TS_CONFIG, TYPESCRIPT_PLUGIN_SLUG } from './constants.js';
4
+ import { createRunnerFunction } from './runner/runner.js';
5
+ import { typescriptPluginConfigSchema, } from './schema.js';
6
+ import { getAudits, getGroups, logSkippedAudits } from './utils.js';
7
+ const packageJson = createRequire(import.meta.url)('../../package.json');
8
+ export async function typescriptPlugin(options) {
9
+ const { tsconfig = DEFAULT_TS_CONFIG, onlyAudits } = parseOptions(options ?? {});
10
+ const filteredAudits = getAudits({ onlyAudits });
11
+ const filteredGroups = getGroups({ onlyAudits });
12
+ logSkippedAudits(filteredAudits);
13
+ return {
14
+ slug: TYPESCRIPT_PLUGIN_SLUG,
15
+ packageName: packageJson.name,
16
+ version: packageJson.version,
17
+ title: 'Typescript',
18
+ description: 'Official Code PushUp Typescript plugin.',
19
+ docsUrl: 'https://www.npmjs.com/package/@code-pushup/typescript-plugin/',
20
+ icon: 'typescript',
21
+ audits: filteredAudits,
22
+ groups: filteredGroups,
23
+ runner: createRunnerFunction({
24
+ tsconfig,
25
+ expectedAudits: filteredAudits,
26
+ }),
27
+ };
28
+ }
29
+ function parseOptions(tsPluginOptions) {
30
+ try {
31
+ return typescriptPluginConfigSchema.parse(tsPluginOptions);
32
+ }
33
+ catch (error) {
34
+ throw new Error(`Error parsing TypeScript Plugin options: ${stringifyError(error)}`);
35
+ }
36
+ }
37
+ //# sourceMappingURL=typescript-plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typescript-plugin.js","sourceRoot":"","sources":["../../../../../packages/plugin-typescript/src/lib/typescript-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAC3E,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAGL,4BAA4B,GAC7B,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEpE,MAAM,WAAW,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAChD,oBAAoB,CACkB,CAAC;AAEzC,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,OAAiC;IAEjC,MAAM,EAAE,QAAQ,GAAG,iBAAiB,EAAE,UAAU,EAAE,GAAG,YAAY,CAC/D,OAAO,IAAI,EAAE,CACd,CAAC;IAEF,MAAM,cAAc,GAAG,SAAS,CAAC,EAAE,UAAU,EAAE,CAAC,CAAC;IACjD,MAAM,cAAc,GAAG,SAAS,CAAC,EAAE,UAAU,EAAE,CAAC,CAAC;IAEjD,gBAAgB,CAAC,cAAc,CAAC,CAAC;IAEjC,OAAO;QACL,IAAI,EAAE,sBAAsB;QAC5B,WAAW,EAAE,WAAW,CAAC,IAAI;QAC7B,OAAO,EAAE,WAAW,CAAC,OAAO;QAC5B,KAAK,EAAE,YAAY;QACnB,WAAW,EAAE,yCAAyC;QACtD,OAAO,EAAE,+DAA+D;QACxE,IAAI,EAAE,YAAY;QAClB,MAAM,EAAE,cAAc;QACtB,MAAM,EAAE,cAAc;QACtB,MAAM,EAAE,oBAAoB,CAAC;YAC3B,QAAQ;YACR,cAAc,EAAE,cAAc;SAC/B,CAAC;KACH,CAAC;AACJ,CAAC;AAED,SAAS,YAAY,CACnB,eAAwC;IAExC,IAAI,CAAC;QACH,OAAO,4BAA4B,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC;IAC7D,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CACb,4CAA4C,cAAc,CAAC,KAAK,CAAC,EAAE,CACpE,CAAC;IACJ,CAAC;AACH,CAAC"}
@@ -0,0 +1,70 @@
1
+ import type { CompilerOptions } from 'typescript';
2
+ import type { Audit, CategoryConfig, CategoryRef } from '@code-pushup/models';
3
+ import type { TypescriptPluginConfig, TypescriptPluginOptions } from './schema.js';
4
+ /**
5
+ * It filters the audits by the slugs
6
+ *
7
+ * @param slugs
8
+ */
9
+ export declare function filterAuditsBySlug(slugs?: string[]): ({ slug }: {
10
+ slug: string;
11
+ }) => boolean;
12
+ /**
13
+ * From a list of audits, it will filter out the ones that might have been disabled from the compiler options
14
+ * plus from the parameter onlyAudits
15
+ * @param compilerOptions Compiler options
16
+ * @param onlyAudits OnlyAudits
17
+ * @returns Filtered Audits
18
+ */
19
+ export declare function filterAuditsByCompilerOptions(compilerOptions: CompilerOptions, onlyAudits?: string[]): ({ slug }: {
20
+ slug: string;
21
+ }) => boolean;
22
+ export declare function getGroups(options?: TypescriptPluginOptions): {
23
+ refs: {
24
+ slug: string;
25
+ weight: number;
26
+ }[];
27
+ slug: string;
28
+ title: string;
29
+ description?: string | undefined;
30
+ docsUrl?: string | undefined;
31
+ isSkipped?: boolean | undefined;
32
+ }[];
33
+ export declare function getAudits(options?: Pick<TypescriptPluginConfig, 'onlyAudits'>): ({
34
+ slug: string;
35
+ title: string;
36
+ description?: string | undefined;
37
+ docsUrl?: string | undefined;
38
+ isSkipped?: boolean | undefined;
39
+ } & {
40
+ slug: import("./types.js").AuditSlug;
41
+ })[];
42
+ /**
43
+ * Retrieve the category references from the groups (already processed from the audits).
44
+ * Used in the code-pushup preset
45
+ * @param opt TSPluginOptions
46
+ * @returns The array of category references
47
+ */
48
+ export declare function getCategoryRefsFromGroups(opt?: TypescriptPluginOptions): CategoryRef[];
49
+ /**
50
+ * Retrieve the category references from the audits.
51
+ * @param opt TSPluginOptions
52
+ * @returns The array of category references
53
+ */
54
+ export declare function getCategoryRefsFromAudits(opt?: TypescriptPluginOptions): CategoryRef[];
55
+ export declare const CATEGORY_MAP: Record<string, CategoryConfig>;
56
+ export declare function getCategories(): {
57
+ slug: string;
58
+ refs: {
59
+ slug: string;
60
+ weight: number;
61
+ type: "audit" | "group";
62
+ plugin: string;
63
+ }[];
64
+ title: string;
65
+ description?: string | undefined;
66
+ docsUrl?: string | undefined;
67
+ isSkipped?: boolean | undefined;
68
+ isBinary?: boolean | undefined;
69
+ }[];
70
+ export declare function logSkippedAudits(audits: Audit[]): void;
@@ -0,0 +1,122 @@
1
+ import { kebabCaseToCamelCase, ui } from '@code-pushup/utils';
2
+ import { AUDITS, GROUPS, TYPESCRIPT_PLUGIN_SLUG } from './constants.js';
3
+ /**
4
+ * It filters the audits by the slugs
5
+ *
6
+ * @param slugs
7
+ */
8
+ export function filterAuditsBySlug(slugs) {
9
+ return ({ slug }) => {
10
+ if (slugs && slugs.length > 0) {
11
+ return slugs.includes(slug);
12
+ }
13
+ return true;
14
+ };
15
+ }
16
+ /**
17
+ * It transforms a slug code to a compiler option format
18
+ * By default, kebabCaseToCamelCase.
19
+ * It will handle also cases like emit-bom that it should be emit-BOM
20
+ * @param slug Slug to be transformed
21
+ * @returns The slug as compilerOption key
22
+ */
23
+ function auditSlugToCompilerOption(slug) {
24
+ // eslint-disable-next-line sonarjs/no-small-switch
25
+ switch (slug) {
26
+ case 'emit-bom':
27
+ return 'emitBOM';
28
+ default:
29
+ return kebabCaseToCamelCase(slug);
30
+ }
31
+ }
32
+ /**
33
+ * From a list of audits, it will filter out the ones that might have been disabled from the compiler options
34
+ * plus from the parameter onlyAudits
35
+ * @param compilerOptions Compiler options
36
+ * @param onlyAudits OnlyAudits
37
+ * @returns Filtered Audits
38
+ */
39
+ export function filterAuditsByCompilerOptions(compilerOptions, onlyAudits) {
40
+ return ({ slug }) => {
41
+ const option = compilerOptions[auditSlugToCompilerOption(slug)];
42
+ return (option !== false &&
43
+ option !== undefined &&
44
+ filterAuditsBySlug(onlyAudits)({ slug }));
45
+ };
46
+ }
47
+ export function getGroups(options) {
48
+ return GROUPS.map(group => ({
49
+ ...group,
50
+ refs: group.refs.filter(filterAuditsBySlug(options?.onlyAudits)),
51
+ })).filter(group => group.refs.length > 0);
52
+ }
53
+ export function getAudits(options) {
54
+ return AUDITS.filter(filterAuditsBySlug(options?.onlyAudits));
55
+ }
56
+ /**
57
+ * Retrieve the category references from the groups (already processed from the audits).
58
+ * Used in the code-pushup preset
59
+ * @param opt TSPluginOptions
60
+ * @returns The array of category references
61
+ */
62
+ export function getCategoryRefsFromGroups(opt) {
63
+ return getGroups(opt).map(({ slug }) => ({
64
+ plugin: TYPESCRIPT_PLUGIN_SLUG,
65
+ slug,
66
+ weight: 1,
67
+ type: 'group',
68
+ }));
69
+ }
70
+ /**
71
+ * Retrieve the category references from the audits.
72
+ * @param opt TSPluginOptions
73
+ * @returns The array of category references
74
+ */
75
+ export function getCategoryRefsFromAudits(opt) {
76
+ return AUDITS.filter(filterAuditsBySlug(opt?.onlyAudits)).map(({ slug }) => ({
77
+ plugin: TYPESCRIPT_PLUGIN_SLUG,
78
+ slug,
79
+ weight: 1,
80
+ type: 'audit',
81
+ }));
82
+ }
83
+ export const CATEGORY_MAP = {
84
+ typescript: {
85
+ slug: 'type-safety',
86
+ title: 'Type Safety',
87
+ description: 'TypeScript diagnostics and type-checking errors',
88
+ refs: getCategoryRefsFromGroups(),
89
+ },
90
+ 'bug-prevention': {
91
+ slug: 'bug-prevention',
92
+ title: 'Bug prevention',
93
+ description: 'Type checks that find **potential bugs** in your code.',
94
+ refs: getCategoryRefsFromGroups({
95
+ onlyAudits: [
96
+ 'syntax-errors',
97
+ 'semantic-errors',
98
+ 'internal-errors',
99
+ 'configuration-errors',
100
+ 'no-implicit-any-errors',
101
+ ],
102
+ }),
103
+ },
104
+ miscellaneous: {
105
+ slug: 'miscellaneous',
106
+ title: 'Miscellaneous',
107
+ description: 'Errors that do not bring any specific value to the developer, but are still useful to know.',
108
+ refs: getCategoryRefsFromGroups({
109
+ onlyAudits: ['unknown-codes', 'declaration-and-language-service-errors'],
110
+ }),
111
+ },
112
+ };
113
+ export function getCategories() {
114
+ return Object.values(CATEGORY_MAP);
115
+ }
116
+ export function logSkippedAudits(audits) {
117
+ const skippedAudits = AUDITS.filter(audit => !audits.some(filtered => filtered.slug === audit.slug)).map(audit => kebabCaseToCamelCase(audit.slug));
118
+ if (skippedAudits.length > 0) {
119
+ ui().logger.info(`Skipped audits: [${skippedAudits.join(', ')}]`);
120
+ }
121
+ }
122
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../../packages/plugin-typescript/src/lib/utils.ts"],"names":[],"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