freshnessRatchetViolation function

String? freshnessRatchetViolation(
  1. String project,
  2. BridgeFreshness freshness, {
  3. required bool knownStale,
})

What is wrong with project's freshness under the ratchet, or null.

knownStale says whether the project is on the caller's known-stale list. A report with errors is always a violation: it has measured nothing, and "known stale" must not excuse a generator that failed to run.

Implementation

String? freshnessRatchetViolation(
  String project,
  BridgeFreshness freshness, {
  required bool knownStale,
}) {
  if (freshness.errors.isNotEmpty) {
    return '$project: generation failed, so nothing was compared:\n  '
        '${freshness.errors.join('\n  ')}';
  }
  if (freshness.checked.isEmpty) {
    return '$project: the generator produced nothing, so nothing was compared.';
  }
  if (knownStale) {
    return freshness.isFresh
        ? '$project is fresh now — delete it from the known-stale list so it '
              'stays fresh.'
        : null;
  }
  return freshness.isFresh
      ? null
      : '$project: regenerate it and commit everything that changes:\n  '
            '${freshness.stale.join('\n  ')}';
}