fromJson static method

AuditBaseline fromJson(
  1. List<Object?> json
)

Parses a JSON List of {file, rule, reason} maps — an entry missing any of the 3 fields, with an empty reason, or naming an unknown rule id is silently dropped (never throws): a malformed baseline should read as "fewer suppressions than intended," which makes the scan MORE strict, never a way to accidentally suppress more than the file actually says.

Implementation

static AuditBaseline fromJson(List<Object?> json) {
  final entries = <AuditSuppression>[];
  for (final raw in json) {
    if (raw is! Map) continue;
    final file = raw['file'];
    final rule = raw['rule'];
    final reason = raw['reason'];
    if (file is! String || rule is! String || reason is! String) continue;
    if (reason.trim().isEmpty) continue;
    AuditRuleId? ruleId;
    for (final id in AuditRuleId.values) {
      if (id.name == rule) {
        ruleId = id;
        break;
      }
    }
    if (ruleId == null) continue;
    entries.add(AuditSuppression(file: file, ruleId: ruleId, reason: reason));
  }
  return AuditBaseline(entries);
}