Skip to content

Commit 4c96419

Browse files
authored
feat: implement scoreTargets configuration for all plugins (#1099)
Closes #713 closes #721 This PR finalizes `scoreTarget`/`scoreTargets` feature implementation, allowing users to configure threshold values for audits across all plugins. ## Changes - Replace `perfectScoreThreshold` with `scoreTargets` in the coverage plugin - Add `scoreTargets` support to all plugins: ESLint, Lighthouse, JS Packages, TypeScript, and JSDoc - Add tests demonstrating score impact ## Breaking change Coverage plugin: `perfectScoreThreshold` → `scoreTargets` ## Usage ```typescript // Single target for all audits export default { // ... core config ... plugins: [ // ... other plugins ... await coveragePlugin({ reports: ['coverage/lcov.info'], scoreTargets: 0.8, }) ] } // Per-audit targets export default { // ... core config ... plugins: [ // ... other plugins ... await coveragePlugin({ reports: ['coverage/lcov.info'], scoreTargets: { 'line-coverage': 0.9, 'branch-coverage': 0.75 }, }) ] } ```
1 parent b05dd6e commit 4c96419

37 files changed

Lines changed: 251 additions & 137 deletions

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"node": ">=22.14"
2323
},
2424
"dependencies": {
25-
"@code-pushup/portal-client": "^0.15.0",
25+
"@code-pushup/portal-client": "^0.16.0",
2626
"@isaacs/cliui": "^8.0.2",
2727
"@nx/devkit": "21.4.1",
2828
"@poppinss/cliui": "6.4.1",

packages/ci/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"type": "module",
2828
"dependencies": {
2929
"@code-pushup/models": "0.78.0",
30-
"@code-pushup/portal-client": "^0.15.0",
30+
"@code-pushup/portal-client": "^0.16.0",
3131
"@code-pushup/utils": "0.78.0",
3232
"glob": "^11.0.1",
3333
"simple-git": "^3.20.0",

packages/ci/src/lib/portal/transform.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ function transformGQLCategory(category: CategoryFragment): CategoryConfig {
6262
slug: category.slug,
6363
title: category.title,
6464
...(category.description && { description: category.description }),
65+
...(category.scoreTarget != null && { scoreTarget: category.scoreTarget }),
6566
refs: category.refs.map(
6667
({ target, weight }): CategoryRef => ({
6768
type: lowercase(target.__typename),
@@ -70,9 +71,6 @@ function transformGQLCategory(category: CategoryFragment): CategoryConfig {
7071
weight,
7172
}),
7273
),
73-
// TODO: Portal API migration - convert isBinary to scoreTarget for backward compatibility
74-
// Remove this conversion when Portal API supports scoreTarget (#713)
75-
...(category.isBinary && { scoreTarget: 1 }),
7674
};
7775
}
7876

packages/ci/src/lib/portal/transform.unit.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ describe('transformGQLReport', () => {
2525
{
2626
slug: 'code-style',
2727
title: 'Code style',
28-
isBinary: false,
2928
score: 0.5,
3029
refs: [
3130
{
@@ -41,7 +40,6 @@ describe('transformGQLReport', () => {
4140
{
4241
slug: 'bundle-size',
4342
title: 'Bundle size',
44-
isBinary: false,
4543
score: 0.75,
4644
refs: [
4745
{

packages/core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"ansis": "^3.3.0"
4545
},
4646
"peerDependencies": {
47-
"@code-pushup/portal-client": "^0.15.0"
47+
"@code-pushup/portal-client": "^0.16.0"
4848
},
4949
"peerDependenciesMeta": {
5050
"@code-pushup/portal-client": {

packages/core/src/lib/implementation/report-to-gql.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,7 @@ function categoryToGQL(category: CategoryConfig): PortalCategory {
199199
slug: category.slug,
200200
title: category.title,
201201
description: category.description,
202-
// TODO: Portal API migration - convert scoreTarget to isBinary for backward compatibility
203-
// Remove this conversion when Portal API supports scoreTarget (#713)
204-
isBinary: category.scoreTarget === 1,
202+
...(category.scoreTarget != null && { scoreTarget: category.scoreTarget }),
205203
refs: category.refs.map(ref => ({
206204
plugin: ref.plugin,
207205
type: categoryRefTypeToGQL(ref.type),

packages/models/docs/models-reference.md

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,21 +1290,21 @@ _(\*) Required._
12901290

12911291
_Object containing the following properties:_
12921292

1293-
| Property | Description | Type |
1294-
| :---------------- | :--------------------------------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------- |
1295-
| `packageName` | NPM package name | `string` |
1296-
| `version` | NPM version of the package | `string` |
1297-
| **`title`** (\*) | Descriptive name | `string` (_max length: 256_) |
1298-
| `description` | Description (markdown) | `string` (_max length: 65536_) |
1299-
| `docsUrl` | Plugin documentation site | `string` (_url_) (_optional_) _or_ `''` |
1300-
| `isSkipped` | | `boolean` |
1301-
| **`slug`** (\*) | Unique plugin slug within core config | [Slug](#slug) |
1302-
| **`icon`** (\*) | Icon from VSCode Material Icons extension | [MaterialIcon](#materialicon) |
1303-
| **`runner`** (\*) | | [RunnerConfig](#runnerconfig) _or_ [RunnerFunction](#runnerfunction) |
1304-
| **`audits`** (\*) | List of audits maintained in a plugin | _Array of at least 1 [Audit](#audit) items_ |
1305-
| `groups` | List of groups | _Array of [Group](#group) items_ |
1306-
| `scoreTargets` | Score targets that trigger a perfect score. Number for all audits or record { slug: target } for specific audits | `number` (_≥0, ≤1_) (_optional_) _or_ _Object with dynamic keys of type_ `string` _and values of type_ `number` (_≥0, ≤1_) |
1307-
| `context` | Plugin-specific context data for helpers | [PluginContext](#plugincontext) |
1293+
| Property | Description | Type |
1294+
| :---------------- | :--------------------------------------------------------------------------------------------------------------- | :------------------------------------------------------------------- |
1295+
| `packageName` | NPM package name | `string` |
1296+
| `version` | NPM version of the package | `string` |
1297+
| **`title`** (\*) | Descriptive name | `string` (_max length: 256_) |
1298+
| `description` | Description (markdown) | `string` (_max length: 65536_) |
1299+
| `docsUrl` | Plugin documentation site | `string` (_url_) (_optional_) _or_ `''` |
1300+
| `isSkipped` | | `boolean` |
1301+
| **`slug`** (\*) | Unique plugin slug within core config | [Slug](#slug) |
1302+
| **`icon`** (\*) | Icon from VSCode Material Icons extension | [MaterialIcon](#materialicon) |
1303+
| **`runner`** (\*) | | [RunnerConfig](#runnerconfig) _or_ [RunnerFunction](#runnerfunction) |
1304+
| **`audits`** (\*) | List of audits maintained in a plugin | _Array of at least 1 [Audit](#audit) items_ |
1305+
| `groups` | List of groups | _Array of [Group](#group) items_ |
1306+
| `scoreTargets` | Score targets that trigger a perfect score. Number for all audits or record { slug: target } for specific audits | [PluginScoreTargets](#pluginscoretargets) |
1307+
| `context` | Plugin-specific context data for helpers | [PluginContext](#plugincontext) |
13081308

13091309
_(\*) Required._
13101310

@@ -1356,6 +1356,16 @@ _Object containing the following properties:_
13561356

13571357
_(\*) Required._
13581358

1359+
## PluginScoreTargets
1360+
1361+
Score targets that trigger a perfect score. Number for all audits or record { slug: target } for specific audits
1362+
1363+
_Union of the following possible types:_
1364+
1365+
- `number` (_≥0, ≤1_) (_optional_)
1366+
- _Object with dynamic keys of type_ `string` _and values of type_ `number` (_≥0, ≤1_)
1367+
(_optional_)
1368+
13591369
## Report
13601370

13611371
Collect output data

packages/models/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ export {
8686
pluginConfigSchema,
8787
pluginContextSchema,
8888
pluginMetaSchema,
89+
pluginScoreTargetsSchema,
8990
type PluginConfig,
9091
type PluginContext,
9192
type PluginMeta,

packages/models/src/lib/plugin-config.unit.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ describe('pluginConfigSchema', () => {
4040
).not.toThrow();
4141
});
4242

43-
it('should accept a valid plugin configuration with a score target', () => {
43+
it('should accept a valid plugin configuration with score targets', () => {
4444
expect(() =>
4545
pluginConfigSchema.parse({
4646
slug: 'lighthouse',
@@ -60,7 +60,7 @@ describe('pluginConfigSchema', () => {
6060
displayValue: '180 ms',
6161
},
6262
],
63-
scoreTarget: { 'total-blocking-time': 0.9 },
63+
scoreTargets: { 'total-blocking-time': 0.9 },
6464
audits: [
6565
{ slug: 'first-contentful-paint', title: 'First Contentful Paint' },
6666
{ slug: 'total-blocking-time', title: 'Total Blocking Time' },

0 commit comments

Comments
 (0)