Class: Rigor::CLI::DiffCommand

Inherits:
Object
  • Object
show all
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

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

#runInteger

Returns CLI exit status.

Returns:

  • (Integer)

    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
  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