Skip to content

Commit b17bdcc

Browse files
committed
refactor: rename scoreTarget to scoreTargets
1 parent 9b185d5 commit b17bdcc

File tree

5 files changed

+15
-15
lines changed

5 files changed

+15
-15
lines changed

packages/core/src/lib/implementation/execute-plugin.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export async function executePlugin(
5858
description,
5959
docsUrl,
6060
groups,
61-
scoreTarget,
61+
scoreTargets,
6262
...pluginMeta
6363
} = pluginConfig;
6464
const { write: cacheWrite = false, read: cacheRead = false } = cache;
@@ -78,9 +78,9 @@ export async function executePlugin(
7878
});
7979
}
8080

81-
// transform audit scores to 1 when they meet/exceed scoreTarget
82-
const scoredAuditsWithTarget = scoreTarget
83-
? scoreAuditsWithTarget(audits, scoreTarget)
81+
// transform audit scores to 1 when they meet/exceed their targets
82+
const scoredAuditsWithTarget = scoreTargets
83+
? scoreAuditsWithTarget(audits, scoreTargets)
8484
: audits;
8585

8686
// enrich `AuditOutputs` to `AuditReport`

packages/models/docs/models-reference.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1297,7 +1297,7 @@ _Object containing the following properties:_
12971297
| **`runner`** (\*) | | [RunnerConfig](#runnerconfig) _or_ [RunnerFunction](#runnerfunction) |
12981298
| **`audits`** (\*) | List of audits maintained in a plugin | _Array of at least 1 [Audit](#audit) items_ |
12991299
| `groups` | List of groups | _Array of [Group](#group) items_ |
1300-
| `scoreTarget` | 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_) |
1300+
| `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_) |
13011301
| `context` | Plugin-specific context data for helpers | [PluginContext](#plugincontext) |
13021302

13031303
_(\*) Required._

packages/models/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export {
8080
type PluginConfig,
8181
type PluginContext,
8282
type PluginMeta,
83-
type PluginScoreTarget,
83+
type PluginScoreTargets,
8484
} from './lib/plugin-config.js';
8585
export {
8686
auditReportSchema,

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export const pluginMetaSchema = packageVersionSchema()
3333
});
3434
export type PluginMeta = z.infer<typeof pluginMetaSchema>;
3535

36-
export const pluginScoreTargetSchema = z
36+
export const pluginScoreTargetsSchema = z
3737
.union([
3838
scoreTargetSchema,
3939
z.record(z.string(), scoreTargetSchema.nonoptional()),
@@ -43,13 +43,13 @@ export const pluginScoreTargetSchema = z
4343
)
4444
.optional();
4545

46-
export type PluginScoreTarget = z.infer<typeof pluginScoreTargetSchema>;
46+
export type PluginScoreTargets = z.infer<typeof pluginScoreTargetsSchema>;
4747

4848
export const pluginDataSchema = z.object({
4949
runner: z.union([runnerConfigSchema, runnerFunctionSchema]),
5050
audits: pluginAuditsSchema,
5151
groups: groupsSchema,
52-
scoreTarget: pluginScoreTargetSchema,
52+
scoreTargets: pluginScoreTargetsSchema,
5353
context: pluginContextSchema,
5454
});
5555

packages/utils/src/lib/reports/scoring.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type {
33
AuditReport,
44
CategoryRef,
55
GroupRef,
6-
PluginScoreTarget,
6+
PluginScoreTargets,
77
Report,
88
} from '@code-pushup/models';
99
import { deepClone } from '../transform.js';
@@ -138,18 +138,18 @@ export function scoreAuditWithTarget(
138138
/**
139139
* Sets audit scores to 1 when targets are met.
140140
* @param audits audit outputs from plugin execution
141-
* @param scoreTarget number or { slug: target } mapping
141+
* @param scoreTargets number or { slug: target } mapping
142142
* @returns Transformed audits with scoreTarget field
143143
*/
144144
export function scoreAuditsWithTarget(
145145
audits: AuditOutput[],
146-
scoreTarget: PluginScoreTarget,
146+
scoreTargets: PluginScoreTargets,
147147
): AuditOutput[] {
148-
if (typeof scoreTarget === 'number') {
149-
return audits.map(audit => scoreAuditWithTarget(audit, scoreTarget));
148+
if (typeof scoreTargets === 'number') {
149+
return audits.map(audit => scoreAuditWithTarget(audit, scoreTargets));
150150
}
151151
return audits.map(audit => {
152-
const target = scoreTarget?.[audit.slug];
152+
const target = scoreTargets?.[audit.slug];
153153
return target == null ? audit : scoreAuditWithTarget(audit, target);
154154
});
155155
}

0 commit comments

Comments
 (0)