fixStaleIgnores function

List<StaleIgnoreFixResult> fixStaleIgnores(
  1. List<StaleIgnore> staleIgnores
)

Removes stale ignore directives from the source files they appear in.

For each stale ignore:

  • Standalone comment (entire line is // ignore: ...): removes the line.
  • Inline comment (code before // ignore: ...): strips the ignore portion, preserving the code.
  • Multi-rule ignore where only SOME rules are stale: removes only the stale rule names from the comma-separated list, keeping the non-stale ones.

Returns one StaleIgnoreFixResult per modified file. Files with no modifications (e.g. all ignores already removed by a prior pass) are excluded from the result.

Implementation

List<StaleIgnoreFixResult> fixStaleIgnores(List<StaleIgnore> staleIgnores) {
  if (staleIgnores.isEmpty) return [];

  // Group by file so we process each file once, applying all removals in a
  // single pass from bottom to top (reverse line order prevents index shift).
  final byFile = <String, List<StaleIgnore>>{};
  for (final s in staleIgnores) {
    byFile.putIfAbsent(s.filePath, () => []).add(s);
  }

  final results = <StaleIgnoreFixResult>[];

  for (final entry in byFile.entries) {
    final result = _fixFileStaleIgnores(entry.key, entry.value);
    if (result != null) results.add(result);
  }

  return results;
}