Skip to content

Commit c386373

Browse files
committed
chore(plugin-doc-coverage): wip request in pr
1 parent 4700bea commit c386373

File tree

13 files changed

+280
-227
lines changed

13 files changed

+280
-227
lines changed

code-pushup.config.ts

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
import 'dotenv/config';
22
import { z } from 'zod';
3-
import {
4-
coverageCoreConfigNx,
5-
docCoverageCoreConfig,
6-
eslintCoreConfigNx,
7-
jsPackagesCoreConfig,
8-
lighthouseCoreConfig,
9-
} from './code-pushup.preset.js';
3+
import { docCoverageCoreConfig } from './code-pushup.preset.js';
104
import type { CoreConfig } from './packages/models/src/index.js';
115
import { mergeConfigs } from './packages/utils/src/index.js';
126

@@ -34,20 +28,18 @@ const config: CoreConfig = {
3428

3529
export default mergeConfigs(
3630
config,
37-
await coverageCoreConfigNx(),
38-
await jsPackagesCoreConfig(),
39-
await lighthouseCoreConfig(
40-
'https://github.com/code-pushup/cli?tab=readme-ov-file#code-pushup-cli/',
41-
),
42-
await eslintCoreConfigNx(),
43-
await docCoverageCoreConfig({
44-
sourceGlob: [
45-
'packages/**/src/**/*.ts',
46-
'!packages/**/node_modules',
47-
'!packages/**/{mocks,mock}',
48-
'!**/*.{spec,test}.ts',
49-
'!**/implementation/**',
50-
'!**/internal/**',
51-
],
52-
}),
31+
// await coverageCoreConfigNx(),
32+
// await jsPackagesCoreConfig(),
33+
// await lighthouseCoreConfig(
34+
// 'https://github.com/code-pushup/cli?tab=readme-ov-file#code-pushup-cli/',
35+
// ),
36+
// await eslintCoreConfigNx(),
37+
docCoverageCoreConfig([
38+
'packages/**/src/**/*.ts',
39+
'!packages/**/node_modules',
40+
'!packages/**/{mocks,mock}',
41+
'!**/*.{spec,test}.ts',
42+
'!**/implementation/**',
43+
'!**/internal/**',
44+
]),
5345
);

code-pushup.preset.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ export function getDocCoverageCategories(
9595
): CategoryConfig[] {
9696
return [
9797
{
98-
slug: 'docs',
99-
title: 'Documentation',
98+
slug: 'docs',
99+
title: 'Documentation',
100100
description: 'Measures how much of your code is **documented**.',
101101
refs: filterGroupsByOnlyAudits(groups, config).map(group => ({
102102
weight: 1,
@@ -141,11 +141,15 @@ export const lighthouseCoreConfig = async (
141141
};
142142

143143
export const docCoverageCoreConfig = (
144-
config: DocCoveragePluginConfig,
144+
config: DocCoveragePluginConfig | string[],
145145
): CoreConfig => {
146146
return {
147-
plugins: [docCoveragePlugin(config)],
148-
categories: getDocCoverageCategories(config),
147+
plugins: [
148+
docCoveragePlugin(Array.isArray(config) ? { patterns: config } : config),
149+
],
150+
categories: getDocCoverageCategories(
151+
Array.isArray(config) ? { patterns: config } : config,
152+
),
149153
};
150154
};
151155

packages/plugin-doc-coverage/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Measured documentation types are mapped to Code PushUp audits in the following w
4545
plugins: [
4646
// ...
4747
docCoveragePlugin({
48-
sourceGlob: ['**/*.ts'],
48+
patterns: ['**/*.ts'],
4949
}),
5050
],
5151
};
@@ -100,13 +100,13 @@ These audits are grouped together to provide a comprehensive view of your codeba
100100

101101
The plugin accepts the following parameters:
102102

103-
#### SourceGlob
103+
#### patterns
104104

105-
Required parameter. The `sourceGlob` 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:
105+
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:
106106

107107
```js
108108
docCoveragePlugin({
109-
sourceGlob: [
109+
patterns: [
110110
'src/**/*.ts', // include all TypeScript files in src
111111
'!src/**/*.{spec,test}.ts', // exclude test files
112112
'!src/**/testing/**/*.ts' // exclude testing utilities
@@ -120,7 +120,7 @@ Optional parameter. The `onlyAudits` option allows you to specify which document
120120

121121
```js
122122
docCoveragePlugin({
123-
sourceGlob: ['src/**/*.ts'],
123+
patterns: ['src/**/*.ts'],
124124
onlyAudits: [
125125
'classes-coverage',
126126
'functions-coverage'
@@ -134,7 +134,7 @@ Optional parameter. The `skipAudits` option allows you to exclude specific docum
134134

135135
```js
136136
docCoveragePlugin({
137-
sourceGlob: ['src/**/*.ts'],
137+
patterns: ['src/**/*.ts'],
138138
skipAudits: [
139139
'variables-coverage',
140140
'interfaces-coverage'

packages/plugin-doc-coverage/src/lib/config.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import { z } from 'zod';
22

3-
export const docCoveragePluginConfigSchema = z
3+
const patternsSchema = z.union([z.string(), z.array(z.string()).min(1)], {
4+
description: 'Glob pattern to match source files to evaluate.',
5+
});
6+
7+
const docCoverageTargetObjectSchema = z
48
.object({
59
skipAudits: z
610
.array(z.string())
@@ -14,16 +18,21 @@ export const docCoveragePluginConfigSchema = z
1418
.describe(
1519
'List of audit slugs to evaluate. When specified, only these audits will be evaluated.',
1620
),
17-
sourceGlob: z
18-
.array(z.string())
19-
.default(['src/**/*.{ts,tsx}', '!**/*.spec.ts', '!**/*.test.ts'])
20-
.describe('Glob pattern to match source files to evaluate.'),
21+
patterns: patternsSchema,
2122
})
2223
.refine(data => !(data.skipAudits && data.onlyAudits), {
2324
message: "You can't define 'skipAudits' and 'onlyAudits' simultaneously",
2425
path: ['skipAudits', 'onlyAudits'],
2526
});
2627

28+
export const docCoveragePluginConfigSchema = z
29+
.union([patternsSchema, docCoverageTargetObjectSchema])
30+
.transform(target =>
31+
typeof target === 'string' || Array.isArray(target)
32+
? { patterns: target }
33+
: target,
34+
);
35+
2736
export type DocCoveragePluginConfig = z.infer<
2837
typeof docCoveragePluginConfigSchema
2938
>;

packages/plugin-doc-coverage/src/lib/config.unit.test.ts

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ describe('DocCoveragePlugin Configuration', () => {
99
it('accepts a valid configuration', () => {
1010
expect(() =>
1111
docCoveragePluginConfigSchema.parse({
12-
sourceGlob: ['src/**/*.ts'],
12+
patterns: ['src/**/*.ts'],
1313
onlyAudits: ['functions-coverage'],
1414
} satisfies DocCoveragePluginConfig),
1515
).not.toThrow();
@@ -18,6 +18,7 @@ describe('DocCoveragePlugin Configuration', () => {
1818
it('throws when skipAudits and onlyAudits are defined', () => {
1919
expect(() =>
2020
docCoveragePluginConfigSchema.parse({
21+
patterns: ['src/**/*.ts'],
2122
skipAudits: ['functions-coverage'],
2223
onlyAudits: ['classes-coverage'],
2324
}),
@@ -27,28 +28,29 @@ describe('DocCoveragePlugin Configuration', () => {
2728
});
2829
});
2930

30-
describe('sourceGlob', () => {
31-
it('accepts a valid source glob pattern', () => {
31+
describe('patterns', () => {
32+
it('accepts a valid patterns array', () => {
3233
expect(() =>
3334
docCoveragePluginConfigSchema.parse({
34-
sourceGlob: ['src/**/*.{ts,tsx}', '!**/*.spec.ts', '!**/*.test.ts'],
35+
patterns: ['src/**/*.{ts,tsx}', '!**/*.spec.ts', '!**/*.test.ts'],
3536
} satisfies DocCoveragePluginConfig),
3637
).not.toThrow();
3738
});
3839

39-
it('uses default value for missing sourceGlob', () => {
40-
const result = docCoveragePluginConfigSchema.parse({});
41-
expect(result.sourceGlob).toEqual([
42-
'src/**/*.{ts,tsx}',
43-
'!**/*.spec.ts',
44-
'!**/*.test.ts',
45-
]);
40+
it('accepts a valid patterns array directly', () => {
41+
expect(() =>
42+
docCoveragePluginConfigSchema.parse([
43+
'src/**/*.{ts,tsx}',
44+
'!**/*.spec.ts',
45+
'!**/*.test.ts',
46+
]),
47+
).not.toThrow();
4648
});
4749

48-
it('throws for invalid sourceGlob type', () => {
50+
it('throws for invalid patterns type', () => {
4951
expect(() =>
5052
docCoveragePluginConfigSchema.parse({
51-
sourceGlob: 123,
53+
patterns: 123,
5254
}),
5355
).toThrow('Expected array');
5456
});
@@ -59,7 +61,7 @@ describe('DocCoveragePlugin Configuration', () => {
5961
expect(() =>
6062
docCoveragePluginConfigSchema.parse({
6163
onlyAudits: ['functions-coverage', 'classes-coverage'],
62-
sourceGlob: ['src/**/*.ts'],
64+
patterns: ['src/**/*.ts'],
6365
}),
6466
).not.toThrow();
6567
});
@@ -68,20 +70,23 @@ describe('DocCoveragePlugin Configuration', () => {
6870
expect(() =>
6971
docCoveragePluginConfigSchema.parse({
7072
onlyAudits: [],
71-
sourceGlob: ['src/**/*.ts'],
73+
patterns: ['src/**/*.ts'],
7274
}),
7375
).not.toThrow();
7476
});
7577

7678
it('allows onlyAudits to be undefined', () => {
77-
const result = docCoveragePluginConfigSchema.parse({});
79+
const result = docCoveragePluginConfigSchema.parse({
80+
patterns: ['src/**/*.ts'],
81+
});
7882
expect(result.onlyAudits).toBeUndefined();
7983
});
8084

8185
it('throws for invalid onlyAudits type', () => {
8286
expect(() =>
8387
docCoveragePluginConfigSchema.parse({
8488
onlyAudits: 'functions-coverage',
89+
patterns: ['src/**/*.ts'],
8590
}),
8691
).toThrow('Expected array');
8792
});
@@ -90,6 +95,7 @@ describe('DocCoveragePlugin Configuration', () => {
9095
expect(() =>
9196
docCoveragePluginConfigSchema.parse({
9297
onlyAudits: [123, true],
98+
patterns: ['src/**/*.ts'],
9399
}),
94100
).toThrow('Expected string, received number');
95101
});
@@ -100,7 +106,7 @@ describe('DocCoveragePlugin Configuration', () => {
100106
expect(() =>
101107
docCoveragePluginConfigSchema.parse({
102108
skipAudits: ['functions-coverage', 'classes-coverage'],
103-
sourceGlob: ['src/**/*.ts'],
109+
patterns: ['src/**/*.ts'],
104110
}),
105111
).not.toThrow();
106112
});
@@ -109,20 +115,23 @@ describe('DocCoveragePlugin Configuration', () => {
109115
expect(() =>
110116
docCoveragePluginConfigSchema.parse({
111117
skipAudits: [],
112-
sourceGlob: ['src/**/*.ts'],
118+
patterns: ['src/**/*.ts'],
113119
}),
114120
).not.toThrow();
115121
});
116122

117123
it('allows skipAudits to be undefined', () => {
118-
const result = docCoveragePluginConfigSchema.parse({});
124+
const result = docCoveragePluginConfigSchema.parse({
125+
patterns: ['src/**/*.ts'],
126+
});
119127
expect(result.skipAudits).toBeUndefined();
120128
});
121129

122130
it('throws for invalid skipAudits type', () => {
123131
expect(() =>
124132
docCoveragePluginConfigSchema.parse({
125133
skipAudits: 'functions-coverage',
134+
patterns: ['src/**/*.ts'],
126135
}),
127136
).toThrow('Expected array');
128137
});
@@ -131,6 +140,7 @@ describe('DocCoveragePlugin Configuration', () => {
131140
expect(() =>
132141
docCoveragePluginConfigSchema.parse({
133142
skipAudits: [123, true],
143+
patterns: ['src/**/*.ts'],
134144
}),
135145
).toThrow('Expected string');
136146
});

packages/plugin-doc-coverage/src/lib/doc-coverage-plugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export const PLUGIN_DOCS_URL =
2929
* plugins: [
3030
* // ... other plugins ...
3131
* docCoveragePlugin({
32-
* sourceGlob: ['src&#47;**&#47;*.{ts,tsx}']
32+
* patterns: ['src&#47;**&#47;*.{ts,tsx}']
3333
* })
3434
* ]
3535
* }

packages/plugin-doc-coverage/src/lib/doc-coverage-plugin.unit.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ describe('docCoveragePlugin', () => {
2525
it('should create a valid plugin config', () => {
2626
expect(
2727
docCoveragePlugin({
28-
sourceGlob: ['src/**/*.ts', '!**/*.spec.ts', '!**/*.test.ts'],
28+
patterns: ['src/**/*.ts', '!**/*.spec.ts', '!**/*.test.ts'],
2929
}),
3030
).toStrictEqual(
3131
expect.objectContaining({
3232
slug: PLUGIN_SLUG,
3333
title: PLUGIN_TITLE,
34-
icon: 'folder-src',
34+
icon: 'folder-docs',
3535
description: PLUGIN_DESCRIPTION,
3636
docsUrl: PLUGIN_DOCS_URL,
3737
groups: expect.any(Array),
@@ -45,27 +45,27 @@ describe('docCoveragePlugin', () => {
4545
expect(() =>
4646
docCoveragePlugin({
4747
// @ts-expect-error testing invalid config
48-
sourceGlob: 123,
48+
patterns: 123,
4949
}),
5050
).toThrow('Expected array, received number');
5151
});
5252

5353
it('should filter groups', () => {
54-
const config = { sourceGlob: ['src/**/*.ts'] };
54+
const config = { patterns: ['src/**/*.ts'] };
5555
docCoveragePlugin(config);
5656

5757
expect(filterGroupsByOnlyAudits).toHaveBeenCalledWith(groups, config);
5858
});
5959

6060
it('should filter audits', async () => {
61-
const config = { sourceGlob: ['src/**/*.ts'] };
61+
const config = { patterns: ['src/**/*.ts'] };
6262
docCoveragePlugin(config);
6363

6464
expect(filterAuditsByPluginConfig).toHaveBeenCalledWith(config);
6565
});
6666

6767
it('should forward options to runner function', async () => {
68-
const config = { sourceGlob: ['src/**/*.ts'] };
68+
const config = { patterns: ['src/**/*.ts'] };
6969
docCoveragePlugin(config);
7070

7171
expect(createRunnerFunction).toHaveBeenCalledWith(config);

0 commit comments

Comments
 (0)