|
6 | 6 |
|
7 | 7 | 🕵️ **Code PushUp plugin for measuring TypeScript quality with compiler diagnostics.** 🔥 |
8 | 8 |
|
9 | | ---- |
| 9 | +This plugin allows you to measure and track TypeScript compiler diagnostics in your TypeScript/JavaScript project. |
| 10 | +It analyzes your codebase using the TypeScript compiler to detect potential issues and configuration problems. |
10 | 11 |
|
11 | | -The plugin parses your TypeScript and JavaScript code and lints all audits of the official [TypeScript Compiler](). |
| 12 | +TypeScript compiler diagnostics are mapped to Code PushUp audits in the following way: |
12 | 13 |
|
13 | | -For more infos visit the [official docs](https://developer.chrome.com/docs/typescript/overview). |
| 14 | +- `value`: The number of issues found for a specific TypeScript configuration option -> 3 |
| 15 | +- `displayValue`: The number of issues found -> 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 |
14 | 21 |
|
15 | 22 | ## Getting started |
16 | 23 |
|
@@ -50,41 +57,148 @@ For more infos visit the [official docs](https://developer.chrome.com/docs/types |
50 | 57 |
|
51 | 58 | 4. Run the CLI with `npx code-pushup collect` and view or upload the report (refer to [CLI docs](../cli/README.md)). |
52 | 59 |
|
53 | | -### Optionally set up categories |
| 60 | +## About documentation coverage |
54 | 61 |
|
55 | | -Reference audits (or groups) which you wish to include in custom categories (use `npx code-pushup print-config --onlyPlugins=typescript` to list audits and groups). |
| 62 | +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. |
56 | 63 |
|
57 | | -Assign weights based on what influence each Lighthouse audit has on the overall category score (assign weight 0 to only include as extra info, without influencing category score). |
58 | | -The plugin exports the helper `typescriptAuditRef` and `typescriptGroupRef` to reference Lighthouse category references for audits and groups. |
| 64 | +The plugin provides multiple audits grouped into different categories like: |
59 | 65 |
|
60 | | -#### Reference audits directly with `typescriptGroupRef` |
| 66 | +- Language and Environment - Checks configuration for TypeScript features like decorators, JSX, target version |
| 67 | +- Type Checking - Validates strict null checks, implicit any/this, function types |
| 68 | +- Module Resolution - Verifies module imports/exports and resolution settings |
| 69 | +- Build/Emit Options - Checks output generation and optimization settings |
| 70 | +- Control Flow - Analyzes code flow, unreachable code, switch statements |
61 | 71 |
|
62 | | -```ts |
63 | | -import { typescriptGroupRef } from './utils'; |
| 72 | +Each audit: |
| 73 | + |
| 74 | +- Checks for specific TypeScript compiler errors and warnings |
| 75 | +- Provides a score based on the number of issues found |
| 76 | +- Includes detailed error messages and locations |
| 77 | + |
| 78 | +The audits are organized into logical groups to give you a comprehensive view of your TypeScript configuration and code quality. You can: |
| 79 | + |
| 80 | +- Use all groups for complete TypeScript analysis |
| 81 | +- Focus on specific groups or individual audits based on your needs |
| 82 | + |
| 83 | +## Plugin architecture |
| 84 | + |
| 85 | +### Plugin configuration specification |
| 86 | + |
| 87 | +The plugin accepts the following parameters: |
64 | 88 |
|
65 | | -export default { |
66 | | - // ... |
67 | | - categories: [], |
68 | | -}; |
| 89 | +#### TsConfigPath |
| 90 | + |
| 91 | +Required parameter. The `tsConfigPath` option accepts a string that defines the path to your `tsconfig.json` file. |
| 92 | + |
| 93 | +```js |
| 94 | +typescriptPlugin({ |
| 95 | + tsConfigPath: './tsconfig.json', |
| 96 | +}), |
69 | 97 | ``` |
70 | 98 |
|
71 | | -#### Reference groups with `typescriptAuditRef` |
| 99 | +#### OnlyAudits |
| 100 | + |
| 101 | +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: |
| 102 | + |
| 103 | +```js |
| 104 | +typescriptPlugin({ |
| 105 | + tsConfigPath: './tsconfig.json', |
| 106 | + onlyAudits: [ |
| 107 | + 'no-implicit-any' |
| 108 | + ] // Only measure documentation for classes and functions |
| 109 | +}), |
| 110 | +``` |
| 111 | + |
| 112 | +### Audits and group |
| 113 | + |
| 114 | +This plugin provides a list of groups to cover different TypeScript configuration options and their areas of responsibility. |
72 | 115 |
|
73 | | -The TypeScript categories are reflected as groups. |
74 | | -Referencing individual audits offers more granularity. However, keep maintenance costs of a higher number of audits in mind as well. |
| 116 | +```ts |
| 117 | + // ... |
| 118 | + categories: [ |
| 119 | + { |
| 120 | + slug: 'typescript', |
| 121 | + title: 'TypeScript', |
| 122 | + refs: [ |
| 123 | + { |
| 124 | + slug: 'language-and-environment', |
| 125 | + weight: 1, |
| 126 | + type: 'group', |
| 127 | + plugin: 'typescript' |
| 128 | + }, |
| 129 | + // ... |
| 130 | + ], |
| 131 | + }, |
| 132 | + // ... |
| 133 | + ], |
| 134 | +``` |
| 135 | + |
| 136 | +Each TypeScript configuration option still has its own audit. So when you want to include a subset of configuration options or assign different weights to them, you can do so in the following way: |
75 | 137 |
|
76 | 138 | ```ts |
77 | | -import { typescriptAuditRef } from './utils'; |
| 139 | + // ... |
| 140 | + categories: [ |
| 141 | + { |
| 142 | + slug: 'typescript', |
| 143 | + title: 'TypeScript', |
| 144 | + refs: [ |
| 145 | + { |
| 146 | + type: 'audit', |
| 147 | + plugin: 'typescript', |
| 148 | + slug: 'no-implicit-any', |
| 149 | + weight: 2, |
| 150 | + }, |
| 151 | + { |
| 152 | + type: 'audit', |
| 153 | + plugin: 'typescript', |
| 154 | + slug: 'no-explicit-any', |
| 155 | + weight: 1, |
| 156 | + }, |
| 157 | + // ... |
| 158 | + ], |
| 159 | + }, |
| 160 | + // ... |
| 161 | + ], |
| 162 | +``` |
| 163 | + |
| 164 | +### Audit output |
78 | 165 |
|
79 | | -export default { |
80 | | - // ... |
81 | | - categories: [ |
| 166 | +The plugin outputs a single audit that measures the overall documentation coverage percentage of your codebase. |
| 167 | + |
| 168 | +For instance, this is an example of the plugin output: |
| 169 | + |
| 170 | +```json |
| 171 | +{ |
| 172 | + "packageName": "@code-pushup/typescript-plugin", |
| 173 | + "version": "0.57.0", |
| 174 | + "title": "Typescript", |
| 175 | + "slug": "typescript", |
| 176 | + "icon": "typescript", |
| 177 | + "date": "2024-12-25T11:10:22.646Z", |
| 178 | + "duration": 2059, |
| 179 | + "audits": [ |
82 | 180 | { |
83 | | - slug: 'pwa', |
84 | | - title: 'PWA', |
85 | | - isBinary: true, |
86 | | - refs: [typescriptAuditRef('installable-manifest', 2), typescriptAuditRef('splash-screen', 1), typescriptAuditRef('themed-omnibox', 1), typescriptAuditRef('content-width', 1), typescriptAuditRef('themed-omnibox', 2), typescriptAuditRef('viewport', 2), typescriptAuditRef('maskable-icon', 1), typescriptAuditRef('pwa-cross-browser', 0), typescriptAuditRef('pwa-page-transitions', 0), typescriptAuditRef('pwa-each-page-has-url', 0)], |
87 | | - }, |
| 181 | + "slug": "experimental-decorators", |
| 182 | + "value": 0, |
| 183 | + "score": 1, |
| 184 | + "title": "ExperimentalDecorators", |
| 185 | + "docsUrl": "https://www.typescriptlang.org/tsconfig/#experimentalDecorators" |
| 186 | + } |
88 | 187 | ], |
89 | | -}; |
| 188 | + "description": "Official Code PushUp typescript plugin.", |
| 189 | + "docsUrl": "https://www.npmjs.com/package/@code-pushup/typescript-plugin/", |
| 190 | + "groups": [ |
| 191 | + { |
| 192 | + "slug": "language-and-environment", |
| 193 | + "refs": [ |
| 194 | + { |
| 195 | + "slug": "experimental-decorators", |
| 196 | + "weight": 1 |
| 197 | + } |
| 198 | + ], |
| 199 | + "title": "LanguageAndEnvironment", |
| 200 | + "description": "Configuration options for TypeScript language features and runtime environment" |
| 201 | + } |
| 202 | + ] |
| 203 | +} |
90 | 204 | ``` |
0 commit comments