applyLevelOverrides function

List<Chki18nIssue> applyLevelOverrides(
  1. List<Chki18nIssue> issues,
  2. Map<Chki18nCheckCode, Chki18nLevel>? levels
)

Re-grades issues whose check the caller asked to report at another severity.

Applied to a finished list rather than at every call site, so a check that builds its issues in several places cannot be left half converted. The list is rewritten in place and handed back, which is what lets a caller keep the reference it already has.

Implementation

List<Chki18nIssue> applyLevelOverrides(
  List<Chki18nIssue> issues,
  Map<Chki18nCheckCode, Chki18nLevel>? levels,
) {
  if (levels == null || levels.isEmpty) {
    return issues;
  }

  for (var index = 0; index < issues.length; index += 1) {
    final level = levels[issues[index].code];

    if (level != null) {
      issues[index] = issues[index].withLevel(level);
    }
  }

  return issues;
}