Class: Ace::Lint::Organisms::ResultReporter

Inherits:
Object
  • Object
show all
Defined in:
lib/ace/lint/organisms/result_reporter.rb

Overview

Formats and displays validation results with colors

Defined Under Namespace

Modules: StringHelper

Class Method Summary collapse

Class Method Details

.exit_code(results) ⇒ Integer

Get exit code based on results

Parameters:

Returns:

  • (Integer)

    Exit code (0 = success, 1 = failures)



42
43
44
# File 'lib/ace/lint/organisms/result_reporter.rb', line 42

def self.exit_code(results)
  results.any?(&:failed?) ? 1 : 0
end

.report(results, verbose: true, report_dir: nil, report_files: nil) ⇒ Object

Report results to stdout

Parameters:

  • results (Array<Models::LintResult>)

    Validation results

  • verbose (Boolean) (defaults to: true)

    Show detailed output (only used when no report)

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

    Path to generated report directory

  • report_files (Hash, nil) (defaults to: nil)

    Hash of generated files with counts



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/ace/lint/organisms/result_reporter.rb', line 26

def self.report(results, verbose: true, report_dir: nil, report_files: nil)
  # When report is generated, show only summary (details are in the report)
  # When no report (--no-report), show per-file details
  unless report_dir
    results.each do |result|
      report_single_result(result, verbose: verbose)
    end
    puts
  end

  report_summary(results, report_dir: report_dir, report_files: report_files)
end

.report_failure(result, verbose:) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/ace/lint/organisms/result_reporter.rb', line 78

def self.report_failure(result, verbose:)
  puts "#{result.file_path}: #{"".red}"

  return unless verbose

  result.errors.each do |error|
    puts "  #{"".red}  #{error.to_s.red}"
  end

  result.warnings.each do |warning|
    puts "  #{"".yellow}  #{warning.to_s.yellow}"
  end
end

.report_single_result(result, verbose:) ⇒ Object



46
47
48
49
50
51
52
53
54
# File 'lib/ace/lint/organisms/result_reporter.rb', line 46

def self.report_single_result(result, verbose:)
  if result.skipped?
    report_skipped(result, verbose: verbose)
  elsif result.success
    report_success(result, verbose: verbose)
  else
    report_failure(result, verbose: verbose)
  end
end

.report_skipped(result, verbose:) ⇒ Object



56
57
58
59
60
61
62
# File 'lib/ace/lint/organisms/result_reporter.rb', line 56

def self.report_skipped(result, verbose:)
  if result.skip_reason && verbose
    puts "#{result.file_path}: #{"".cyan} (skipped: #{result.skip_reason})"
  else
    puts "#{result.file_path}: #{"".cyan} (skipped)"
  end
end

.report_success(result, verbose:) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/ace/lint/organisms/result_reporter.rb', line 64

def self.report_success(result, verbose:)
  if result.formatted
    puts "#{result.file_path}: #{"".green} #{"(formatted)".yellow}"
  else
    puts "#{result.file_path}: #{"".green}"
  end

  return unless verbose && result.has_warnings?

  result.warnings.each do |warning|
    puts "  #{"".yellow}  #{warning.to_s.yellow}"
  end
end

.report_summary(results, report_dir: nil, report_files: nil) ⇒ Object



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/ace/lint/organisms/result_reporter.rb', line 92

def self.report_summary(results, report_dir: nil, report_files: nil)
  total = results.size
  fixed = results.count(&:formatted?)
  skipped = results.count(&:skipped?)
  failed = results.count(&:failed?)
  # Passed files: success but not formatted and not skipped
  passed = results.count { |r| r.success? && !r.formatted? && !r.skipped? }
  total_errors = results.sum(&:error_count)
  total_warnings = results.sum(&:warning_count)

  puts "=" * 60
  puts "Validated: #{total} #{StringHelper.pluralize("file", total)}"

  if failed.zero? && fixed.zero?
    puts "✓ All files passed".green
  else
    puts "#{passed} passed".green if passed.positive?
    puts "#{fixed} fixed".green if fixed.positive?
    puts "#{failed} failed".red if failed.positive?
  end

  puts "#{skipped} skipped".cyan if skipped.positive?
  puts "  #{total_errors} #{StringHelper.pluralize("error", total_errors)}".red if total_errors.positive?
  puts "  #{total_warnings} #{StringHelper.pluralize("warning", total_warnings)}".yellow if total_warnings.positive?

  return unless report_dir && report_files

  puts
  puts "Reports: #{report_dir}/"
  report_files.each do |type, info|
    label = "#{type}.md".ljust(12)
    unit = (type == :pending) ? "issues" : "files"
    puts "  #{label} (#{info[:count]} #{unit})"
  end
end