Class: Kamal::Lint::Formatters::Human

Inherits:
Object
  • Object
show all
Defined in:
lib/kamal/lint/formatters/human.rb

Constant Summary collapse

COLORS =
{
  reset: "\e[0m",
  bold: "\e[1m",
  dim: "\e[2m",
  red: "\e[31m",
  yellow: "\e[33m",
  green: "\e[32m",
  blue: "\e[34m",
  magenta: "\e[35m",
  cyan: "\e[36m",
  gray: "\e[90m"
}.freeze
SEVERITY_GLYPH =
{
  error: "",
  warning: "",
  info: ""
}.freeze
SEVERITY_COLOR =
{
  error: :red,
  warning: :yellow,
  info: :blue
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(io: $stdout, color: nil) ⇒ Human

Returns a new instance of Human.



32
33
34
35
# File 'lib/kamal/lint/formatters/human.rb', line 32

def initialize(io: $stdout, color: nil)
  @io = io
  @color = color.nil? ? io.tty? : color
end

Instance Method Details

#render(result) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/kamal/lint/formatters/human.rb', line 37

def render(result)
  render_header(result)

  if result.findings.empty?
    @io.puts c(:green, "  ✓ No issues found.")
    return
  end

  result.findings
    .sort_by { |f| [ SEVERITIES.index(f.severity), f.line || 0 ] }
    .each { |finding| render_finding(finding) }

  render_summary(result)
end

#render_fix_summary(result) ⇒ Object



52
53
54
55
56
57
58
59
60
# File 'lib/kamal/lint/formatters/human.rb', line 52

def render_fix_summary(result)
  return if result.fixed.empty?

  @io.puts
  @io.puts c(:bold, "Applied autofixes:")
  result.fixed.each do |finding|
    @io.puts "  #{c(:green, "")} [#{finding.check_id}] #{finding.message}"
  end
end