Skip to content

Commit 1686dda

Browse files
authored
feat(plugin-jsdocs): add plugin-jsdocs to analyze documentation in ts/js projects (code-pushup#896)
1 parent 053d595 commit 1686dda

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+2991
-0
lines changed

code-pushup.config.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { z } from 'zod';
33
import {
44
coverageCoreConfigNx,
55
eslintCoreConfigNx,
6+
jsDocsCoreConfig,
67
jsPackagesCoreConfig,
78
lighthouseCoreConfig,
89
} from './code-pushup.preset.js';
@@ -39,4 +40,12 @@ export default mergeConfigs(
3940
'https://github.com/code-pushup/cli?tab=readme-ov-file#code-pushup-cli/',
4041
),
4142
await eslintCoreConfigNx(),
43+
jsDocsCoreConfig([
44+
'packages/**/src/**/*.ts',
45+
'!packages/**/node_modules',
46+
'!packages/**/{mocks,mock}',
47+
'!**/*.{spec,test}.ts',
48+
'!**/implementation/**',
49+
'!**/internal/**',
50+
]),
4251
);

code-pushup.preset.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ import eslintPlugin, {
1010
eslintConfigFromNxProject,
1111
} from './packages/plugin-eslint/src/index.js';
1212
import jsPackagesPlugin from './packages/plugin-js-packages/src/index.js';
13+
import jsDocsPlugin, {
14+
JsDocsPluginConfig,
15+
} from './packages/plugin-jsdocs/src/index.js';
16+
import {
17+
PLUGIN_SLUG,
18+
groups,
19+
} from './packages/plugin-jsdocs/src/lib/constants.js';
20+
import { filterGroupsByOnlyAudits } from './packages/plugin-jsdocs/src/lib/utils.js';
1321
import lighthousePlugin, {
1422
lighthouseGroupRef,
1523
} from './packages/plugin-lighthouse/src/index.js';
@@ -82,6 +90,24 @@ export const eslintCategories: CategoryConfig[] = [
8290
},
8391
];
8492

93+
export function getJsDocsCategories(
94+
config: JsDocsPluginConfig,
95+
): CategoryConfig[] {
96+
return [
97+
{
98+
slug: 'docs',
99+
title: 'Documentation',
100+
description: 'Measures how much of your code is **documented**.',
101+
refs: filterGroupsByOnlyAudits(groups, config).map(group => ({
102+
weight: 1,
103+
type: 'group',
104+
plugin: PLUGIN_SLUG,
105+
slug: group.slug,
106+
})),
107+
},
108+
];
109+
}
110+
85111
export const coverageCategories: CategoryConfig[] = [
86112
{
87113
slug: 'code-coverage',
@@ -114,6 +140,19 @@ export const lighthouseCoreConfig = async (
114140
};
115141
};
116142

143+
export const jsDocsCoreConfig = (
144+
config: JsDocsPluginConfig | string[],
145+
): CoreConfig => {
146+
return {
147+
plugins: [
148+
jsDocsPlugin(Array.isArray(config) ? { patterns: config } : config),
149+
],
150+
categories: getJsDocsCategories(
151+
Array.isArray(config) ? { patterns: config } : config,
152+
),
153+
};
154+
};
155+
117156
export const eslintCoreConfigNx = async (
118157
projectName?: string,
119158
): Promise<CoreConfig> => {
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import tseslint from 'typescript-eslint';
2+
import baseConfig from '../../eslint.config.js';
3+
4+
export default tseslint.config(...baseConfig, {
5+
files: ['**/*.ts'],
6+
languageOptions: {
7+
parserOptions: {
8+
projectService: true,
9+
tsconfigRootDir: import.meta.dirname,
10+
},
11+
},
12+
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import jsDocsPlugin from '@code-pushup/jsdocs-plugin';
2+
3+
export default {
4+
plugins: [jsDocsPlugin(['**/*.ts'])],
5+
};
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
h1 {
2+
color: #336699;
3+
text-align: center;
4+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<h1>{{ title }}</h1>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
function notRealisticFunction() {
2+
return 'notRealisticFunction';
3+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* Basic Angular component that displays a welcome message
3+
*/
4+
export class AppComponent {
5+
protected readonly title = 'My Angular App';
6+
7+
/**
8+
* Dummy method that returns a welcome message
9+
* @returns {string} - The welcome message
10+
*/
11+
getWelcomeMessage() {
12+
return 'Welcome to My Angular App!';
13+
}
14+
15+
sendEvent() {
16+
return 'Event sent';
17+
}
18+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export const someVariable = 'Hello World 1';
2+
3+
export function mapEventToCustomEvent(event: string) {
4+
return event;
5+
}
6+
7+
/** Commented */
8+
export function mapCustomEventToEvent(event: string) {
9+
return event;
10+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import jsDocsPlugin from '@code-pushup/jsdocs-plugin';
2+
3+
export default {
4+
plugins: [jsDocsPlugin(['**/*.ts'])],
5+
};

0 commit comments

Comments
 (0)