Class: Rigor::CLI::DiffCommand

Inherits:
Command
  • Object
show all
Defined in:
lib/rigor/cli/diff_command.rb,
sig/rigor/cli/diff_command.rbs

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

Constructor Details

#initializeDiffCommand

Returns a new instance of DiffCommand.

Parameters:

  • argv: (Object)
  • out: (Object)
  • err: (Object)


2
# File 'sig/rigor/cli/diff_command.rbs', line 2

def initialize: (argv: untyped, out: untyped, err: untyped) -> void

Instance Method Details

#runInteger

Returns CLI exit status.

Returns:

  • (Integer)

    CLI exit status.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/rigor/cli/diff_command.rb', line 30

def run
  options = parse_options

  baseline_path = @argv.shift
  if baseline_path.nil?
    @err.puts(USAGE)
    return CLI::EXIT_USAGE
  end

  baseline = load_diagnostics(baseline_path)
  current = options.fetch(:current_path) ? load_diagnostics(options.fetch(:current_path)) : run_current(options)
  return CLI::EXIT_USAGE if baseline.nil? || current.nil?

  diff = compute_diff(baseline, current)
  write_diff(
    diff, options.fetch(:format),
    baseline_path: baseline_path,
    baseline_count: baseline.size,
    current_count: current.size
  )
  diff[:new].any? ? 1 : 0
end