format method
String
format(
- ComparisonResult result,
- ExtractionResult extracted, {
- bool verbose = false,
override
Generate output for the given comparison result.
Implementation
@override
String format(
ComparisonResult result,
ExtractionResult extracted, {
bool verbose = false,
}) {
final buffer = StringBuffer();
// Header comment
buffer.writeln('# shard_i18n extract diff');
buffer.writeln('# Generated: ${DateTime.now().toUtc().toIso8601String()}');
buffer.writeln('# Keys in code: ${result.stats.totalKeysInCode}');
buffer.writeln('# Keys in JSON: ${result.stats.totalKeysInJson}');
buffer.writeln(
'# Coverage: ${result.stats.coveragePercent.toStringAsFixed(1)}%',
);
buffer.writeln();
// Missing keys (to add)
if (result.missingInJson.isNotEmpty) {
buffer.writeln('# Missing in JSON (need to add):');
final sortedMissing = result.missingInJson.toList()..sort();
for (final key in sortedMissing) {
final locations = extracted.keys.where((k) => k.key == key);
final firstLoc = locations.isNotEmpty ? locations.first : null;
final comment = firstLoc != null
? ' # ${firstLoc.filePath}:${firstLoc.line}'
: '';
buffer.writeln('+ $key$comment');
}
buffer.writeln();
}
// Orphaned keys (to remove)
if (result.orphanedInJson.isNotEmpty) {
buffer.writeln('# Orphaned in JSON (can remove):');
final sortedOrphaned = result.orphanedInJson.toList()..sort();
for (final key in sortedOrphaned) {
buffer.writeln('- $key');
}
buffer.writeln();
}
// Placeholder mismatches (need attention)
if (result.placeholderMismatches.isNotEmpty) {
buffer.writeln('# Placeholder mismatches (need attention):');
for (final mismatch in result.placeholderMismatches.values) {
buffer.writeln(
'~ ${mismatch.key} # code:{${mismatch.inCode.join(',')}} json:{${mismatch.inJson.join(',')}}',
);
}
buffer.writeln();
}
// Plural issues
if (result.pluralIssues.isNotEmpty) {
buffer.writeln('# Plural form issues:');
for (final issue in result.pluralIssues.values) {
buffer.writeln('! ${issue.key} # ${issue.message}');
}
buffer.writeln();
}
// Summary
if (!result.hasDiscrepancies) {
buffer.writeln('# All keys are in sync!');
}
return buffer.toString();
}