export function getViolations()

in eng/tools/lint-diff/src/correlateResults.ts [80:112]


export function getViolations(
  runCorrelations: Map<string, BeforeAfter>,
  affectedSwaggers: Set<string>,
) {
  const newViolations: LintDiffViolation[] = [];
  const existingViolations: LintDiffViolation[] = [];

  for (const [, { before, after }] of runCorrelations.entries()) {
    const beforeViolations = before
      ? getLintDiffViolations(before).filter(
          (v) => (isFailure(v.level) || isWarning(v.level)) && v.source?.length > 0,
        )
      : [];
    const afterViolations = getLintDiffViolations(after).filter(
      (v) =>
        // Fatal errors are always new
        v.level.toLowerCase() === "fatal" ||
        ((isFailure(v.level) || isWarning(v.level)) &&
          v.source?.length > 0 &&
          affectedSwaggers.has(relativizePath(v.source[0].document).slice(1))),
    );

    const [newItems, existingItems] = getNewItems(beforeViolations, afterViolations);
    console.log("Correlation:");
    console.log(`\tBefore: Readme: ${before?.readme} Tag: ${before?.tag}`);
    console.log(`\tAfter: Readme : ${after.readme} Tag: ${after.tag}`);

    newViolations.push(...newItems);
    existingViolations.push(...existingItems);
  }

  return [newViolations, existingViolations];
}