@code-pushup/jsdocs-plugin 0.58.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 +241 -0
- package/package.json +46 -0
- package/src/index.d.ts +3 -0
- package/src/index.js +3 -0
- package/src/index.js.map +1 -0
- package/src/lib/config.d.ts +34 -0
- package/src/lib/config.js +26 -0
- package/src/lib/config.js.map +1 -0
- package/src/lib/constants.d.ts +5 -0
- package/src/lib/constants.js +61 -0
- package/src/lib/constants.js.map +1 -0
- package/src/lib/jsdocs-plugin.d.ts +22 -0
- package/src/lib/jsdocs-plugin.js +37 -0
- package/src/lib/jsdocs-plugin.js.map +1 -0
- package/src/lib/models.d.ts +2 -0
- package/src/lib/models.js +2 -0
- package/src/lib/models.js.map +1 -0
- package/src/lib/runner/constants.d.ts +4 -0
- package/src/lib/runner/constants.js +14 -0
- package/src/lib/runner/constants.js.map +1 -0
- package/src/lib/runner/doc-processor.d.ts +45 -0
- package/src/lib/runner/doc-processor.js +120 -0
- package/src/lib/runner/doc-processor.js.map +1 -0
- package/src/lib/runner/models.d.ts +21 -0
- package/src/lib/runner/models.js +2 -0
- package/src/lib/runner/models.js.map +1 -0
- package/src/lib/runner/runner.d.ts +11 -0
- package/src/lib/runner/runner.js +44 -0
- package/src/lib/runner/runner.js.map +1 -0
- package/src/lib/runner/utils.d.ts +25 -0
- package/src/lib/runner/utils.js +59 -0
- package/src/lib/runner/utils.js.map +1 -0
- package/src/lib/utils.d.ts +18 -0
- package/src/lib/utils.js +35 -0
- package/src/lib/utils.js.map +1 -0
package/README.md
ADDED
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
# @code-pushup/jsdocs-plugin
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@code-pushup/jsdocs-plugin)
|
|
4
|
+
[](https://npmtrends.com/@code-pushup/jsdocs-plugin)
|
|
5
|
+
[](https://www.npmjs.com/package/@code-pushup/jsdocs-plugin?activeTab=dependencies)
|
|
6
|
+
|
|
7
|
+
📚 **Code PushUp plugin for tracking documentation coverage.** 📝
|
|
8
|
+
|
|
9
|
+
This plugin allows you to measure and track documentation coverage in your TypeScript/JavaScript project.
|
|
10
|
+
It analyzes your codebase and checks for documentation on different code elements like classes, functions, interfaces, types, and variables.
|
|
11
|
+
|
|
12
|
+
Measured documentation types are mapped to Code PushUp audits in the following way:
|
|
13
|
+
|
|
14
|
+
- `value`: The value is the number of undocumented nodes -> 4
|
|
15
|
+
- `displayValue`: `${value} undocumented ${type}` -> 4 undocumented functions
|
|
16
|
+
- `score`: 0.5 -> total nodes 8, undocumented 4 -> 4/8
|
|
17
|
+
- The score is value converted to 0-1 range
|
|
18
|
+
- Missing documentation is mapped to issues in the audit details (undocumented classes, functions, interfaces, etc.)
|
|
19
|
+
|
|
20
|
+
## Getting started
|
|
21
|
+
|
|
22
|
+
1. If you haven't already, install [@code-pushup/cli](../cli/README.md) and create a configuration file.
|
|
23
|
+
|
|
24
|
+
2. Install as a dev dependency with your package manager:
|
|
25
|
+
|
|
26
|
+
```sh
|
|
27
|
+
npm install --save-dev @code-pushup/jsdocs-plugin
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
```sh
|
|
31
|
+
yarn add --dev @code-pushup/jsdocs-plugin
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
```sh
|
|
35
|
+
pnpm add --save-dev @code-pushup/jsdocs-plugin
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
3. Add this plugin to the `plugins` array in your Code PushUp CLI config file (e.g. `code-pushup.config.ts`).
|
|
39
|
+
|
|
40
|
+
```js
|
|
41
|
+
import jsDocsPlugin from '@code-pushup/jsdocs-plugin';
|
|
42
|
+
|
|
43
|
+
export default {
|
|
44
|
+
// ...
|
|
45
|
+
plugins: [
|
|
46
|
+
// ...
|
|
47
|
+
jsDocsPlugin(['**/*.ts']),
|
|
48
|
+
],
|
|
49
|
+
};
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
4. (Optional) Reference individual audits or the provided plugin group which you wish to include in custom categories (use `npx code-pushup print-config` to list audits and groups).
|
|
53
|
+
|
|
54
|
+
💡 Assign weights based on what influence each documentation type should have on the overall category score (assign weight 0 to only include as extra info, without influencing category score).
|
|
55
|
+
|
|
56
|
+
```js
|
|
57
|
+
export default {
|
|
58
|
+
// ...
|
|
59
|
+
categories: [
|
|
60
|
+
{
|
|
61
|
+
slug: 'documentation',
|
|
62
|
+
title: 'Documentation',
|
|
63
|
+
refs: [
|
|
64
|
+
{
|
|
65
|
+
type: 'group',
|
|
66
|
+
plugin: 'jsdocs',
|
|
67
|
+
slug: 'jsdocs',
|
|
68
|
+
weight: 1,
|
|
69
|
+
},
|
|
70
|
+
// ...
|
|
71
|
+
],
|
|
72
|
+
},
|
|
73
|
+
// ...
|
|
74
|
+
],
|
|
75
|
+
};
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
5. Run the CLI with `npx code-pushup collect` and view or upload report (refer to [CLI docs](../cli/README.md)).
|
|
79
|
+
|
|
80
|
+
## About documentation coverage
|
|
81
|
+
|
|
82
|
+
Documentation coverage is a metric that indicates what percentage of your code elements have proper documentation. It helps ensure your codebase is well-documented and maintainable.
|
|
83
|
+
|
|
84
|
+
The plugin provides multiple audits, one for each documentation type (classes, functions, interfaces, etc.), and groups them together for an overall documentation coverage measurement. Each audit:
|
|
85
|
+
|
|
86
|
+
- Measures the documentation coverage for its specific type (e.g., classes, functions)
|
|
87
|
+
- Provides a score based on the percentage of documented elements
|
|
88
|
+
- Includes details about which elements are missing documentation
|
|
89
|
+
|
|
90
|
+
These audits are grouped together to provide a comprehensive view of your codebase's documentation status. You can use either:
|
|
91
|
+
|
|
92
|
+
- The complete group of audits for overall documentation coverage
|
|
93
|
+
- Individual audits to focus on specific documentation types
|
|
94
|
+
|
|
95
|
+
## Plugin architecture
|
|
96
|
+
|
|
97
|
+
### Plugin configuration specification
|
|
98
|
+
|
|
99
|
+
The plugin accepts the following parameters:
|
|
100
|
+
|
|
101
|
+
#### patterns
|
|
102
|
+
|
|
103
|
+
Required parameter. The `patterns` option accepts an array of strings that define patterns to include or exclude files. You can use glob patterns to match files and the `!` symbol to exclude specific patterns. Example:
|
|
104
|
+
|
|
105
|
+
```js
|
|
106
|
+
jsDocsPlugin({
|
|
107
|
+
patterns: [
|
|
108
|
+
'src/**/*.ts', // include all TypeScript files in src
|
|
109
|
+
'!src/**/*.{spec,test}.ts', // exclude test files
|
|
110
|
+
'!src/**/testing/**/*.ts' // exclude testing utilities
|
|
111
|
+
],
|
|
112
|
+
}),
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
#### OnlyAudits
|
|
116
|
+
|
|
117
|
+
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:
|
|
118
|
+
|
|
119
|
+
```js
|
|
120
|
+
jsDocsPlugin({
|
|
121
|
+
patterns: ['src/**/*.ts'],
|
|
122
|
+
onlyAudits: [
|
|
123
|
+
'classes-coverage',
|
|
124
|
+
'functions-coverage'
|
|
125
|
+
] // Only measure documentation for classes and functions
|
|
126
|
+
}),
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
#### SkipAudits
|
|
130
|
+
|
|
131
|
+
Optional parameter. The `skipAudits` option allows you to exclude specific documentation types from measurement. All other types will be included in the results.
|
|
132
|
+
|
|
133
|
+
```js
|
|
134
|
+
jsDocsPlugin({
|
|
135
|
+
patterns: ['src/**/*.ts'],
|
|
136
|
+
skipAudits: [
|
|
137
|
+
'variables-coverage',
|
|
138
|
+
'interfaces-coverage'
|
|
139
|
+
] // Measure all documentation types except variables and interfaces
|
|
140
|
+
}),
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
> ⚠️ **Warning:** You cannot use both `onlyAudits` and `skipAudits` in the same configuration. Choose the one that better suits your needs.
|
|
144
|
+
|
|
145
|
+
### Audits and group
|
|
146
|
+
|
|
147
|
+
This plugin provides a group for convenient declaration in your config. When defined this way, all measured documentation type audits have the same weight.
|
|
148
|
+
|
|
149
|
+
```ts
|
|
150
|
+
// ...
|
|
151
|
+
categories: [
|
|
152
|
+
{
|
|
153
|
+
slug: 'documentation',
|
|
154
|
+
title: 'Documentation',
|
|
155
|
+
refs: [
|
|
156
|
+
{
|
|
157
|
+
type: 'group',
|
|
158
|
+
plugin: 'jsdocs',
|
|
159
|
+
slug: 'jsdocs',
|
|
160
|
+
weight: 1,
|
|
161
|
+
},
|
|
162
|
+
// ...
|
|
163
|
+
],
|
|
164
|
+
},
|
|
165
|
+
// ...
|
|
166
|
+
],
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
Each documentation type still has its own audit. So when you want to include a subset of documentation types or assign different weights to them, you can do so in the following way:
|
|
170
|
+
|
|
171
|
+
```ts
|
|
172
|
+
// ...
|
|
173
|
+
categories: [
|
|
174
|
+
{
|
|
175
|
+
slug: 'documentation',
|
|
176
|
+
title: 'Documentation',
|
|
177
|
+
refs: [
|
|
178
|
+
{
|
|
179
|
+
type: 'audit',
|
|
180
|
+
plugin: 'jsdocs',
|
|
181
|
+
slug: 'class-jsdocs',
|
|
182
|
+
weight: 2,
|
|
183
|
+
},
|
|
184
|
+
{
|
|
185
|
+
type: 'audit',
|
|
186
|
+
plugin: 'jsdocs',
|
|
187
|
+
slug: 'function-jsdocs',
|
|
188
|
+
weight: 1,
|
|
189
|
+
},
|
|
190
|
+
// ...
|
|
191
|
+
],
|
|
192
|
+
},
|
|
193
|
+
// ...
|
|
194
|
+
],
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
### Audit output
|
|
198
|
+
|
|
199
|
+
The plugin outputs a single audit that measures the overall documentation coverage percentage of your codebase.
|
|
200
|
+
|
|
201
|
+
For instance, this is an example of the plugin output:
|
|
202
|
+
|
|
203
|
+
```json
|
|
204
|
+
{
|
|
205
|
+
"packageName": "@code-pushup/jsdocs-plugin",
|
|
206
|
+
"version": "0.57.0",
|
|
207
|
+
"title": "Documentation coverage",
|
|
208
|
+
"slug": "jsdocs",
|
|
209
|
+
"icon": "folder-src",
|
|
210
|
+
"duration": 920,
|
|
211
|
+
"date": "2024-12-17T16:45:28.581Z",
|
|
212
|
+
"audits": [
|
|
213
|
+
{
|
|
214
|
+
"slug": "percentage-coverage",
|
|
215
|
+
"displayValue": "16 %",
|
|
216
|
+
"value": 16,
|
|
217
|
+
"score": 0.16,
|
|
218
|
+
"details": {
|
|
219
|
+
"issues": []
|
|
220
|
+
},
|
|
221
|
+
"title": "Percentage of codebase with documentation",
|
|
222
|
+
"description": "Measures how many % of the codebase have documentation."
|
|
223
|
+
}
|
|
224
|
+
],
|
|
225
|
+
"description": "Official Code PushUp documentation coverage plugin.",
|
|
226
|
+
"docsUrl": "https://www.npmjs.com/package/@code-pushup/jsdocs-plugin/",
|
|
227
|
+
"groups": [
|
|
228
|
+
{
|
|
229
|
+
"slug": "jsdocs",
|
|
230
|
+
"refs": [
|
|
231
|
+
{
|
|
232
|
+
"slug": "percentage-coverage",
|
|
233
|
+
"weight": 1
|
|
234
|
+
}
|
|
235
|
+
],
|
|
236
|
+
"title": "Documentation coverage metrics",
|
|
237
|
+
"description": "Group containing all defined documentation coverage types as audits."
|
|
238
|
+
}
|
|
239
|
+
]
|
|
240
|
+
}
|
|
241
|
+
```
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@code-pushup/jsdocs-plugin",
|
|
3
|
+
"version": "0.58.0",
|
|
4
|
+
"description": "Code PushUp plugin for tracking documentation coverage 📚",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"homepage": "https://github.com/code-pushup/cli/tree/main/packages/plugin-jsdocs#readme",
|
|
7
|
+
"bugs": {
|
|
8
|
+
"url": "https://github.com/code-pushup/cli/issues?q=is%3Aissue%20state%3Aopen%20type%3ABug%20label%3A\"🧩%20jsdocs-plugin\""
|
|
9
|
+
},
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/code-pushup/cli.git",
|
|
13
|
+
"directory": "packages/plugin-jsdocs"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"documentation coverage",
|
|
17
|
+
"documentation quality",
|
|
18
|
+
"docs completeness",
|
|
19
|
+
"automated documentation checks",
|
|
20
|
+
"coverage audit",
|
|
21
|
+
"documentation conformance",
|
|
22
|
+
"docs KPI tracking",
|
|
23
|
+
"documentation feedback",
|
|
24
|
+
"actionable documentation insights",
|
|
25
|
+
"documentation regression guard",
|
|
26
|
+
"documentation score monitoring",
|
|
27
|
+
"developer documentation tools",
|
|
28
|
+
"plugin for documentation coverage",
|
|
29
|
+
"CLI documentation coverage",
|
|
30
|
+
"Code PushUp documentation",
|
|
31
|
+
"documentation audit"
|
|
32
|
+
],
|
|
33
|
+
"publishConfig": {
|
|
34
|
+
"access": "public"
|
|
35
|
+
},
|
|
36
|
+
"type": "module",
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@code-pushup/models": "0.58.0",
|
|
39
|
+
"@code-pushup/utils": "0.58.0",
|
|
40
|
+
"zod": "^3.22.4",
|
|
41
|
+
"ts-morph": "^24.0.0"
|
|
42
|
+
},
|
|
43
|
+
"module": "./src/index.js",
|
|
44
|
+
"main": "./src/index.js",
|
|
45
|
+
"types": "./src/index.d.ts"
|
|
46
|
+
}
|
package/src/index.d.ts
ADDED
package/src/index.js
ADDED
package/src/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/plugin-jsdocs/src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAEtD,eAAe,YAAY,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const jsDocsPluginConfigSchema: z.ZodEffects<z.ZodUnion<[z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>, z.ZodEffects<z.ZodObject<{
|
|
3
|
+
skipAudits: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
4
|
+
onlyAudits: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
5
|
+
patterns: z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>;
|
|
6
|
+
}, "strip", z.ZodTypeAny, {
|
|
7
|
+
patterns: string | string[];
|
|
8
|
+
skipAudits?: string[] | undefined;
|
|
9
|
+
onlyAudits?: string[] | undefined;
|
|
10
|
+
}, {
|
|
11
|
+
patterns: string | string[];
|
|
12
|
+
skipAudits?: string[] | undefined;
|
|
13
|
+
onlyAudits?: string[] | undefined;
|
|
14
|
+
}>, {
|
|
15
|
+
patterns: string | string[];
|
|
16
|
+
skipAudits?: string[] | undefined;
|
|
17
|
+
onlyAudits?: string[] | undefined;
|
|
18
|
+
}, {
|
|
19
|
+
patterns: string | string[];
|
|
20
|
+
skipAudits?: string[] | undefined;
|
|
21
|
+
onlyAudits?: string[] | undefined;
|
|
22
|
+
}>]>, {
|
|
23
|
+
patterns: string | string[];
|
|
24
|
+
skipAudits?: string[] | undefined;
|
|
25
|
+
onlyAudits?: string[] | undefined;
|
|
26
|
+
}, string | string[] | {
|
|
27
|
+
patterns: string | string[];
|
|
28
|
+
skipAudits?: string[] | undefined;
|
|
29
|
+
onlyAudits?: string[] | undefined;
|
|
30
|
+
}>;
|
|
31
|
+
/** Type of the config that is passed to the plugin */
|
|
32
|
+
export type JsDocsPluginConfig = z.input<typeof jsDocsPluginConfigSchema>;
|
|
33
|
+
/** Same as JsDocsPluginConfig but processed so the config is already an object even if it was passed the array of patterns */
|
|
34
|
+
export type JsDocsPluginTransformedConfig = z.infer<typeof jsDocsPluginConfigSchema>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
const patternsSchema = z.union([z.string(), z.array(z.string()).min(1)], {
|
|
3
|
+
description: 'Glob pattern to match source files to evaluate.',
|
|
4
|
+
});
|
|
5
|
+
const jsDocsTargetObjectSchema = z
|
|
6
|
+
.object({
|
|
7
|
+
skipAudits: z
|
|
8
|
+
.array(z.string())
|
|
9
|
+
.optional()
|
|
10
|
+
.describe('List of audit slugs to exclude from evaluation. When specified, all audits except these will be evaluated.'),
|
|
11
|
+
onlyAudits: z
|
|
12
|
+
.array(z.string())
|
|
13
|
+
.optional()
|
|
14
|
+
.describe('List of audit slugs to evaluate. When specified, only these audits will be evaluated.'),
|
|
15
|
+
patterns: patternsSchema,
|
|
16
|
+
})
|
|
17
|
+
.refine(data => !(data.skipAudits && data.onlyAudits), {
|
|
18
|
+
message: "You can't define 'skipAudits' and 'onlyAudits' simultaneously",
|
|
19
|
+
path: ['skipAudits', 'onlyAudits'],
|
|
20
|
+
});
|
|
21
|
+
export const jsDocsPluginConfigSchema = z
|
|
22
|
+
.union([patternsSchema, jsDocsTargetObjectSchema])
|
|
23
|
+
.transform(target => typeof target === 'string' || Array.isArray(target)
|
|
24
|
+
? { patterns: target }
|
|
25
|
+
: target);
|
|
26
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../../../../packages/plugin-jsdocs/src/lib/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE;IACvE,WAAW,EAAE,iDAAiD;CAC/D,CAAC,CAAC;AAEH,MAAM,wBAAwB,GAAG,CAAC;KAC/B,MAAM,CAAC;IACN,UAAU,EAAE,CAAC;SACV,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;SACjB,QAAQ,EAAE;SACV,QAAQ,CACP,4GAA4G,CAC7G;IACH,UAAU,EAAE,CAAC;SACV,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;SACjB,QAAQ,EAAE;SACV,QAAQ,CACP,uFAAuF,CACxF;IACH,QAAQ,EAAE,cAAc;CACzB,CAAC;KACD,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,IAAI,IAAI,CAAC,UAAU,CAAC,EAAE;IACrD,OAAO,EAAE,+DAA+D;IACxE,IAAI,EAAE,CAAC,YAAY,EAAE,YAAY,CAAC;CACnC,CAAC,CAAC;AAEL,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC;KACtC,KAAK,CAAC,CAAC,cAAc,EAAE,wBAAwB,CAAC,CAAC;KACjD,SAAS,CAAC,MAAM,CAAC,EAAE,CAClB,OAAO,MAAM,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC;IACjD,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE;IACtB,CAAC,CAAC,MAAM,CACX,CAAC"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
export const PLUGIN_SLUG = 'jsdocs';
|
|
2
|
+
export const AUDITS_MAP = {
|
|
3
|
+
'classes-coverage': {
|
|
4
|
+
slug: 'classes-coverage',
|
|
5
|
+
title: 'Classes coverage',
|
|
6
|
+
description: 'Documentation coverage of classes',
|
|
7
|
+
},
|
|
8
|
+
'methods-coverage': {
|
|
9
|
+
slug: 'methods-coverage',
|
|
10
|
+
title: 'Methods coverage',
|
|
11
|
+
description: 'Documentation coverage of methods',
|
|
12
|
+
},
|
|
13
|
+
'functions-coverage': {
|
|
14
|
+
slug: 'functions-coverage',
|
|
15
|
+
title: 'Functions coverage',
|
|
16
|
+
description: 'Documentation coverage of functions',
|
|
17
|
+
},
|
|
18
|
+
'interfaces-coverage': {
|
|
19
|
+
slug: 'interfaces-coverage',
|
|
20
|
+
title: 'Interfaces coverage',
|
|
21
|
+
description: 'Documentation coverage of interfaces',
|
|
22
|
+
},
|
|
23
|
+
'variables-coverage': {
|
|
24
|
+
slug: 'variables-coverage',
|
|
25
|
+
title: 'Variables coverage',
|
|
26
|
+
description: 'Documentation coverage of variables',
|
|
27
|
+
},
|
|
28
|
+
'properties-coverage': {
|
|
29
|
+
slug: 'properties-coverage',
|
|
30
|
+
title: 'Properties coverage',
|
|
31
|
+
description: 'Documentation coverage of properties',
|
|
32
|
+
},
|
|
33
|
+
'types-coverage': {
|
|
34
|
+
slug: 'types-coverage',
|
|
35
|
+
title: 'Types coverage',
|
|
36
|
+
description: 'Documentation coverage of types',
|
|
37
|
+
},
|
|
38
|
+
'enums-coverage': {
|
|
39
|
+
slug: 'enums-coverage',
|
|
40
|
+
title: 'Enums coverage',
|
|
41
|
+
description: 'Documentation coverage of enums',
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
export const groups = [
|
|
45
|
+
{
|
|
46
|
+
slug: 'documentation-coverage',
|
|
47
|
+
title: 'Documentation coverage',
|
|
48
|
+
description: 'Documentation coverage',
|
|
49
|
+
refs: Object.keys(AUDITS_MAP).map(slug => ({
|
|
50
|
+
slug,
|
|
51
|
+
weight: [
|
|
52
|
+
'classes-coverage',
|
|
53
|
+
'functions-coverage',
|
|
54
|
+
'methods-coverage',
|
|
55
|
+
].includes(slug)
|
|
56
|
+
? 2
|
|
57
|
+
: 1,
|
|
58
|
+
})),
|
|
59
|
+
},
|
|
60
|
+
];
|
|
61
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../../packages/plugin-jsdocs/src/lib/constants.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,MAAM,WAAW,GAAG,QAAQ,CAAC;AAEpC,MAAM,CAAC,MAAM,UAAU,GAA6B;IAClD,kBAAkB,EAAE;QAClB,IAAI,EAAE,kBAAkB;QACxB,KAAK,EAAE,kBAAkB;QACzB,WAAW,EAAE,mCAAmC;K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ig } from '@code-pushup/models';
|
|
2
|
+
import { type JsDocsPluginConfig } from './config.js';
|
|
3
|
+
export declare const PLUGIN_TITLE = "JSDoc coverage";
|
|
4
|
+
export declare const PLUGIN_DESCRIPTION = "Official Code PushUp JSDoc coverage plugin.";
|
|
5
|
+
export declare const PLUGIN_DOCS_URL = "https://www.npmjs.com/package/@code-pushup/jsdocs-plugin/";
|
|
6
|
+
/**
|
|
7
|
+
* Instantiates Code PushUp documentation coverage plugin for core config.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* import jsDocsPlugin from '@code-pushup/jsdocs-plugin'
|
|
11
|
+
*
|
|
12
|
+
* export default {
|
|
13
|
+
* // ... core config ...
|
|
14
|
+
* plugins: [
|
|
15
|
+
* // ... other plugins ...
|
|
16
|
+
* jsDocsPlugin(['**/*.ts'])
|
|
17
|
+
* ]
|
|
18
|
+
* }
|
|
19
|
+
*
|
|
20
|
+
* @returns Plugin configuration.
|
|
21
|
+
*/
|
|
22
|
+
export declare function jsDocsPlugin(config: JsDocsPluginConfig): PluginConfig;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { jsDocsPluginConfigSchema } from './config.js';
|
|
2
|
+
import { PLUGIN_SLUG, groups } from './constants.js';
|
|
3
|
+
import { createRunnerFunction } from './runner/runner.js';
|
|
4
|
+
import { filterAuditsByPluginConfig, filterGroupsByOnlyAudits, } from './utils.js';
|
|
5
|
+
export const PLUGIN_TITLE = 'JSDoc coverage';
|
|
6
|
+
export const PLUGIN_DESCRIPTION = 'Official Code PushUp JSDoc coverage plugin.';
|
|
7
|
+
export const PLUGIN_DOCS_URL = 'https://www.npmjs.com/package/@code-pushup/jsdocs-plugin/';
|
|
8
|
+
/**
|
|
9
|
+
* Instantiates Code PushUp documentation coverage plugin for core config.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* import jsDocsPlugin from '@code-pushup/jsdocs-plugin'
|
|
13
|
+
*
|
|
14
|
+
* export default {
|
|
15
|
+
* // ... core config ...
|
|
16
|
+
* plugins: [
|
|
17
|
+
* // ... other plugins ...
|
|
18
|
+
* jsDocsPlugin(['**/*.ts'])
|
|
19
|
+
* ]
|
|
20
|
+
* }
|
|
21
|
+
*
|
|
22
|
+
* @returns Plugin configuration.
|
|
23
|
+
*/
|
|
24
|
+
export function jsDocsPlugin(config) {
|
|
25
|
+
const jsDocsConfig = jsDocsPluginConfigSchema.parse(config);
|
|
26
|
+
return {
|
|
27
|
+
slug: PLUGIN_SLUG,
|
|
28
|
+
title: PLUGIN_TITLE,
|
|
29
|
+
icon: 'folder-docs',
|
|
30
|
+
description: PLUGIN_DESCRIPTION,
|
|
31
|
+
docsUrl: PLUGIN_DOCS_URL,
|
|
32
|
+
groups: filterGroupsByOnlyAudits(groups, jsDocsConfig),
|
|
33
|
+
audits: filterAuditsByPluginConfig(jsDocsConfig),
|
|
34
|
+
runner: createRunnerFunction(jsDocsConfig),
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=jsdocs-plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsdocs-plugin.js","sourceRoot":"","sources":["../../../../../packages/plugin-jsdocs/src/lib/jsdocs-plugin.ts"],"names":[],"mappings":"AACA,OAAO,EAA2B,wBAAwB,EAAE,MAAM,aAAa,CAAC;AAChF,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EACL,0BAA0B,EAC1B,wBAAwB,GACzB,MAAM,YAAY,CAAC;AAEpB,MAAM,CAAC,MAAM,YAAY,GAAG,gBAAgB,CAAC;AAE7C,MAAM,CAAC,MAAM,kBAAkB,GAAG,6CAA6C,CAAC;AAEhF,MAAM,CAAC,MAAM,eAAe,GAC1B,2DAA2D,CAAC;AAE9D;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,YAAY,CAAC,MAA0B;IACrD,MAAM,YAAY,GAAG,wBAAwB,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IAE5D,OAAO;QACL,IAAI,EAAE,WAAW;QACjB,KAAK,EAAE,YAAY;QACnB,IAAI,EAAE,aAAa;QACnB,WAAW,EAAE,kBAAkB;QAC/B,OAAO,EAAE,eAAe;QACxB,MAAM,EAAE,wBAAwB,CAAC,MAAM,EAAE,YAAY,CAAC;QACtD,MAAM,EAAE,0BAA0B,CAAC,YAAY,CAAC;QAChD,MAAM,EAAE,oBAAoB,CAAC,YAAY,CAAC;KAC3C,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"models.js","sourceRoot":"","sources":["../../../../../packages/plugin-jsdocs/src/lib/models.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { SyntaxKind } from 'ts-morph';
|
|
2
|
+
/** Maps the SyntaxKind from the library ts-morph to the coverage type. */
|
|
3
|
+
export const SYNTAX_COVERAGE_MAP = new Map([
|
|
4
|
+
[SyntaxKind.ClassDeclaration, 'classes'],
|
|
5
|
+
[SyntaxKind.MethodDeclaration, 'methods'],
|
|
6
|
+
[SyntaxKind.FunctionDeclaration, 'functions'],
|
|
7
|
+
[SyntaxKind.InterfaceDeclaration, 'interfaces'],
|
|
8
|
+
[SyntaxKind.EnumDeclaration, 'enums'],
|
|
9
|
+
[SyntaxKind.VariableDeclaration, 'variables'],
|
|
10
|
+
[SyntaxKind.VariableStatement, 'variables'],
|
|
11
|
+
[SyntaxKind.PropertyDeclaration, 'properties'],
|
|
12
|
+
[SyntaxKind.TypeAliasDeclaration, 'types'],
|
|
13
|
+
]);
|
|
14
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../../../packages/plugin-jsdocs/src/lib/runner/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAGtC,0EAA0E;AAC1E,MAAM,CAAC,MAAM,mBAAmB,GAAG,IAAI,GAAG,CAA2B;IACnE,CAAC,UAAU,CAAC,gBAAgB,EAAE,SAAS,CAAC;IACxC,CAAC,UAAU,CAAC,iBAAiB,EAAE,SAAS,CAAC;IACzC,CAAC,UAAU,CAAC,mBAAmB,EAAE,WAAW,CAAC;IAC7C,CAAC,UAAU,CAAC,oBAAoB,EAAE,YAAY,CAAC;IAC/C,CAAC,UAAU,CAAC,eAAe,EAAE,OAAO,CAAC;IACrC,CAAC,UAAU,CAAC,mBAAmB,EAAE,WAAW,CAAC;IAC7C,CAAC,UAAU,CAAC,iBAAiB,EAAE,WAAW,CAAC;IAC3C,CAAC,UAAU,CAAC,mBAAmB,EAAE,YAAY,CAAC;IAC9C,CAAC,UAAU,CAAC,oBAAoB,EAAE,OAAO,CAAC;CAC3C,CAAC,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { ClassDeclaration, JSDoc, SourceFile, SyntaxKind, VariableStatement } from 'ts-morph';
|
|
2
|
+
import type { JsDocsPluginTransformedConfig } from '../config.js';
|
|
3
|
+
import type { DocumentationCoverageReport, DocumentationReport } from './models.js';
|
|
4
|
+
/**
|
|
5
|
+
* Gets the variables information from the variable statements
|
|
6
|
+
* @param variableStatements - The variable statements to process
|
|
7
|
+
* @returns The variables information with the right methods to get the information
|
|
8
|
+
*/
|
|
9
|
+
export declare function getVariablesInformation(variableStatements: VariableStatement[]): {
|
|
10
|
+
getName: () => string;
|
|
11
|
+
getKind: () => SyntaxKind;
|
|
12
|
+
getJsDocs: () => JSDoc[];
|
|
13
|
+
getStartLineNumber: () => number;
|
|
14
|
+
}[];
|
|
15
|
+
/**
|
|
16
|
+
* Processes documentation coverage for TypeScript files in the specified path
|
|
17
|
+
* @param config - The configuration object containing patterns to include for documentation analysis
|
|
18
|
+
* @returns Object containing coverage statistics and undocumented items
|
|
19
|
+
*/
|
|
20
|
+
export declare function processJsDocs(config: JsDocsPluginTransformedConfig): DocumentationCoverageReport;
|
|
21
|
+
export declare function getAllNodesFromASourceFile(sourceFile: SourceFile): ({
|
|
22
|
+
getName: () => string;
|
|
23
|
+
getKind: () => SyntaxKind;
|
|
24
|
+
getJsDocs: () => JSDoc[];
|
|
25
|
+
getStartLineNumber: () => number;
|
|
26
|
+
} | ClassDeclaration | import("ts-morph").FunctionDeclaration | import("ts-morph").MethodDeclaration | import("ts-morph").PropertyDeclaration | import("ts-morph").TypeAliasDeclaration | import("ts-morph").EnumDeclaration | import("ts-morph").InterfaceDeclaration)[];
|
|
27
|
+
/**
|
|
28
|
+
* Gets the documentation coverage report from the source files
|
|
29
|
+
* @param sourceFiles - The source files to process
|
|
30
|
+
* @returns The documentation coverage report
|
|
31
|
+
*/
|
|
32
|
+
export declare function getDocumentationReport(sourceFiles: SourceFile[]): DocumentationCoverageReport;
|
|
33
|
+
/**
|
|
34
|
+
* Merges two documentation results
|
|
35
|
+
* @param accumulatedReport - The first empty documentation result
|
|
36
|
+
* @param currentFileReport - The second documentation result
|
|
37
|
+
* @returns The merged documentation result
|
|
38
|
+
*/
|
|
39
|
+
export declare function mergeDocumentationReports(accumulatedReport: DocumentationReport, currentFileReport: Partial<DocumentationReport>): DocumentationReport;
|
|
40
|
+
/**
|
|
41
|
+
* Gets the nodes from a class
|
|
42
|
+
* @param classNodes - The class nodes to process
|
|
43
|
+
* @returns The nodes from the class
|
|
44
|
+
*/
|
|
45
|
+
export declare function getClassNodes(classNodes: ClassDeclaration[]): (import("ts-morph").MethodDeclaration | import("ts-morph").PropertyDeclaration)[];
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { ClassDeclaration, JSDoc, Project, SourceFile, SyntaxKind, VariableStatement, } from 'ts-morph';
|
|
2
|
+
import { objectFromEntries, objectToEntries } from '@code-pushup/utils';
|
|
3
|
+
import { calculateCoverage, createEmptyCoverageData, getCoverageTypeFromKind, } from './utils.js';
|
|
4
|
+
/**
|
|
5
|
+
* Gets the variables information from the variable statements
|
|
6
|
+
* @param variableStatements - The variable statements to process
|
|
7
|
+
* @returns The variables information with the right methods to get the information
|
|
8
|
+
*/
|
|
9
|
+
export function getVariablesInformation(variableStatements) {
|
|
10
|
+
return variableStatements.flatMap(variable => {
|
|
11
|
+
// Get parent-level information
|
|
12
|
+
const parentInfo = {
|
|
13
|
+
getKind: () => variable.getKind(),
|
|
14
|
+
getJsDocs: () => variable.getJsDocs(),
|
|
15
|
+
getStartLineNumber: () => variable.getStartLineNumber(),
|
|
16
|
+
};
|
|
17
|
+
// Map each declaration to combine parent info with declaration-specific info
|
|
18
|
+
return variable.getDeclarations().map(declaration => ({
|
|
19
|
+
...parentInfo,
|
|
20
|
+
getName: () => declaration.getName(),
|
|
21
|
+
}));
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Processes documentation coverage for TypeScript files in the specified path
|
|
26
|
+
* @param config - The configuration object containing patterns to include for documentation analysis
|
|
27
|
+
* @returns Object containing coverage statistics and undocumented items
|
|
28
|
+
*/
|
|
29
|
+
export function processJsDocs(config) {
|
|
30
|
+
const project = new Project();
|
|
31
|
+
project.addSourceFilesAtPaths(config.patterns);
|
|
32
|
+
return getDocumentationReport(project.getSourceFiles());
|
|
33
|
+
}
|
|
34
|
+
export function getAllNodesFromASourceFile(sourceFile) {
|
|
35
|
+
const classes = sourceFile.getClasses();
|
|
36
|
+
return [
|
|
37
|
+
...sourceFile.getFunctions(),
|
|
38
|
+
...classes,
|
|
39
|
+
...getClassNodes(classes),
|
|
40
|
+
...sourceFile.getTypeAliases(),
|
|
41
|
+
...sourceFile.getEnums(),
|
|
42
|
+
...sourceFile.getInterfaces(),
|
|
43
|
+
...getVariablesInformation(sourceFile.getVariableStatements()),
|
|
44
|
+
];
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Gets the documentation coverage report from the source files
|
|
48
|
+
* @param sourceFiles - The source files to process
|
|
49
|
+
* @returns The documentation coverage report
|
|
50
|
+
*/
|
|
51
|
+
export function getDocumentationReport(sourceFiles) {
|
|
52
|
+
const unprocessedCoverageReport = sourceFiles.reduce((coverageReportOfAllFiles, sourceFile) => {
|
|
53
|
+
const filePath = sourceFile.getFilePath();
|
|
54
|
+
const allNodesFromFile = getAllNodesFromASourceFile(sourceFile);
|
|
55
|
+
const coverageReportOfCurrentFile = getCoverageFromAllNodesOfFile(allNodesFromFile, filePath);
|
|
56
|
+
return mergeDocumentationReports(coverageReportOfAllFiles, coverageReportOfCurrentFile);
|
|
57
|
+
}, createEmptyCoverageData());
|
|
58
|
+
return calculateCoverage(unprocessedCoverageReport);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Gets the coverage from all nodes of a file
|
|
62
|
+
* @param nodes - The nodes to process
|
|
63
|
+
* @param filePath - The file path where the nodes are located
|
|
64
|
+
* @returns The coverage report for the nodes
|
|
65
|
+
*/
|
|
66
|
+
function getCoverageFromAllNodesOfFile(nodes, filePath) {
|
|
67
|
+
return nodes.reduce((acc, node) => {
|
|
68
|
+
const nodeType = getCoverageTypeFromKind(node.getKind());
|
|
69
|
+
const currentTypeReport = acc[nodeType];
|
|
70
|
+
const updatedIssues = node.getJsDocs().length === 0
|
|
71
|
+
? [
|
|
72
|
+
...currentTypeReport.issues,
|
|
73
|
+
{
|
|
74
|
+
file: filePath,
|
|
75
|
+
type: nodeType,
|
|
76
|
+
name: node.getName() || '',
|
|
77
|
+
line: node.getStartLineNumber(),
|
|
78
|
+
},
|
|
79
|
+
]
|
|
80
|
+
: currentTypeReport.issues;
|
|
81
|
+
return {
|
|
82
|
+
...acc,
|
|
83
|
+
[nodeType]: {
|
|
84
|
+
nodesCount: currentTypeReport.nodesCount + 1,
|
|
85
|
+
issues: updatedIssues,
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
}, createEmptyCoverageData());
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Merges two documentation results
|
|
92
|
+
* @param accumulatedReport - The first empty documentation result
|
|
93
|
+
* @param currentFileReport - The second documentation result
|
|
94
|
+
* @returns The merged documentation result
|
|
95
|
+
*/
|
|
96
|
+
export function mergeDocumentationReports(accumulatedReport, currentFileReport) {
|
|
97
|
+
return objectFromEntries(objectToEntries(accumulatedReport).map(([key, value]) => {
|
|
98
|
+
const node = value;
|
|
99
|
+
const type = key;
|
|
100
|
+
return [
|
|
101
|
+
type,
|
|
102
|
+
{
|
|
103
|
+
nodesCount: node.nodesCount + (currentFileReport[type]?.nodesCount ?? 0),
|
|
104
|
+
issues: [...node.issues, ...(currentFileReport[type]?.issues ?? [])],
|
|
105
|
+
},
|
|
106
|
+
];
|
|
107
|
+
}));
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Gets the nodes from a class
|
|
111
|
+
* @param classNodes - The class nodes to process
|
|
112
|
+
* @returns The nodes from the class
|
|
113
|
+
*/
|
|
114
|
+
export function getClassNodes(classNodes) {
|
|
115
|
+
return classNodes.flatMap(classNode => [
|
|
116
|
+
...classNode.getMethods(),
|
|
117
|
+
...classNode.getProperties(),
|
|
118
|
+
]);
|
|
119
|
+
}
|
|
120
|
+
//# sourceMappingURL=doc-processor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"doc-processor.js","sourceRoot":"","sources":["../../../../../../packages/plugin-jsdocs/src/lib/runner/doc-processor.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,KAAK,EACL,OAAO,EACP,UAAU,EACV,UAAU,EACV,iBAAiB,GAClB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAMxE,OAAO,EACL,iBAAiB,EACjB,uBAAuB,EACvB,uBAAuB,GACxB,MAAM,YAAY,CAAC;AASpB;;;;GAIG;AACH,MAAM,UAAU,uBAAuB,CACrC,kBAAuC;IAEvC,OAAO,kBAAkB,CAAC,OAAO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;;GAKG;AACH,MAAM,UAAU,yBAAyB,CACvC,iBAAsC,EACtC,iBAA+C;IAE/C,OAAO,iBAAiB,CACtB,eAAe,CAAC,iBAAiB,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;QACtD,MAAM,IAAI,GAAG,KAAK,CAAC;QACnB,MAAM,IAAI,GAAG,GAAG,CAAC;QACjB,OAAO;YACL,IAAI;YACJ;gBACE,UAAU,EACR,IAAI,CAAC,UAAU,GAAG,CAAC,iBAAiB,CAAC,IAAI,CAAC,EAAE,UAAU,IAAI,CAAC,CAAC;gBAC9D,MAAM,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,iBAAiB,CAAC,IAAI,CAAC,EAAE,MAAM,IAAI,EAAE,CAAC,CAAC;aACrE;SACF,CAAC;IACJ,CAAC,CAAC,CACH,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,UAA8B;IAC1D,OAAO,UAAU,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC;QACrC,GAAG,SAAS,CAAC,UAAU,EAAE;QACzB,GAAG,SAAS,CAAC,aAAa,EAAE;KAC7B,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** The possible coverage types for documentation analysis */
|
|
2
|
+
export type CoverageType = 'classes' | 'methods' | 'functions' | 'interfaces' | 'enums' | 'variables' | 'properties' | 'types';
|
|
3
|
+
/** The undocumented node is the node that is not documented and has the information for the report. */
|
|
4
|
+
export type UndocumentedNode = {
|
|
5
|
+
file: string;
|
|
6
|
+
type: CoverageType;
|
|
7
|
+
name: string;
|
|
8
|
+
line: number;
|
|
9
|
+
class?: string;
|
|
10
|
+
};
|
|
11
|
+
/** The documentation data has the issues and the total nodes count from a specific CoverageType. */
|
|
12
|
+
export type DocumentationData = {
|
|
13
|
+
issues: UndocumentedNode[];
|
|
14
|
+
nodesCount: number;
|
|
15
|
+
};
|
|
16
|
+
/** The documentation report has all the documentation data for each coverage type. */
|
|
17
|
+
export type DocumentationReport = Record<CoverageType, DocumentationData>;
|
|
18
|
+
/** The processed documentation result has the documentation data for each coverage type and with coverage stats. */
|
|
19
|
+
export type DocumentationCoverageReport = Record<CoverageType, DocumentationData & {
|
|
20
|
+
coverage: number;
|
|
21
|
+
}>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"models.js","sourceRoot":"","sources":["../../../../../../packages/plugin-jsdocs/src/lib/runner/models.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { AuditOutputs, RunnerFunction } from '@code-pushup/models';
|
|
2
|
+
import type { JsDocsPluginTransformedConfig } from '../config.js';
|
|
3
|
+
import type { DocumentationCoverageReport } from './models.js';
|
|
4
|
+
export declare function createRunnerFunction(config: JsDocsPluginTransformedConfig): RunnerFunction;
|
|
5
|
+
/**
|
|
6
|
+
* Transforms the coverage report into audit outputs.
|
|
7
|
+
* @param coverageResult - The coverage result containing undocumented items and coverage statistics
|
|
8
|
+
* @param options - Configuration options specifying which audits to include and exclude
|
|
9
|
+
* @returns Audit outputs with coverage scores and details about undocumented items
|
|
10
|
+
*/
|
|
11
|
+
export declare function trasformCoverageReportToAuditOutputs(coverageResult: DocumentationCoverageReport, options: Pick<JsDocsPluginTransformedConfig, 'onlyAudits' | 'skipAudits'>): AuditOutputs;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { processJsDocs } from './doc-processor.js';
|
|
2
|
+
import { coverageTypeToAuditSlug } from './utils.js';
|
|
3
|
+
export function createRunnerFunction(config) {
|
|
4
|
+
return () => {
|
|
5
|
+
const coverageResult = processJsDocs(config);
|
|
6
|
+
return trasformCoverageReportToAuditOutputs(coverageResult, config);
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Transforms the coverage report into audit outputs.
|
|
11
|
+
* @param coverageResult - The coverage result containing undocumented items and coverage statistics
|
|
12
|
+
* @param options - Configuration options specifying which audits to include and exclude
|
|
13
|
+
* @returns Audit outputs with coverage scores and details about undocumented items
|
|
14
|
+
*/
|
|
15
|
+
export function trasformCoverageReportToAuditOutputs(coverageResult, options) {
|
|
16
|
+
return Object.entries(coverageResult)
|
|
17
|
+
.filter(([type]) => {
|
|
18
|
+
const auditSlug = coverageTypeToAuditSlug(type);
|
|
19
|
+
if (options.onlyAudits?.length) {
|
|
20
|
+
return options.onlyAudits.includes(auditSlug);
|
|
21
|
+
}
|
|
22
|
+
if (options.skipAudits?.length) {
|
|
23
|
+
return !options.skipAudits.includes(auditSlug);
|
|
24
|
+
}
|
|
25
|
+
return true;
|
|
26
|
+
})
|
|
27
|
+
.map(([type, item]) => {
|
|
28
|
+
const { coverage, issues } = item;
|
|
29
|
+
return {
|
|
30
|
+
slug: `${type}-coverage`,
|
|
31
|
+
value: issues.length,
|
|
32
|
+
score: coverage / 100,
|
|
33
|
+
displayValue: `${issues.length} undocumented ${type}`,
|
|
34
|
+
details: {
|
|
35
|
+
issues: item.issues.map(({ file, line, name }) => ({
|
|
36
|
+
message: `Missing ${type} documentation for ${name}`,
|
|
37
|
+
source: { file, position: { startLine: line } },
|
|
38
|
+
severity: 'warning',
|
|
39
|
+
})),
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=runner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runner.js","sourceRoot":"","sources":["../../../../../../packages/plugin-jsdocs/src/lib/runner/runner.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,OAAO,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AAErD,MAAM,UAAU,oBAAoB,CAClC,MAAqC;IAErC,OAAO,GAAiB,EAAE;QACxB,MAAM,cAAc,GAAG,aAAa,CAAC,MAAM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AAE;oBAC/C,QAAQ,EAAE,SAAS;iBACpB,CAAC,CAAC;aACJ;SACF,CAAC;IACJ,CAAC,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { SyntaxKind } from 'ts-morph';
|
|
2
|
+
import type { CoverageType, DocumentationCoverageReport, DocumentationReport } from './models.js';
|
|
3
|
+
/**
|
|
4
|
+
* Creates an empty unprocessed coverage report.
|
|
5
|
+
* @returns The empty unprocessed coverage report.
|
|
6
|
+
*/
|
|
7
|
+
export declare function createEmptyCoverageData(): DocumentationReport;
|
|
8
|
+
/**
|
|
9
|
+
* Converts the coverage type to the audit slug.
|
|
10
|
+
* @param type - The coverage type.
|
|
11
|
+
* @returns The audit slug.
|
|
12
|
+
*/
|
|
13
|
+
export declare function coverageTypeToAuditSlug(type: CoverageType): string;
|
|
14
|
+
/**
|
|
15
|
+
* Calculates the coverage percentage for each coverage type.
|
|
16
|
+
* @param result - The unprocessed coverage result.
|
|
17
|
+
* @returns The processed coverage result.
|
|
18
|
+
*/
|
|
19
|
+
export declare function calculateCoverage(result: DocumentationReport): DocumentationCoverageReport;
|
|
20
|
+
/**
|
|
21
|
+
* Maps the SyntaxKind from the library ts-morph to the coverage type.
|
|
22
|
+
* @param kind - The SyntaxKind from the library ts-morph.
|
|
23
|
+
* @returns The coverage type.
|
|
24
|
+
*/
|
|
25
|
+
export declare function getCoverageTypeFromKind(kind: SyntaxKind): CoverageType;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { SyntaxKind } from 'ts-morph';
|
|
2
|
+
import { SYNTAX_COVERAGE_MAP } from './constants.js';
|
|
3
|
+
/**
|
|
4
|
+
* Creates an empty unprocessed coverage report.
|
|
5
|
+
* @returns The empty unprocessed coverage report.
|
|
6
|
+
*/
|
|
7
|
+
export function createEmptyCoverageData() {
|
|
8
|
+
return {
|
|
9
|
+
enums: { nodesCount: 0, issues: [] },
|
|
10
|
+
interfaces: { nodesCount: 0, issues: [] },
|
|
11
|
+
types: { nodesCount: 0, issues: [] },
|
|
12
|
+
functions: { nodesCount: 0, issues: [] },
|
|
13
|
+
variables: { nodesCount: 0, issues: [] },
|
|
14
|
+
classes: { nodesCount: 0, issues: [] },
|
|
15
|
+
methods: { nodesCount: 0, issues: [] },
|
|
16
|
+
properties: { nodesCount: 0, issues: [] },
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Converts the coverage type to the audit slug.
|
|
21
|
+
* @param type - The coverage type.
|
|
22
|
+
* @returns The audit slug.
|
|
23
|
+
*/
|
|
24
|
+
export function coverageTypeToAuditSlug(type) {
|
|
25
|
+
return `${type}-coverage`;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Calculates the coverage percentage for each coverage type.
|
|
29
|
+
* @param result - The unprocessed coverage result.
|
|
30
|
+
* @returns The processed coverage result.
|
|
31
|
+
*/
|
|
32
|
+
export function calculateCoverage(result) {
|
|
33
|
+
return Object.fromEntries(Object.entries(result).map(([key, value]) => {
|
|
34
|
+
const type = key;
|
|
35
|
+
return [
|
|
36
|
+
type,
|
|
37
|
+
{
|
|
38
|
+
coverage: value.nodesCount === 0
|
|
39
|
+
? 100
|
|
40
|
+
: Number(((1 - value.issues.length / value.nodesCount) * 100).toFixed(2)),
|
|
41
|
+
issues: value.issues,
|
|
42
|
+
nodesCount: value.nodesCount,
|
|
43
|
+
},
|
|
44
|
+
];
|
|
45
|
+
}));
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Maps the SyntaxKind from the library ts-morph to the coverage type.
|
|
49
|
+
* @param kind - The SyntaxKind from the library ts-morph.
|
|
50
|
+
* @returns The coverage type.
|
|
51
|
+
*/
|
|
52
|
+
export function getCoverageTypeFromKind(kind) {
|
|
53
|
+
const type = SYNTAX_COVERAGE_MAP.get(kind);
|
|
54
|
+
if (!type) {
|
|
55
|
+
throw new Error(`Unsupported syntax kind: ${kind}`);
|
|
56
|
+
}
|
|
57
|
+
return type;
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../../../packages/plugin-jsdocs/src/lib/runner/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAOrD;;;GAGG;AACH,MAAM,UAAU,uBAAuB;IACrC,OAAO;QACL,KAAK,EAAE,EAAE,UAAU,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE;QACpC,UAAU,EAAE,EAAE,UAAU,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE;QACzC,KAAK,EAAE,EAAE,UAAU,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE;QACpC,SAAS,EAAE,EAAE,UAAU,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE;QACxC,SAAS,EAAE,EAAE,UAAU,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE;QACxC,OAAO,EAAE,EAAE,UAAU,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE;QACtC,OAAO,EAAE,EAAE,UAAU,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE;QACtC,UAAU,EAAE,EAAE,UAAU,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE;KAC1C,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,uBAAuB,CAAC,IAAkB;IACxD,OAAO,GAAG,IAAI,WAAW,CAAC;AAC5B,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAAC,MAA2B;IAC3D,OAAO,MAAM,CAAC,WAAW,CACvB,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;QAC1C,MAAM,IAAI,GAAG,GAAmB,CAAC;QACjC,OAAO;YACL,IAAI;YACJ;gBACE,QAAQ,EACN,KAAK,CAAC,UAAU,KAAK,CAAC;oBACpB,CAAC,CAAC,GAAG;oBACL,CAAC,CAAC,MAAM,CACJ,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,MAAM,GAAG,KAAK,CAAC,UAAU,CAAC,GAAG,GAAG,CAAC,CAAC,OAAO,CAC1D,CAAC,CACF,CACF;gBACP,MAAM,EAAE,KAAK,CAAC,MAAM;gBACpB,UAAU,EAAE,KAAK,CAAC,UAAU;aAC7B;SACF,CAAC;IACJ,CAAC,CAAC,CAC4B,CAAC;AACnC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,uBAAuB,CAAC,IAAgB;IACtD,MAAM,IAAI,GAAG,mBAAmB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAE3C,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,MAAM,IAAI,KAAK,CAAC,4BAA4B,IAAI,EAAE,CAAC,CAAC;IACtD,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Audit, Group } from '@code-pushup/models';
|
|
2
|
+
import type { JsDocsPluginTransformedConfig } from './config.js';
|
|
3
|
+
/**
|
|
4
|
+
* Get audits based on the configuration.
|
|
5
|
+
* If no audits are specified, return all audits.
|
|
6
|
+
* If audits are specified, return only the specified audits.
|
|
7
|
+
* @param config - The configuration object.
|
|
8
|
+
* @returns The audits.
|
|
9
|
+
*/
|
|
10
|
+
export declare function filterAuditsByPluginConfig(config: Pick<JsDocsPluginTransformedConfig, 'onlyAudits' | 'skipAudits'>): Audit[];
|
|
11
|
+
/**
|
|
12
|
+
* Filter groups by the audits that are specified in the configuration.
|
|
13
|
+
* The groups refs are filtered to only include the audits that are specified in the configuration.
|
|
14
|
+
* @param groups - The groups to filter.
|
|
15
|
+
* @param options - The configuration object containing either onlyAudits or skipAudits.
|
|
16
|
+
* @returns The filtered groups.
|
|
17
|
+
*/
|
|
18
|
+
export declare function filterGroupsByOnlyAudits(groups: Group[], options: Pick<JsDocsPluginTransformedConfig, 'onlyAudits' | 'skipAudits'>): Group[];
|
package/src/lib/utils.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { AUDITS_MAP } from './constants.js';
|
|
2
|
+
/**
|
|
3
|
+
* Get audits based on the configuration.
|
|
4
|
+
* If no audits are specified, return all audits.
|
|
5
|
+
* If audits are specified, return only the specified audits.
|
|
6
|
+
* @param config - The configuration object.
|
|
7
|
+
* @returns The audits.
|
|
8
|
+
*/
|
|
9
|
+
export function filterAuditsByPluginConfig(config) {
|
|
10
|
+
const { onlyAudits, skipAudits } = config;
|
|
11
|
+
if (onlyAudits && onlyAudits.length > 0) {
|
|
12
|
+
return Object.values(AUDITS_MAP).filter(audit => onlyAudits.includes(audit.slug));
|
|
13
|
+
}
|
|
14
|
+
if (skipAudits && skipAudits.length > 0) {
|
|
15
|
+
return Object.values(AUDITS_MAP).filter(audit => !skipAudits.includes(audit.slug));
|
|
16
|
+
}
|
|
17
|
+
return Object.values(AUDITS_MAP);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Filter groups by the audits that are specified in the configuration.
|
|
21
|
+
* The groups refs are filtered to only include the audits that are specified in the configuration.
|
|
22
|
+
* @param groups - The groups to filter.
|
|
23
|
+
* @param options - The configuration object containing either onlyAudits or skipAudits.
|
|
24
|
+
* @returns The filtered groups.
|
|
25
|
+
*/
|
|
26
|
+
export function filterGroupsByOnlyAudits(groups, options) {
|
|
27
|
+
const audits = filterAuditsByPluginConfig(options);
|
|
28
|
+
return groups
|
|
29
|
+
.map(group => ({
|
|
30
|
+
...group,
|
|
31
|
+
refs: group.refs.filter(ref => audits.some(audit => audit.slug === ref.slug)),
|
|
32
|
+
}))
|
|
33
|
+
.filter(group => group.refs.length > 0);
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../../packages/plugin-jsdocs/src/lib/utils.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C;;;;;;GAMG;AACH,MAAM,UAAU,0BAA0B,CACxC,MAAwE;IAExE,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,GAAG,MAAM,CAAC;IAE1C,IAAI,UAAU,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACxC,OAAO,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAC9C,UAAU,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,CAChC,CAAC;IACJ,CAAC;IAED,IAAI,UAAU,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACxC,OAAO,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,MAAM,CACrC,KAAK,CAAC,EAAE,CAAC,CAAC,UAAU,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,CAC1C,CAAC;IACJ,CAAC;IAED,OAAO,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;AACnC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,wBAAwB,CACtC,MAAe,EACf,OAAyE;IAEzE,MAAM,MAAM,GAAG,0BAA0B,CAAC,OAAO,CAAC,CAAC;IACnD,OAAO,MAAM;SACV,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QACb,GAAG,KAAK;QACR,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAC5B,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,IAAI,CAAC,CAC9C;KAC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