Class: Steep::Drivers::DiagnosticPrinter::CodeFormatter

Inherits:
BaseFormatter show all
Defined in:
lib/steep/drivers/diagnostic_printer/code_formatter.rb

Instance Attribute Summary

Attributes inherited from BaseFormatter

#buffer, #stdout

Instance Method Summary collapse

Methods inherited from BaseFormatter

#initialize, #path

Constructor Details

This class inherits a constructor from Steep::Drivers::DiagnosticPrinter::BaseFormatter

Instance Method Details



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/steep/drivers/diagnostic_printer/code_formatter.rb', line 5

def print(diagnostic, prefix: "", source: true)
  header, *rest = diagnostic[:message].split(/\n/)

  stdout.puts "#{prefix}#{location(diagnostic)}: [#{severity_message(diagnostic[:severity])}] #{Rainbow(header).underline}"

  unless rest.empty?
    rest.each do |message|
      stdout.puts "#{prefix}#{message}"
    end
  end

  if diagnostic[:code]
    stdout.puts "#{prefix}" unless rest.empty?
    stdout.puts "#{prefix}│ Diagnostic ID: #{diagnostic[:code]}"
  end

  stdout.puts "#{prefix}"

  if source
    print_source_line(diagnostic, prefix: prefix)
  else
    stdout.puts "#{prefix}└ (no source code available)"
    stdout.puts "#{prefix}"
  end
end