Class: Rigor::CLI::DiffCommand
- Defined in:
- lib/rigor/cli/diff_command.rb
Overview
Executes ‘rigor diff <baseline.json> [paths…]`. Compares the current `rigor check` diagnostics against a saved baseline JSON (the output of a previous `rigor check –format=json` run) and prints the delta:
-
new — diagnostics in the current run that were not in the baseline (typically a regression introduced in this PR).
-
fixed — diagnostics in the baseline that no longer appear in the current run (typically progress).
Identity for matching is the tuple ‘(path, line, column, rule, source_family, message)`. An edit that moves a diagnostic to a new line surfaces as one fixed + one new pair, which lines up with the user’s mental model of “you changed the line, the analyzer’s position changed too.”
CI usage: commit a ‘rigor.baseline.json` produced once with `rigor check –format=json > rigor.baseline.json`, then run `rigor diff rigor.baseline.json` in CI. Exit code is `1` when any new diagnostic appears, `0` otherwise —so adding new errors fails CI but legacy errors recorded in the baseline don’t.
Constant Summary collapse
- USAGE =
"Usage: rigor diff [options] <baseline.json> [paths...]"
Instance Method Summary collapse
-
#run ⇒ Integer
CLI exit status.
Methods inherited from Command
Constructor Details
This class inherits a constructor from Rigor::CLI::Command
Instance Method Details
#run ⇒ Integer
Returns CLI exit status.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/rigor/cli/diff_command.rb', line 38 def run = baseline_path = @argv.shift if baseline_path.nil? @err.puts(USAGE) return CLI::EXIT_USAGE end baseline = load_diagnostics(baseline_path) current = .fetch(:current_path) ? load_diagnostics(.fetch(:current_path)) : run_current() return CLI::EXIT_USAGE if baseline.nil? || current.nil? diff = compute_diff(baseline, current) write_diff( diff, .fetch(:format), baseline_path: baseline_path, baseline_count: baseline.size, current_count: current.size ) diff[:new].any? ? 1 : 0 end |