textReport function

String textReport(
  1. CheckResult result
)

Human-readable report: one block per finding, the reason each rule exists (once per rule), then a summary line.

Implementation

String textReport(CheckResult result) {
  final out = StringBuffer();
  final seen = <Rule>[];
  for (final f in result.findings) {
    if (!seen.contains(f.rule)) seen.add(f.rule);
    out
      ..writeln(
        '${f.path}:${f.line}:${f.column}  ${f.severity.name}  ${f.rule.id}',
      )
      ..writeln('  ${f.message}')
      ..writeln('  fix: ${f.rule.fix}')
      ..writeln();
  }
  if (seen.isNotEmpty) {
    out.writeln('Why:');
    for (final rule in seen) {
      out.writeln('  ${rule.id}: ${rule.why}');
    }
    out.writeln();
  }
  for (final file in result.untyped) {
    out.writeln(
      'note: $file was checked without type information (an import did not '
      'resolve); run `flutter pub get` for exact results.',
    );
  }
  if (result.untyped.isNotEmpty) out.writeln();
  out.writeln(_summary(result));
  return out.toString();
}