@code-pushup/core 0.10.6 → 0.10.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +31 -19
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -1364,24 +1364,6 @@ function deepClone(obj) {
1364
1364
  }
1365
1365
 
1366
1366
  // packages/utils/src/lib/reports/scoring.ts
1367
- function calculateScore(refs, scoreFn) {
1368
- const { numerator, denominator } = refs.reduce(
1369
- (acc, ref) => {
1370
- const score = scoreFn(ref);
1371
- return {
1372
- numerator: acc.numerator + score * ref.weight,
1373
- denominator: acc.denominator + ref.weight
1374
- };
1375
- },
1376
- { numerator: 0, denominator: 0 }
1377
- );
1378
- if (!numerator && !denominator) {
1379
- throw new Error(
1380
- "0 division for score. This can be caused by refs only weighted with 0 or empty refs"
1381
- );
1382
- }
1383
- return numerator / denominator;
1384
- }
1385
1367
  function scoreReport(report) {
1386
1368
  const allScoredAuditsAndGroups = /* @__PURE__ */ new Map();
1387
1369
  const scoredPlugins = report.plugins.map((plugin) => {
@@ -1431,6 +1413,36 @@ function scoreReport(report) {
1431
1413
  categories: scoredCategories
1432
1414
  };
1433
1415
  }
1416
+ function calculateScore(refs, scoreFn) {
1417
+ const validatedRefs = parseScoringParameters(refs, scoreFn);
1418
+ const { numerator, denominator } = validatedRefs.reduce(
1419
+ (acc, ref) => ({
1420
+ numerator: acc.numerator + ref.score * ref.weight,
1421
+ denominator: acc.denominator + ref.weight
1422
+ }),
1423
+ { numerator: 0, denominator: 0 }
1424
+ );
1425
+ return numerator / denominator;
1426
+ }
1427
+ function parseScoringParameters(refs, scoreFn) {
1428
+ if (refs.length === 0) {
1429
+ throw new Error("Reference array cannot be empty.");
1430
+ }
1431
+ if (refs.some((ref) => ref.weight < 0)) {
1432
+ throw new Error("Weight cannot be negative.");
1433
+ }
1434
+ if (refs.every((ref) => ref.weight === 0)) {
1435
+ throw new Error("All references cannot have zero weight.");
1436
+ }
1437
+ const scoredRefs = refs.map((ref) => ({
1438
+ weight: ref.weight,
1439
+ score: scoreFn(ref)
1440
+ }));
1441
+ if (scoredRefs.some((ref) => ref.score < 0 || ref.score > 1)) {
1442
+ throw new Error("All scores must be in range 0-1.");
1443
+ }
1444
+ return scoredRefs;
1445
+ }
1434
1446
 
1435
1447
  // packages/utils/src/lib/reports/sorting.ts
1436
1448
  function sortReport(report) {
@@ -1683,7 +1695,7 @@ function auditOutputsCorrelateWithPluginOutput(auditOutputs, pluginConfigAudits)
1683
1695
 
1684
1696
  // packages/core/package.json
1685
1697
  var name = "@code-pushup/core";
1686
- var version = "0.10.6";
1698
+ var version = "0.10.7";
1687
1699
 
1688
1700
  // packages/core/src/lib/implementation/collect.ts
1689
1701
  async function collect(options) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@code-pushup/core",
3
- "version": "0.10.6",
3
+ "version": "0.10.7",
4
4
  "license": "MIT",
5
5
  "dependencies": {
6
6
  "@code-pushup/models": "*",