readOverrides function
Read the override file into a key → fingerprint map (last entry wins per key). Returns an empty
map when no overrides were recorded. rootPath defaults to the reporter's cwd.
Implementation
Map<String, String> readOverrides({String? rootPath}) {
final file = _overridesFileFor(rootPath ?? Directory.current.path);
if (!file.existsSync()) return {};
final overrides = <String, String>{};
for (final line in file.readAsLinesSync()) {
if (line.trim().isEmpty) continue;
try {
final entry = jsonDecode(line) as Map<String, dynamic>;
final fingerprint = entry['fingerprint'] as String?;
if (fingerprint == null) continue;
final key = fingerprintKey(
ruleId: entry['ruleId'] as String? ?? '',
filePath: entry['filePath'] as String? ?? '',
line: entry['line'] as int? ?? 0,
column: entry['column'] as int? ?? 0,
);
overrides[key] = fingerprint;
} catch (_) {
// Skip malformed lines rather than failing the whole report.
}
}
return overrides;
}