Class: RailsDoctor::Reporters::Terminal

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_doctor/reporters/terminal.rb

Instance Method Summary collapse

Constructor Details

#initialize(result) ⇒ Terminal

Returns a new instance of Terminal.



6
7
8
# File 'lib/rails_doctor/reporters/terminal.rb', line 6

def initialize(result)
  @result = result
end

Instance Method Details

#renderObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/rails_doctor/reporters/terminal.rb', line 10

def render
  lines = []
  lines << "Rails Doctor"
  lines << ("=" * 12)
  lines << "Profile: #{@result.profile}"
  lines << "Score: #{score_text}"
  lines << "Confidence: #{@result.score&.confidence || "n/a"}%"
  lines << "Coverage: #{coverage_text}"
  lines << "Findings: #{severity_counts}"
  lines << "Duration: #{@result.duration_ms}ms" if @result.duration_ms
  lines << ""

  if @result.skipped_tools.any?
    lines << "Skipped tools"
    @result.skipped_tools.each do |tool|
      lines << "- #{tool.name}: #{tool.skip_reason}"
      lines << "  #{tool.[:install]}" if tool.[:install]
    end
    lines << ""
  end

  if low_coverage_files.any?
    lines << "Low coverage files"
    low_coverage_files.each do |file|
      lines << "- #{file.fetch(:file)}: #{format_percent(file.fetch(:line_percent))} lines"
    end
    lines << ""
  end

  lines << "Top fixes"
  top_findings.each do |finding|
    location = [finding.file, finding.line].compact.join(":")
    lines << "- [#{finding.severity}] #{finding.message}"
    lines << "  #{location}" unless location.empty?
    lines << "  #{finding.recommendation}" if finding.recommendation
  end
  lines << "- No findings. Keep running Rails Doctor in CI." if top_findings.empty?

  if @result.hotspots.any?
    lines << ""
    lines << "Hotspots"
    @result.hotspots.first(5).each do |hotspot|
      lines << "- #{hotspot.file}: score #{hotspot.score}, #{hotspot.finding_count} findings, churn #{hotspot.churn}"
    end
  end

  lines.join("\n") + "\n"
end