staleIgnoresToJsonString function
Serializes staleIgnores to the JSON format compatible with the scan
CLI's --format json output convention.
Implementation
String staleIgnoresToJsonString(List<StaleIgnore> staleIgnores) {
final list = staleIgnores
.map(
(s) => <String, Object>{
'filePath': s.filePath,
'commentLine': s.commentLine,
'targetLine': s.targetLine,
'ruleName': s.ruleName,
'commentText': s.commentText,
},
)
.toList();
// Group by file for the summary, same pattern as scan diagnostics.
final byFile = <String, int>{};
final byRule = <String, int>{};
for (final s in staleIgnores) {
byFile[s.filePath] = (byFile[s.filePath] ?? 0) + 1;
byRule[s.ruleName] = (byRule[s.ruleName] ?? 0) + 1;
}
return const JsonEncoder.withIndent(' ').convert(<String, Object>{
'version': 1,
'staleIgnores': list,
'summary': <String, Object>{
'totalCount': staleIgnores.length,
'byFile': byFile,
'byRule': byRule,
},
});
}