module

Ignorelint::Fixer

The fixer module. Uses extend self so methods can be called as Fixer.apply_fixes(...) without instantiating a class.

Instance methods

apply_fixes(content_lines : Array(String), fixes : Array(Fix), sort_fix : SortFix | Nil) : String

Apply individual fixes + sort fix to content lines, return new content.

The algorithm:

  1. Detect the file's line-ending style (CRLF vs LF) and chomp all lines
  2. Compose per-line fixes (each recomputed on the evolving line text)
  3. Apply deletions (remove lines whose fix is a deletion)
  4. Apply sort fix (reorder all active lines alphabetically)
  5. Re-join with the detected ending, restoring the final newline

content_lines comes from content.lines(chomp: false) — each element may or may not end with \n. We normalize by chomping everything and then adding a final ending at the end if the original file had one.

collect_fixes(issues : Array(Issue), patterns : Array(Pattern), content_lines : Array(String)) : Tuple(Array(Fix), SortFix | Nil)

Collect all fixes for a set of issues. Returns individual line fixes plus a special bulk SortFix when sorting is needed.

The separation between individual Fix values and the SortFix is important: individual fixes are simple line-by-line replacements or deletions, while the SortFix reorders all active lines alphabetically. They must be applied in the right order (individual first, then sort) to avoid index-shifting bugs.

fix_for_issue(issue : Issue, patterns : Array(Pattern)) : Fix | Nil

Generate a Fix for a single issue, given the surrounding context of all parsed patterns.

Returns nil when the issue's code is not fixable or when the pattern for the affected line cannot be found (should not happen in practice).

The patterns array is needed because the fix needs access to the parsed Pattern struct (which holds the decomposed body, flags, etc.) to compute the corrected text.

fixable?(code : Code) : Bool

Check whether a given diagnostic code has an auto-fix available.

Used by CLI#mark_fixed to decide which issues to relabel as :fixed.

Nested types