class

Ignorelint::Formatter

Inherits Reference < Object

Abstract base class for all output formatters.

Subclasses must implement the three-phase lifecycle:

  • start: called before processing begins
  • format_file: called once per linted file
  • finish: called after all files are processed

The io parameter is the output stream (usually STDOUT). Formatters write directly to it — they do not buffer internally (except for JSON/SARIF which need the complete structure before writing).

Crystal note: abstract class vs module

We use an abstract class (not a module) because formatters need per-instance state (e.g., HumanFormatter stores @color, JsonFormatter collects @results). Modules in Crystal cannot have per-instance state when used via include — they share state with the including type.

Instance methods

finish(io : IO) : Nil

Called once after all files are processed. Use for document footers and final aggregation (e.g., JSON total count).

format_file(result : FileResult, io : IO) : Nil

Called once per file with the lint results for that file.

start(io : IO) : Nil

Called once before any files are processed. Use for document headers.