From ca149c13b0dbc6f4a279ae55bb74c243014f8b1e Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 10 Mar 2025 19:27:51 +0100 Subject: [PATCH 01/17] feat(plugin-typescript): adjust logic --- code-pushup.config.ts | 5 + code-pushup.preset.ts | 12 ++ packages/plugin-typescript/README.md | 167 ++++++++++++++++ .../docs/audits-and-groups.md | 186 ++++++++++++++++++ packages/plugin-typescript/src/index.ts | 7 + 5 files changed, 377 insertions(+) create mode 100644 packages/plugin-typescript/README.md create mode 100644 packages/plugin-typescript/docs/audits-and-groups.md diff --git a/code-pushup.config.ts b/code-pushup.config.ts index 9af68c6fb..c92bf4219 100644 --- a/code-pushup.config.ts +++ b/code-pushup.config.ts @@ -6,6 +6,7 @@ import { jsDocsCoreConfig, jsPackagesCoreConfig, lighthouseCoreConfig, + typescriptPluginConfigNx, } from './code-pushup.preset.js'; import type { CoreConfig } from './packages/models/src/index.js'; import { mergeConfigs } from './packages/utils/src/index.js'; @@ -39,6 +40,10 @@ export default mergeConfigs( await lighthouseCoreConfig( 'https://github.com/code-pushup/cli?tab=readme-ov-file#code-pushup-cli/', ), + await typescriptPluginConfigNx({ + tsconfig: + 'packages/plugin-typescript/mocks/fixtures/basic-setup/tsconfig.json', + }), await eslintCoreConfigNx(), jsDocsCoreConfig([ 'packages/**/src/**/*.ts', diff --git a/code-pushup.preset.ts b/code-pushup.preset.ts index 9b9c462f9..ea8b692ce 100644 --- a/code-pushup.preset.ts +++ b/code-pushup.preset.ts @@ -21,6 +21,11 @@ import { filterGroupsByOnlyAudits } from './packages/plugin-jsdocs/src/lib/utils import lighthousePlugin, { lighthouseGroupRef, } from './packages/plugin-lighthouse/src/index.js'; +import { + type TypescriptPluginOptions, + getCategories, + typescriptPlugin, +} from './packages/plugin-typescript/src/index.js'; export const jsPackagesCategories: CategoryConfig[] = [ { @@ -168,6 +173,13 @@ export const eslintCoreConfigNx = async ( }; }; +export const typescriptPluginConfigNx = async ( + options?: TypescriptPluginOptions, +): Promise => ({ + plugins: [await typescriptPlugin(options)], + categories: getCategories(), +}); + export const coverageCoreConfigNx = async ( projectName?: string, ): Promise => { diff --git a/packages/plugin-typescript/README.md b/packages/plugin-typescript/README.md new file mode 100644 index 000000000..72eae7353 --- /dev/null +++ b/packages/plugin-typescript/README.md @@ -0,0 +1,167 @@ +# @code-pushup/typescript-plugin + +[![npm](https://img.shields.io/npm/v/%40code-pushup%2Ftypescript-plugin.svg)](https://www.npmjs.com/package/@code-pushup/typescript-plugin) +[![downloads](https://img.shields.io/npm/dm/%40code-pushup%2Ftypescript-plugin)](https://npmtrends.com/@code-pushup/typescript-plugin) +[![dependencies](https://img.shields.io/librariesio/release/npm/%40code-pushup/typescript-plugin)](https://www.npmjs.com/package/@code-pushup/typescript-plugin?activeTab=dependencies) + +🕵️ **Code PushUp plugin for measuring TypeScript quality with compiler diagnostics.** 🔥 + +This plugin allows you to **incrementally adopting strict compilation flags in TypeScript projects**. +It analyzes your codebase using the TypeScript compiler to detect potential issues and configuration problems. + +TypeScript compiler diagnostics are mapped to Code PushUp audits in the following way: + +- `value`: The number of issues found for a specific TypeScript configuration option -> 3 +- `displayValue`: The number of issues found -> 3 issues +- `score`: Binary scoring - 1 if no issues are found, 0 if any issues exist +- Issues are mapped to audit details, containing: + - Source file location + - Error message from TypeScript compiler + - Code reference where the issue was found + +## Getting started + +1. If you haven't already, install [@code-pushup/cli](../cli/README.md) and create a configuration file. + +2. Install as a dev dependency with your package manager: + + ```sh + npm install --save-dev @code-pushup/typescript-plugin + ``` + + ```sh + yarn add --dev @code-pushup/typescript-plugin + ``` + + ```sh + pnpm add --save-dev @code-pushup/typescript-plugin + ``` + +3. Add this plugin to the `plugins` array in your Code PushUp CLI config file (e.g. `code-pushup.config.ts`). + +Define the ts config file used to compile your codebase. Based on those compiler options the plugin will generate audits. + +```ts +import typescriptPlugin from '@code-pushup/typescript-plugin'; + +export default { + // ... + plugins: [ + // ... + typescriptPlugin({ + tsConfigPath: './tsconfig.json', + onlyAudits: ['no-implicit-any'], + }), + ], +}; +``` + +4. Run the CLI with `npx code-pushup collect` and view or upload the report (refer to [CLI docs](../cli/README.md)). + +## About TypeScript checks + +The TypeScript plugin analyzes your codebase using the TypeScript compiler to identify potential issues and enforce best practices. +It helps ensure type safety and maintainability of your TypeScript code. + +The plugin provides multiple audits grouped into different sets: + +- _Semantic Errors_: `semantic-errors` - Errors that occur during type checking and type inference +- _Syntax Errors_: `syntax-errors` - Errors that occur during parsing and lexing of TypeScript source code +- _Configuration Errors_: `configuration-errors` - Errors that occur when parsing TypeScript configuration files +- _Declaration and Language Service Errors_: `declaration-and-language-service-errors` - Errors that occur during TypeScript language service operations +- _Internal Errors_: `internal-errors` - Errors that occur during TypeScript internal operations +- _No Implicit Any Errors_: `no-implicit-any-errors` - Errors related to no implicit any compiler option +- _Unknown Codes_: `unknown-codes` - Errors that do not match any known TypeScript error code + +Each audit: + +- Checks for specific TypeScript compiler errors and warnings +- Provides a score based on the number of issues found +- Includes detailed error messages and locations + +Each set is also available as group in the plugin. See more under [Audits and Groups](./docs/audits-and-groups.md). + +## Plugin architecture + +### Plugin configuration specification + +The plugin accepts the following parameters: + +| Option | Type | Default | Description | +| ------------ | -------- | --------------- | ------------------------------------------------------------------------------------------------------------------------------------------- | +| tsConfigPath | string | `tsconfig.json` | A string that defines the path to your `tsconfig.json` file | +| 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 | + +#### TsConfigPath + +Optional parameter. The `tsConfigPath` option accepts a string that defines the path to your config file and defaults to `tsconfig.json`. + +```js +typescriptPlugin({ + tsConfigPath: './tsconfig.json', +}); +``` + +#### OnlyAudits + +Optional parameter. The `onlyAudits` option allows you to specify which documentation types you want to measure. Only the specified audits will be included in the results. Example: + +```js +typescriptPlugin({ + onlyAudits: ['no-implicit-any'], +}); +``` + +### Optionally set up categories + +1. Reference audits (or groups) which you wish to include in custom categories (use `npx code-pushup print-config` to list audits and groups). + +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). + +```ts +// ... +categories: [ + { + slug: 'typescript', + title: 'TypeScript', + refs: [ + { + type: 'audit', + plugin: 'typescript', + slug: 'no-implicit-any', + weight: 2, + }, + { + type: 'audit', + plugin: 'typescript', + slug: 'no-explicit-any', + weight: 1, + }, + // ... + ], + }, + // ... +]; +``` + +Also groups can be used: + +```ts +// ... +categories: [ + { + slug: 'typescript', + title: 'TypeScript', + refs: [ + { + slug: 'language-and-environment', + weight: 1, + type: 'group', + plugin: 'typescript', + }, + // ... + ], + }, + // ... +]; +``` diff --git a/packages/plugin-typescript/docs/audits-and-groups.md b/packages/plugin-typescript/docs/audits-and-groups.md new file mode 100644 index 000000000..5cb528c22 --- /dev/null +++ b/packages/plugin-typescript/docs/audits-and-groups.md @@ -0,0 +1,186 @@ +# 📚 Audits and Groups + +The TypeScript plugin analyzes your codebase using the TypeScript compiler to identify potential issues and enforce best practices. + +--- + +## 🛡️ Audits Overview + +The plugin manages issues through structured audits and groups. Each audit targets a specific type of error, ensuring comprehensive analysis. + +| **Audit** | **Slug** | +| ------------------------------------------- | ----------------------------------------- | +| **Semantic Errors** | `semantic-errors` | +| **Syntax Errors** | `syntax-errors` | +| **Configuration Errors** | `configuration-errors` | +| **Declaration and Language Service Errors** | `declaration-and-language-service-errors` | +| **Internal Errors** | `internal-errors` | +| **No Implicit Any Errors** | `no-implicit-any-errors` | +| **Unknown Codes** | `unknown-codes` | + +--- + +### Semantic Errors - `semantic-errors` + +Errors that occur during type checking and type inference. + +- **Slug:** `semantic-errors` +- **Title:** Semantic Errors +- **Description:** Errors that occur during type checking and type inference. +- **Scoring:** The score is based on the number of issues found. +- **Value:** The value is the number of issues found. +- **Display Value:** The display value is the number of issues found. + +#### Issues + +| Severity | Message | Source file | Line(s) | +| :--------: | :----------------------------------------------------------------------------------- | :------------------------------------------------------------------------ | :-----: | +| 🚨 _error_ | TS2307: Cannot find module './non-existent' or its corresponding type declarations. | [`path/to/module-resolution.ts`](../path/to/module-resolution.ts) | 2 | +| 🚨 _error_ | TS2349: This expression is not callable.
Type 'Number' has no call signatures. | [`path/to/strict-function-types.ts`](../path/to/strict-function-types.ts) | 3 | +| 🚨 _error_ | TS2304: Cannot find name 'NonExistentType'. | [`path/to/cannot-find-module.ts`](../path/to/cannot-find-module.ts) | 1 | + +--- + +### Syntax Errors - `syntax-errors` + +Errors that occur during parsing and lexing of TypeScript source code. + +- **Slug:** `syntax-errors` +- **Title:** Syntax Errors +- **Description:** Errors that occur during parsing and lexing of TypeScript source code. +- **Scoring:** The score is based on the number of issues found. +- **Value:** The value is the number of issues found. +- **Display Value:** The display value is the number of issues found. + +#### Issues + +| Severity | Message | Source file | Line(s) | +| :--------: | :------------------------------------ | :------------------------------------------------------ | :-----: | +| 🚨 _error_ | TS1136: Property assignment expected. | [`path/to/syntax-error.ts`](../path/to/syntax-error.ts) | 1 | + +--- + +### Configuration Errors - `configuration-errors` + +Errors that occur when parsing TypeScript configuration files. + +- **Slug:** `configuration-errors` +- **Title:** Configuration Errors +- **Description:** Errors that occur when parsing TypeScript configuration files. +- **Scoring:** The score is based on the number of issues found. +- **Value:** The value is the number of issues found. +- **Display Value:** The display value is the number of issues found. + +#### Issues + +| Severity | Message | Source file | Line(s) | +| :--------: | :----------------------------------------- | :-------------------------------------------------- | :-----: | +| 🚨 _error_ | TS5023: Unknown compiler option 'invalid'. | [`path/to/tsconfig.json`](../path/to/tsconfig.json) | 1 | + +--- + +### Declaration and Language Service Errors - `declaration-and-language-service-errors` + +Errors that occur during TypeScript language service operations. + +- **Slug:** `declaration-and-language-service-errors` +- **Title:** Declaration and Language Service Errors +- **Description:** Errors that occur during TypeScript language service operations. +- **Scoring:** The score is based on the number of issues found. +- **Value:** The value is the number of issues found. +- **Display Value:** The display value is the number of issues found. + +#### Issues + +| Severity | Message | Source file | Line(s) | +| :--------: | :------------------------------------------------------------------------------------------------------------------------------ | :------------------------------------------------------------------ | :-----: | +| 🚨 _error_ | TS4112: This member cannot have an 'override' modifier because its containing class 'Standalone' does not extend another class. | [`path/to/incorrect-modifier.ts`](../path/to/incorrect-modifier.ts) | 2 | + +--- + +### Internal Errors - `internal-errors` + +Errors that occur during TypeScript internal operations. + +- **Slug:** `internal-errors` +- **Title:** Internal Errors +- **Description:** Errors that occur during TypeScript internal operations. +- **Scoring:** The score is based on the number of issues found. +- **Value:** The value is the number of issues found. +- **Display Value:** The display value is the number of issues found. + +#### Issues + +| Severity | Message | Source file | Line(s) | +| :--------: | :------------------------------- | :---------------------------------------------------------- | :-----: | +| 🚨 _error_ | TS9001: Internal compiler error. | [`path/to/internal-error.ts`](../path/to/internal-error.ts) | 4 | + +--- + +### No Implicit Any Errors - `no-implicit-any-errors` + +Errors related to no implicit any compiler option. + +- **Slug:** `no-implicit-any-errors` +- **Title:** No Implicit Any Errors +- **Description:** Errors related to no implicit any compiler option. +- **Scoring:** The score is based on the number of issues found. +- **Value:** The value is the number of issues found. +- **Display Value:** The display value is the number of issues found. + +#### Issues + +| Severity | Message | Source file | Line(s) | +| :--------: | :-------------------------------------------------- | :------------------------------------------------------ | :-----: | +| 🚨 _error_ | TS7006: Parameter 'x' implicitly has an 'any' type. | [`path/to/implicit-any.ts`](../path/to/implicit-any.ts) | 5 | + +--- + +### Unknown Codes - `unknown-codes` + +Errors that do not match any known TypeScript error code. + +- **Slug:** `unknown-codes` +- **Title:** Unknown Codes +- **Description:** Errors that do not match any known TypeScript error code. +- **Scoring:** The score is based on the number of issues found. +- **Value:** The value is the number of issues found. +- **Display Value:** The display value is the number of issues found. + +#### Issues + +| Severity | Message | Source file | Line(s) | +| :--------: | :-------------------------------------- | :-------------------------------------------------------- | :-----: | +| 🚨 _error_ | TS9999: Unknown error code encountered. | [`path/to/unknown-error.ts`](../path/to/unknown-error.ts) | 6 | + +--- + +## 📂 Groups Overview + +| **Group** | **Slug** | +| ----------------- | ------------------ | +| **Problems** | `problems` | +| **Configuration** | `ts-configuration` | +| **Miscellaneous** | `miscellaneous` | + +### Problems - `problems` + +- **Description:** Syntax, semantic, and internal compiler errors are critical for identifying and preventing bugs. +- **References:** + - Syntax Errors (`syntax-errors`) + - Semantic Errors (`semantic-errors`) + - No Implicit Any Errors (`no-implicit-any-errors`) + +### Configuration - `ts-configuration` + +- **Description:** Ensures correct TypeScript project setup, minimizing risks from misconfiguration. +- **References:** + - Configuration Errors (`configuration-errors`) + +### Miscellaneous - `miscellaneous` + +- **Description:** Informational errors that may not impact development directly but are helpful for deeper insights. +- **References:** + - Unknown Codes (`unknown-codes`) + - Internal Errors (`internal-errors`) + - Declaration and Language Service Errors (`declaration-and-language-service-errors`) diff --git a/packages/plugin-typescript/src/index.ts b/packages/plugin-typescript/src/index.ts index 26c2b67c0..de384e130 100644 --- a/packages/plugin-typescript/src/index.ts +++ b/packages/plugin-typescript/src/index.ts @@ -1 +1,8 @@ export { TYPESCRIPT_PLUGIN_SLUG } from './lib/constants.js'; +export { typescriptPlugin } from './lib/typescript-plugin.js'; +export { getCategories } from './lib/utils.js'; +export { + type TypescriptPluginConfig, + type TypescriptPluginOptions, + typescriptPluginConfigSchema, +} from './lib/schema.js'; From 95eed89c245c01fb77e5a968afc4890f073b5891 Mon Sep 17 00:00:00 2001 From: Michael Hladky <10064416+BioPhoton@users.noreply.github.com> Date: Tue, 11 Mar 2025 17:36:45 +0100 Subject: [PATCH 02/17] Update packages/plugin-typescript/README.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Matěj Chalk <34691111+matejchalk@users.noreply.github.com> --- packages/plugin-typescript/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/plugin-typescript/README.md b/packages/plugin-typescript/README.md index 72eae7353..6155d6122 100644 --- a/packages/plugin-typescript/README.md +++ b/packages/plugin-typescript/README.md @@ -6,7 +6,7 @@ 🕵️ **Code PushUp plugin for measuring TypeScript quality with compiler diagnostics.** 🔥 -This plugin allows you to **incrementally adopting strict compilation flags in TypeScript projects**. +This plugin allows you to **incrementally adopt strict compilation flags in TypeScript projects**. It analyzes your codebase using the TypeScript compiler to detect potential issues and configuration problems. TypeScript compiler diagnostics are mapped to Code PushUp audits in the following way: From 4accbca3302743053a7059c71d35e2596b01e30b Mon Sep 17 00:00:00 2001 From: Michael Hladky <10064416+BioPhoton@users.noreply.github.com> Date: Tue, 11 Mar 2025 17:36:54 +0100 Subject: [PATCH 03/17] Update code-pushup.config.ts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Matěj Chalk <34691111+matejchalk@users.noreply.github.com> --- code-pushup.config.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/code-pushup.config.ts b/code-pushup.config.ts index c92bf4219..07984ec3e 100644 --- a/code-pushup.config.ts +++ b/code-pushup.config.ts @@ -41,8 +41,7 @@ export default mergeConfigs( 'https://github.com/code-pushup/cli?tab=readme-ov-file#code-pushup-cli/', ), await typescriptPluginConfigNx({ - tsconfig: - 'packages/plugin-typescript/mocks/fixtures/basic-setup/tsconfig.json', + tsconfig: 'packages/cli/tsconfig.lib.json', }), await eslintCoreConfigNx(), jsDocsCoreConfig([ From d1451b596776fee28cacd9b5976e7c2a3ed86f78 Mon Sep 17 00:00:00 2001 From: Michael Hladky <10064416+BioPhoton@users.noreply.github.com> Date: Tue, 11 Mar 2025 17:37:38 +0100 Subject: [PATCH 04/17] Update packages/plugin-typescript/README.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Matěj Chalk <34691111+matejchalk@users.noreply.github.com> --- packages/plugin-typescript/README.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/plugin-typescript/README.md b/packages/plugin-typescript/README.md index 6155d6122..05138b6c7 100644 --- a/packages/plugin-typescript/README.md +++ b/packages/plugin-typescript/README.md @@ -48,10 +48,7 @@ export default { // ... plugins: [ // ... - typescriptPlugin({ - tsConfigPath: './tsconfig.json', - onlyAudits: ['no-implicit-any'], - }), + await typescriptPlugin(), ], }; ``` From 3769b215fbfa94fb3d0762382bb075df41ddf052 Mon Sep 17 00:00:00 2001 From: Michael Hladky <10064416+BioPhoton@users.noreply.github.com> Date: Tue, 11 Mar 2025 17:37:48 +0100 Subject: [PATCH 05/17] Update packages/plugin-typescript/README.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Matěj Chalk <34691111+matejchalk@users.noreply.github.com> --- packages/plugin-typescript/README.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/packages/plugin-typescript/README.md b/packages/plugin-typescript/README.md index 05138b6c7..d69a9bb5a 100644 --- a/packages/plugin-typescript/README.md +++ b/packages/plugin-typescript/README.md @@ -89,15 +89,14 @@ The plugin accepts the following parameters: | tsConfigPath | string | `tsconfig.json` | A string that defines the path to your `tsconfig.json` file | | 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 | -#### TsConfigPath +#### `tsconfig` -Optional parameter. The `tsConfigPath` option accepts a string that defines the path to your config file and defaults to `tsconfig.json`. +Optional parameter. The `tsconfig` option accepts a string that defines the path to your config file and defaults to `tsconfig.json`. ```js -typescriptPlugin({ - tsConfigPath: './tsconfig.json', +await typescriptPlugin({ + tsconfig: './tsconfig.json', }); -``` #### OnlyAudits From fd76f9554d5199cbf08d3bccf10e50778258a584 Mon Sep 17 00:00:00 2001 From: Michael Hladky <10064416+BioPhoton@users.noreply.github.com> Date: Tue, 11 Mar 2025 17:37:57 +0100 Subject: [PATCH 06/17] Update packages/plugin-typescript/README.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Matěj Chalk <34691111+matejchalk@users.noreply.github.com> --- packages/plugin-typescript/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/plugin-typescript/README.md b/packages/plugin-typescript/README.md index d69a9bb5a..5dd3cd073 100644 --- a/packages/plugin-typescript/README.md +++ b/packages/plugin-typescript/README.md @@ -11,8 +11,8 @@ It analyzes your codebase using the TypeScript compiler to detect potential issu TypeScript compiler diagnostics are mapped to Code PushUp audits in the following way: -- `value`: The number of issues found for a specific TypeScript configuration option -> 3 -- `displayValue`: The number of issues found -> 3 issues +- `value`: The number of issues found for a specific TypeScript configuration option (e.g. 3) +- `displayValue`: The number of issues found (e.g. "3 issues') - `score`: Binary scoring - 1 if no issues are found, 0 if any issues exist - Issues are mapped to audit details, containing: - Source file location From b238ec4cb4dd72770437ce7ddadd2987b2ce39e5 Mon Sep 17 00:00:00 2001 From: Michael Hladky <10064416+BioPhoton@users.noreply.github.com> Date: Tue, 11 Mar 2025 17:38:19 +0100 Subject: [PATCH 07/17] Update packages/plugin-typescript/README.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Matěj Chalk <34691111+matejchalk@users.noreply.github.com> --- packages/plugin-typescript/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/plugin-typescript/README.md b/packages/plugin-typescript/README.md index 5dd3cd073..4a487b982 100644 --- a/packages/plugin-typescript/README.md +++ b/packages/plugin-typescript/README.md @@ -110,7 +110,7 @@ typescriptPlugin({ ### Optionally set up categories -1. Reference audits (or groups) which you wish to include in custom categories (use `npx code-pushup print-config` to list audits and groups). +Reference audits (or groups) which you wish to include in custom categories (use `npx code-pushup print-config` to list audits and groups). 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). From 4f75d5ab24611e6175f3220bed44dadb98fad447 Mon Sep 17 00:00:00 2001 From: Michael Hladky <10064416+BioPhoton@users.noreply.github.com> Date: Tue, 11 Mar 2025 17:38:28 +0100 Subject: [PATCH 08/17] Update packages/plugin-typescript/README.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Matěj Chalk <34691111+matejchalk@users.noreply.github.com> --- packages/plugin-typescript/README.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/plugin-typescript/README.md b/packages/plugin-typescript/README.md index 4a487b982..c5fcb4fc0 100644 --- a/packages/plugin-typescript/README.md +++ b/packages/plugin-typescript/README.md @@ -98,15 +98,14 @@ await typescriptPlugin({ tsconfig: './tsconfig.json', }); -#### OnlyAudits +#### `onlyAudits` -Optional parameter. The `onlyAudits` option allows you to specify which documentation types you want to measure. Only the specified audits will be included in the results. Example: +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: ```js -typescriptPlugin({ +await typescriptPlugin({ onlyAudits: ['no-implicit-any'], }); -``` ### Optionally set up categories From 01eaefacd9e51d3323d6e6bb8bcb55f97c9ed5b4 Mon Sep 17 00:00:00 2001 From: Michael Hladky <10064416+BioPhoton@users.noreply.github.com> Date: Tue, 11 Mar 2025 17:38:59 +0100 Subject: [PATCH 09/17] Update packages/plugin-typescript/README.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Matěj Chalk <34691111+matejchalk@users.noreply.github.com> --- packages/plugin-typescript/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/plugin-typescript/README.md b/packages/plugin-typescript/README.md index c5fcb4fc0..5bdab9e31 100644 --- a/packages/plugin-typescript/README.md +++ b/packages/plugin-typescript/README.md @@ -39,7 +39,7 @@ TypeScript compiler diagnostics are mapped to Code PushUp audits in the followin 3. Add this plugin to the `plugins` array in your Code PushUp CLI config file (e.g. `code-pushup.config.ts`). -Define the ts config file used to compile your codebase. Based on those compiler options the plugin will generate audits. +By default, a root `tsconfig.json` is used to compile your codebase. Based on those compiler options, the plugin will generate audits. ```ts import typescriptPlugin from '@code-pushup/typescript-plugin'; From ea6443cbf93cf50efe383f016f699549c9b78c3a Mon Sep 17 00:00:00 2001 From: Michael Hladky <10064416+BioPhoton@users.noreply.github.com> Date: Tue, 11 Mar 2025 17:39:13 +0100 Subject: [PATCH 10/17] Update packages/plugin-typescript/README.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Matěj Chalk <34691111+matejchalk@users.noreply.github.com> --- packages/plugin-typescript/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/plugin-typescript/README.md b/packages/plugin-typescript/README.md index 5bdab9e31..8c46bd867 100644 --- a/packages/plugin-typescript/README.md +++ b/packages/plugin-typescript/README.md @@ -67,7 +67,7 @@ The plugin provides multiple audits grouped into different sets: - _Configuration Errors_: `configuration-errors` - Errors that occur when parsing TypeScript configuration files - _Declaration and Language Service Errors_: `declaration-and-language-service-errors` - Errors that occur during TypeScript language service operations - _Internal Errors_: `internal-errors` - Errors that occur during TypeScript internal operations -- _No Implicit Any Errors_: `no-implicit-any-errors` - Errors related to no implicit any compiler option +- _No Implicit Any Errors_: `no-implicit-any-errors` - Errors related to `noImplicitAny` compiler option - _Unknown Codes_: `unknown-codes` - Errors that do not match any known TypeScript error code Each audit: From 0625d41f79ae4571721db6c2574d7dd7bc8df781 Mon Sep 17 00:00:00 2001 From: Michael Hladky <10064416+BioPhoton@users.noreply.github.com> Date: Tue, 11 Mar 2025 17:39:29 +0100 Subject: [PATCH 11/17] Update packages/plugin-typescript/README.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Matěj Chalk <34691111+matejchalk@users.noreply.github.com> --- packages/plugin-typescript/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/plugin-typescript/README.md b/packages/plugin-typescript/README.md index 8c46bd867..d702aad72 100644 --- a/packages/plugin-typescript/README.md +++ b/packages/plugin-typescript/README.md @@ -86,7 +86,7 @@ The plugin accepts the following parameters: | Option | Type | Default | Description | | ------------ | -------- | --------------- | ------------------------------------------------------------------------------------------------------------------------------------------- | -| tsConfigPath | string | `tsconfig.json` | A string that defines the path to your `tsconfig.json` file | +| tsconfig | string | `tsconfig.json` | A string that defines the path to your `tsconfig.json` file | | 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 | #### `tsconfig` From 32daa061e9e6cf06e9c16fdb67669447470e7edb Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 19 Mar 2025 22:50:51 +0100 Subject: [PATCH 12/17] fix(plugin-typescript): add display value --- packages/plugin-typescript/README.md | 16 ++++++++-------- .../plugin-typescript/src/lib/runner/runner.ts | 2 ++ .../src/lib/runner/runner.unit.test.ts | 1 + 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/packages/plugin-typescript/README.md b/packages/plugin-typescript/README.md index d702aad72..1902523f6 100644 --- a/packages/plugin-typescript/README.md +++ b/packages/plugin-typescript/README.md @@ -84,16 +84,16 @@ Each set is also available as group in the plugin. See more under [Audits and Gr The plugin accepts the following parameters: -| Option | Type | Default | Description | -| ------------ | -------- | --------------- | ------------------------------------------------------------------------------------------------------------------------------------------- | -| tsconfig | string | `tsconfig.json` | A string that defines the path to your `tsconfig.json` file | -| 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 | +| Option | Type | Default | Description | +| ---------- | -------- | --------------- | ------------------------------------------------------------------------------------------------------------------------------------------- | +| tsconfig | string | `tsconfig.json` | A string that defines the path to your `tsconfig.json` file | +| 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 | #### `tsconfig` Optional parameter. The `tsconfig` option accepts a string that defines the path to your config file and defaults to `tsconfig.json`. -```js +````js await typescriptPlugin({ tsconfig: './tsconfig.json', }); @@ -123,13 +123,13 @@ categories: [ { type: 'audit', plugin: 'typescript', - slug: 'no-implicit-any', + slug: 'semantic-errors', weight: 2, }, { type: 'audit', plugin: 'typescript', - slug: 'no-explicit-any', + slug: 'syntax-errors', weight: 1, }, // ... @@ -137,7 +137,7 @@ categories: [ }, // ... ]; -``` +```` Also groups can be used: diff --git a/packages/plugin-typescript/src/lib/runner/runner.ts b/packages/plugin-typescript/src/lib/runner/runner.ts index 0c12a393d..30c560895 100644 --- a/packages/plugin-typescript/src/lib/runner/runner.ts +++ b/packages/plugin-typescript/src/lib/runner/runner.ts @@ -4,6 +4,7 @@ import type { Issue, RunnerFunction, } from '@code-pushup/models'; +import { pluralize } from '@code-pushup/utils'; import type { AuditSlug } from '../types.js'; import { type DiagnosticsOptions, @@ -44,6 +45,7 @@ export function createRunnerFunction(options: RunnerOptions): RunnerFunction { slug, score: issues.length === 0 ? 1 : 0, value: issues.length, + displayValue: `${issues.length} ${pluralize('issue', issues.length)}`, ...(issues.length > 0 ? { details } : {}), } satisfies AuditOutput; }); diff --git a/packages/plugin-typescript/src/lib/runner/runner.unit.test.ts b/packages/plugin-typescript/src/lib/runner/runner.unit.test.ts index 804260e38..063ac9583 100644 --- a/packages/plugin-typescript/src/lib/runner/runner.unit.test.ts +++ b/packages/plugin-typescript/src/lib/runner/runner.unit.test.ts @@ -110,6 +110,7 @@ describe('createRunnerFunction', () => { slug: 'semantic-errors', score: 0, value: 2, + displayValue: '2 issues', details: { issues: [ expect.objectContaining({ From 8a5bde70621082d6fad0e2dfbc7c22ccb97f28d6 Mon Sep 17 00:00:00 2001 From: Michael Hladky <10064416+BioPhoton@users.noreply.github.com> Date: Thu, 20 Mar 2025 14:36:09 +0100 Subject: [PATCH 13/17] Update packages/plugin-typescript/README.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Matěj Chalk <34691111+matejchalk@users.noreply.github.com> --- packages/plugin-typescript/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/plugin-typescript/README.md b/packages/plugin-typescript/README.md index 1902523f6..7aa9d1f01 100644 --- a/packages/plugin-typescript/README.md +++ b/packages/plugin-typescript/README.md @@ -12,7 +12,7 @@ It analyzes your codebase using the TypeScript compiler to detect potential issu TypeScript compiler diagnostics are mapped to Code PushUp audits in the following way: - `value`: The number of issues found for a specific TypeScript configuration option (e.g. 3) -- `displayValue`: The number of issues found (e.g. "3 issues') +- `displayValue`: The number of issues found (e.g. "3 issues") - `score`: Binary scoring - 1 if no issues are found, 0 if any issues exist - Issues are mapped to audit details, containing: - Source file location From cdb3d364f3573e6a0f35a7ea556f29820deb8b9a Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 20 Mar 2025 14:37:09 +0100 Subject: [PATCH 14/17] docs(plugin-typescript): fix type --- packages/plugin-typescript/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/plugin-typescript/README.md b/packages/plugin-typescript/README.md index 7aa9d1f01..5fca001fc 100644 --- a/packages/plugin-typescript/README.md +++ b/packages/plugin-typescript/README.md @@ -137,7 +137,7 @@ categories: [ }, // ... ]; -```` +``` Also groups can be used: @@ -160,3 +160,4 @@ categories: [ // ... ]; ``` +```` From dfb3d5502936370989b9e4267129da51de3732f8 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 20 Mar 2025 15:09:55 +0100 Subject: [PATCH 15/17] test(plugin-typescript): fix integration test --- .../runner/__snapshots__/runner-function-all-audits.json | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/plugin-typescript/src/lib/runner/__snapshots__/runner-function-all-audits.json b/packages/plugin-typescript/src/lib/runner/__snapshots__/runner-function-all-audits.json index d5deaabe4..919122510 100644 --- a/packages/plugin-typescript/src/lib/runner/__snapshots__/runner-function-all-audits.json +++ b/packages/plugin-typescript/src/lib/runner/__snapshots__/runner-function-all-audits.json @@ -14,6 +14,7 @@ }, ], }, + "displayValue": "1 issue", "score": 0, "slug": "syntax-errors", "value": 1, @@ -74,6 +75,7 @@ }, ], }, + "displayValue": "5 issues", "score": 0, "slug": "semantic-errors", "value": 5, @@ -93,26 +95,31 @@ }, ], }, + "displayValue": "1 issue", "score": 0, "slug": "declaration-and-language-service-errors", "value": 1, }, { + "displayValue": "0 issues", "score": 1, "slug": "internal-errors", "value": 0, }, { + "displayValue": "0 issues", "score": 1, "slug": "configuration-errors", "value": 0, }, { + "displayValue": "0 issues", "score": 1, "slug": "no-implicit-any-errors", "value": 0, }, { + "displayValue": "0 issues", "score": 1, "slug": "unknown-codes", "value": 0, From f7a2def4f05e77925584553c8d655d690688b479 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 20 Mar 2025 15:39:01 +0100 Subject: [PATCH 16/17] docs(plugin-typescript): fix typo From 7536f28ee9c9ae7f69bae159f08dea02410c2e1e Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 21 Mar 2025 12:48:30 +0100 Subject: [PATCH 17/17] docs(plugin-typescript): fix code blocks --- packages/plugin-typescript/README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/plugin-typescript/README.md b/packages/plugin-typescript/README.md index 5fca001fc..9ae5b9697 100644 --- a/packages/plugin-typescript/README.md +++ b/packages/plugin-typescript/README.md @@ -93,10 +93,11 @@ The plugin accepts the following parameters: Optional parameter. The `tsconfig` option accepts a string that defines the path to your config file and defaults to `tsconfig.json`. -````js +```js await typescriptPlugin({ tsconfig: './tsconfig.json', }); +``` #### `onlyAudits` @@ -106,6 +107,7 @@ The `onlyAudits` option allows you to specify which documentation types you want await typescriptPlugin({ onlyAudits: ['no-implicit-any'], }); +``` ### Optionally set up categories @@ -160,4 +162,3 @@ categories: [ // ... ]; ``` -````