Ignorelint::CLI
Inherits Reference < Object
The command-line interface class.
Design
The CLI is a regular class (not a struct) because it holds mutable state:
the parsed options (@paths, @fail_on, @format, @fix, @verbose).
A single instance is created per invocation and orchestrates the entire
lint run.
Exit codes
0: no issues at or above the--fail-onthreshold1: issues found at or above the threshold2: invalid CLI arguments (unknown flags, bad values)
Crystal note: private constants
SEVERITY_WIDTH is a private constant (uppercase = constant in Crystal).
It is defined on the class, not the module. Crystal's private on a
constant restricts visibility to the defining type.
Constructors
Initialize the CLI with an output stream.
Detects TTY status; option defaults resolve later in run so that
explicit flags beat environment, which beats the projectfile subtree.
Crystal's responds_to?(:tty?) is a type-safe way to check if the IO
supports TTY detection (not all IO types do — StringIO does not).
Class methods
TTY plus empty-or-unset NO_COLOR means color.
Convenience entry point: create an instance and run.
Separates construction from execution so tests can inject a custom IO.
The io parameter defaults to STDOUT but can be replaced with a
StringIO for testing.
Instance methods
Main execution: parse flags, discover files, lint, format.
Returns the process exit code (0 = clean) instead of exiting, so specs
can assert on it; self.run performs the actual exit.
The flow is:
- Build and parse the option parser (consumes flags from
args) - Load policy (explicit
--config, else cwd projectfile discovery) - Apply projectfile, then environment overrides (flags always win)
- Build the output formatter
- Determine which files to lint (explicit paths or auto-discovery)
- Lint each file, collecting the exit code
- Emit formatted output
- Return non-zero if issues were found above the threshold