Class: Moult::DeadCodeReport

Inherits:
Object
  • Object
show all
Defined in:
lib/moult/dead_code_report.rb

Overview

The serialized result model for moult deadcode, sibling to Report. It owns the JSON envelope (schema/deadcode.schema.json) and leaves the protected hotspots Report untouched. The findings it carries are Confidence::Finding objects — the per-finding confidence model is the protected API, so this class only adds the report-level envelope around it.

Constant Summary collapse

SCHEMA_VERSION =

Bump only on a breaking change to the serialized shape. v2 adds the Phase 3 runtime block: analysis.coverage provenance and a per-finding runtime classification (both null when no coverage was merged).

2

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root:, findings:, git_ref: nil, generated_at: nil, backend: "rubydex", backend_version: nil, resolved: true, rails: false, diagnostics: [], coverage_source: nil) ⇒ DeadCodeReport

Returns a new instance of DeadCodeReport.

Parameters:

  • root (String)

    absolute analysis root

  • findings (Array<Confidence::Finding>)

    ranked, most-likely-dead first

  • git_ref (String, nil) (defaults to: nil)

    HEAD sha when run inside a repo

  • generated_at (String, nil) (defaults to: nil)

    ISO8601 timestamp

  • backend (String) (defaults to: "rubydex")

    index backend name (e.g. "rubydex")

  • backend_version (String, nil) (defaults to: nil)

    backend gem version

  • resolved (Boolean) (defaults to: true)

    whether the index fully resolved

  • rails (Boolean) (defaults to: false)

    whether Rails entrypoint awareness was applied

  • diagnostics (Array<String>) (defaults to: [])

    non-fatal index diagnostics

  • coverage_source (Coverage::Source, nil) (defaults to: nil)

    provenance of merged runtime coverage; nil when moult deadcode was run without --coverage



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/moult/dead_code_report.rb', line 29

def initialize(root:, findings:, git_ref: nil, generated_at: nil,
  backend: "rubydex", backend_version: nil, resolved: true, rails: false, diagnostics: [],
  coverage_source: nil)
  @root = root
  @findings = findings
  @git_ref = git_ref
  @generated_at = generated_at
  @backend = backend
  @backend_version = backend_version
  @resolved = resolved
  @rails = rails
  @diagnostics = diagnostics
  @coverage_source = coverage_source
end

Instance Attribute Details

#backendObject (readonly)

Returns the value of attribute backend.



15
16
17
# File 'lib/moult/dead_code_report.rb', line 15

def backend
  @backend
end

#backend_versionObject (readonly)

Returns the value of attribute backend_version.



15
16
17
# File 'lib/moult/dead_code_report.rb', line 15

def backend_version
  @backend_version
end

#coverage_sourceObject (readonly)

Returns the value of attribute coverage_source.



15
16
17
# File 'lib/moult/dead_code_report.rb', line 15

def coverage_source
  @coverage_source
end

#diagnosticsObject (readonly)

Returns the value of attribute diagnostics.



15
16
17
# File 'lib/moult/dead_code_report.rb', line 15

def diagnostics
  @diagnostics
end

#findingsObject (readonly)

Returns the value of attribute findings.



15
16
17
# File 'lib/moult/dead_code_report.rb', line 15

def findings
  @findings
end

#generated_atObject (readonly)

Returns the value of attribute generated_at.



15
16
17
# File 'lib/moult/dead_code_report.rb', line 15

def generated_at
  @generated_at
end

#git_refObject (readonly)

Returns the value of attribute git_ref.



15
16
17
# File 'lib/moult/dead_code_report.rb', line 15

def git_ref
  @git_ref
end

#railsObject (readonly)

Returns the value of attribute rails.



15
16
17
# File 'lib/moult/dead_code_report.rb', line 15

def rails
  @rails
end

#resolvedObject (readonly)

Returns the value of attribute resolved.



15
16
17
# File 'lib/moult/dead_code_report.rb', line 15

def resolved
  @resolved
end

#rootObject (readonly)

Returns the value of attribute root.



15
16
17
# File 'lib/moult/dead_code_report.rb', line 15

def root
  @root
end

Instance Method Details

#to_hObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/moult/dead_code_report.rb', line 44

def to_h
  {
    schema_version: SCHEMA_VERSION,
    tool: {name: "moult", version: Moult::VERSION},
    analysis: {
      root: root,
      git_ref: git_ref,
      generated_at: generated_at,
      coverage: coverage_source&.to_h,
      index: {
        backend: backend,
        backend_version: backend_version,
        resolved: resolved,
        rails: rails,
        diagnostics: diagnostics
      }
    },
    findings: findings.map(&:to_h)
  }
end