MCPcopy Create free account
hub / github.com/code-pushup/cli / parseScoringParameters

Function parseScoringParameters

packages/utils/src/lib/reports/scoring.ts:95–121  ·  view source on GitHub ↗
(
  refs: T[],
  scoreFn: (ref: T) => number,
)

Source from the content-addressed store, hash-verified

93}
94
95function parseScoringParameters<T extends { weight: number }>(
96 refs: T[],
97 scoreFn: (ref: T) => number,
98): { weight: number; score: number }[] {
99 if (refs.length === 0) {
100 throw new Error('Reference array cannot be empty.');
101 }
102
103 if (refs.some(ref => ref.weight < 0)) {
104 throw new Error('Weight cannot be negative.');
105 }
106
107 if (refs.every(ref => ref.weight === 0)) {
108 throw new Error('All references cannot have zero weight.');
109 }
110
111 const scoredRefs = refs.map(ref => ({
112 weight: ref.weight,
113 score: scoreFn(ref),
114 }));
115
116 if (scoredRefs.some(ref => ref.score < 0 || ref.score > 1)) {
117 throw new Error('All scores must be in range 0-1.');
118 }
119
120 return scoredRefs;
121}
122
123/**
124 * Sets audit score to 1 if it meets target.

Callers 1

calculateScoreFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected