export function compareLintDiffViolations()

in eng/tools/lint-diff/src/generateReport.ts [165:196]


export function compareLintDiffViolations(a: LintDiffViolation, b: LintDiffViolation): number {
  // Sort by level
  if (isFailure(a.level) && isWarning(b.level)) {
    return -1;
  } else if (isWarning(a.level) && isFailure(b.level)) {
    return 1;
  } else if (a.level === "fatal" && b.level !== "fatal") {
    return -1;
  } else if (a.level !== "fatal" && b.level === "fatal") {
    return 1;
  }

  const fileA = getFile(a) || "";
  const fileB = getFile(b) || "";

  // Sort by file name
  if (fileA !== fileB) {
    return fileA.localeCompare(fileB);
  }

  // Sort by line number
  const lineA = getLine(a) || 0;
  const lineB = getLine(b) || 0;

  if (lineA < lineB) {
    return -1;
  } else if (lineA > lineB) {
    return 1;
  }

  return 0;
}