Class: LintTrappings::Formatter::Default

Inherits:
Base
  • Object
show all
Defined in:
lib/lint_trappings/formatter/default.rb

Overview

Outputs lints in a simple format with the filename, line number, and lint message.

Instance Method Summary collapse

Methods inherited from Base

#initialize, #job_started

Constructor Details

This class inherits a constructor from LintTrappings::Formatter::Base

Instance Method Details

#finished(report) ⇒ Object


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
# File 'lib/lint_trappings/formatter/default.rb', line 24

def finished(report)
  # Ensure we have a newline after the last progress dot output
  output.newline if @at_least_one_job_finished

  report.lints.each do |lint|
    print_location(lint)
    print_message(lint)
  end

  output.newline

  files = LintTrappings::Utils.pluralize('file', report.documents_inspected.count)
  output.print "#{report.documents_inspected.count} #{files} inspected"

  if report.failures?
    failures = LintTrappings::Utils.pluralize('failure', report.failures.count)
    output.print ', '
    output.error "#{report.failures.count} #{failures} reported", false
  end

  if report.warnings?
    warnings = LintTrappings::Utils.pluralize('warning', report.warnings.count)
    output.print ', '
    output.warning "#{report.warnings.count} #{warnings} reported", false
  end

  if report.success?
    output.print ', '
    output.success 'no issues reported', false
  end

  output.newline
end

#job_finished(_job, lints) ⇒ Object


12
13
14
15
16
17
18
19
20
21
22
# File 'lib/lint_trappings/formatter/default.rb', line 12

def job_finished(_job, lints)
  @at_least_one_job_finished = true

  if lints.any? { |lint| failing_lint?(lint) }
    output.error 'F', false
  elsif lints.any? { |lint| warning_lint?(lint) }
    output.warning 'W', false
  else
    output.success '.', false
  end
end

#started(files_to_lint) ⇒ Object


7
8
9
10
# File 'lib/lint_trappings/formatter/default.rb', line 7

def started(files_to_lint)
  files = LintTrappings::Utils.pluralize('file', files_to_lint.count)
  output.info "Scanning #{files_to_lint.count} #{files}..."
end