Class: Rigor::CLI::UnusedCommand

Inherits:
Command
  • Object
show all
Defined in:
lib/rigor/cli/unused_command.rb

Overview

ADR-102 — executes rigor unused.

Reports project constants that nothing reachable references. It is a REPORT, never a diagnostic: the measured precision of this signal is 7.0% on an adjudicated corpus target (docs/notes/20260813-unused-constant-fp-baseline.md), so its output is a review queue, not a defect list, and it never enters rigor check's stream at any severity (WD1). Exits 0 whatever it finds.

Constant Summary collapse

USAGE =
"Usage: rigor unused [options] [paths]"
REFERENCE_GLOB =

WD7 — the REFERENCE corpus is wider than the ANALYSIS corpus. .rake files sit inside paths: and reference project constants, but PathExpansion::RUBY_GLOB never reads them, which made them pure artifacts on two of three corpus targets. Harvesting references from a file is far cheaper than type-checking it, so the report takes the wider set.

"**/*.{rb,rake}"
TEMPLATE_GLOB =

Templates and data files that carry class names as strings. A name here is NOT counted as a reference — a YAML value is far weaker evidence than a constant node, and treating it as proof would silently hide real dead code. It demotes the declaration to cannot-decide instead, with the file named, so the reader judges it (ADR-102 WD4).

"**/*.{erb,haml,slim,yml,yaml,json}"

Instance Method Summary collapse

Methods inherited from Command

#initialize

Constructor Details

This class inherits a constructor from Rigor::CLI::Command

Instance Method Details

#runObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/rigor/cli/unused_command.rb', line 40

def run
  options = parse_options
  return CLI::EXIT_USAGE if options == :usage_error

  configuration = Configuration.load(options.fetch(:config))
  paths = @argv.empty? ? configuration.paths : @argv
  declarations, references, dynamic_uses = scan(paths, configuration)
  references.concat(signature_references(configuration))
  dynamic_uses.concat(template_mentions(declarations))

  contribution = Analysis::Reachability::PluginRoots.collect(configuration: configuration)
  references.concat(plugin_references(contribution.references))
  graph = Analysis::Reachability::Graph.new(
    declarations: declarations, references: references, dynamic_uses: dynamic_uses,
    root_fqns: root_fqns(declarations, options.fetch(:entry_points)) + contribution.roots,
    foreign: foreign_predicate(configuration)
  )
  emit(graph.report, options, supply: root_supply(contribution.roots, declarations))
  0
end