Global Metrics

path: .metrics.halstead.difficulty
old: 35.05434782608695
new: 35.19021739130435

path: .metrics.halstead.purity_ratio
old: 1.1333292795911605
new: 1.1315388699867508

path: .metrics.halstead.effort
old: 152208.4496897271
new: 153040.17454912237

path: .metrics.halstead.N2
old: 258.0
new: 259.0

path: .metrics.halstead.bugs
old: 0.9502500919067892
new: 0.953708632155646

path: .metrics.halstead.level
old: 0.02852713178294574
new: 0.028416988416988413

path: .metrics.halstead.length
old: 632.0
new: 633.0

path: .metrics.halstead.time
old: 8456.024982762618
new: 8502.231919395686

path: .metrics.halstead.volume
old: 4342.070502776712
new: 4348.940867496295

path: .metrics.mi.mi_sei
old: 8.663253856473617
new: 8.651392961967161

path: .metrics.mi.mi_original
old: 30.069312233030946
new: 30.061090887444877

path: .metrics.mi.mi_visual_studio
old: 17.584393118731544
new: 17.579585314295247

Spaces Data

Minimal test - lines (234, 304)

path: .spaces[4].metrics.halstead.length
old: 203.0
new: 204.0

path: .spaces[4].metrics.halstead.bugs
old: 0.2931971697929899
new: 0.2970361533842847

path: .spaces[4].metrics.halstead.level
old: 0.04248366013071895
new: 0.04186795491143318

path: .spaces[4].metrics.halstead.purity_ratio
old: 0.971773806392266
new: 0.967010209302108

path: .spaces[4].metrics.halstead.effort
old: 26086.844098962436
new: 26600.87058367105

path: .spaces[4].metrics.halstead.time
old: 1449.2691166090242
new: 1477.8261435372806

path: .spaces[4].metrics.halstead.difficulty
old: 23.53846153846154
new: 23.884615384615383

path: .spaces[4].metrics.halstead.volume
old: 1108.2646185833714
new: 1113.7240502020086

path: .spaces[4].metrics.halstead.N2
old: 68.0
new: 69.0

path: .spaces[4].metrics.mi.mi_sei
old: 38.244968045286576
new: 38.20810303639772

path: .spaces[4].metrics.mi.mi_original
old: 63.18972253793868
new: 63.16416966096605

path: .spaces[4].metrics.mi.mi_visual_studio
old: 36.953054115753616
new: 36.93811091284565

Code

async function getContrastRatioFor(node, options = {}) {
  const computedStyle = CssLogic.getComputedStyle(node);
  const props = computedStyle ? getTextProperties(computedStyle) : null;

  if (!props) {
    return {
      error: true,
    };
  }

  const { isLargeText, isBoldText, size, opacity } = props;
  const { appliedColorMatrix } = options;
  const color = appliedColorMatrix
    ? getTransformedRGBA(props.color, appliedColorMatrix)
    : props.color;
  let rgba = await getBackgroundFor(node, {
    ...options,
    isBoldText,
    size,
  });

  if (!rgba) {
    // Fallback (original) contrast calculation algorithm. It tries to get the
    // closest background colour for the node and use it to calculate contrast.
    const backgroundColor = InspectorActorUtils.getClosestBackgroundColor(node);
    const backgroundImage = InspectorActorUtils.getClosestBackgroundImage(node);

    if (backgroundImage !== "none") {
      // Both approaches failed, at this point we don't have a better one yet.
      return {
        error: true,
      };
    }

    let { r, g, b, a } = colorUtils.colorToRGBA(backgroundColor, true);
    // If the element has opacity in addition to background alpha value, take it
    // into account. TODO: this does not handle opacity set on ancestor
    // elements (see bug https://bugzilla.mozilla.org/show_bug.cgi?id=1544721).
    if (opacity < 1) {
      a = opacity * a;
    }

    return getContrastRatioAgainstBackground(
      {
        value: appliedColorMatrix
          ? getTransformedRGBA([r, g, b, a], appliedColorMatrix)
          : [r, g, b, a],
      },
      {
        color,
        isLargeText,
      }
    );
  }

  if (appliedColorMatrix) {
    rgba = rgba.value
      ? {
          value: getTransformedRGBA(rgba.value, appliedColorMatrix),
        }
      : {
          min: getTransformedRGBA(rgba.min, appliedColorMatrix),
          max: getTransformedRGBA(rgba.max, appliedColorMatrix),
        };
  }

  return getContrastRatioAgainstBackground(rgba, {
    color,
    isLargeText,
  });
}