formatTinyrackCheckResult function

String formatTinyrackCheckResult(
  1. TinyrackCheckResult result, [
  2. TinyrackCheckFormat format = TinyrackCheckFormat.pretty
])

Implementation

String formatTinyrackCheckResult(
  TinyrackCheckResult result, [
  TinyrackCheckFormat format = TinyrackCheckFormat.pretty,
]) {
  if (format == TinyrackCheckFormat.json) {
    return const JsonEncoder.withIndent('  ').convert(result.toJson());
  }
  if (result.violations.isEmpty) {
    return 'Tinyrack UI check passed (${result.checkedFiles} files).';
  }
  if (format == TinyrackCheckFormat.github) {
    return result.violations
        .map((violation) {
          return '::error file=${_escapeAnnotation(violation.path)},'
              'line=${violation.line},col=${violation.column},'
              'title=${_escapeAnnotation(violation.ruleId)}::'
              '${_escapeAnnotation(violation.message)}';
        })
        .join('\n');
  }
  return <String>[
    ...result.violations.map((violation) => violation.toString()),
    'Tinyrack UI check failed with ${result.violations.length} violation(s) '
        'in ${result.checkedFiles} file(s).',
  ].join('\n');
}