Class: Rigor::CLI::DiffCommand
- Inherits:
-
Object
- Object
- 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 =
rubocop:disable Metrics/ClassLength
"Usage: rigor diff [options] <baseline.json> [paths...]"
Instance Method Summary collapse
-
#initialize(argv:, out:, err:) ⇒ DiffCommand
constructor
A new instance of DiffCommand.
-
#run ⇒ Integer
CLI exit status.
Constructor Details
#initialize(argv:, out:, err:) ⇒ DiffCommand
Returns a new instance of DiffCommand.
35 36 37 38 39 |
# File 'lib/rigor/cli/diff_command.rb', line 35 def initialize(argv:, out:, err:) @argv = argv @out = out @err = err end |
Instance Method Details
#run ⇒ Integer
Returns CLI exit status.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/rigor/cli/diff_command.rb', line 42 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 |