Module: HamlLint::Reporter::Utils

Included in:
DefaultReporter, ProgressReporter
Defined in:
lib/haml_lint/reporter/utils.rb

Overview

Formatting helpers for printing the default report format.

Instance Method Summary collapse

Instance Method Details

#pluralize(word, count: 1) ⇒ String

Pluralizes a word based on a count.

Parameters:

  • word (String)

    the word to pluralize

  • count (Integer) (defaults to: 1)

    the count of items

Returns:

  • (String)


12
13
14
15
16
17
18
# File 'lib/haml_lint/reporter/utils.rb', line 12

def pluralize(word, count: 1)
  if count.zero? || count > 1
    "#{count} #{word}s"
  else
    "#{count} #{word}"
  end
end

This method returns an undefined value.

Prints the lint with its location and severity.

Parameters:



24
25
26
27
28
# File 'lib/haml_lint/reporter/utils.rb', line 24

def print_lint(lint)
  print_location(lint)
  print_type(lint)
  print_message(lint)
end

This method returns an undefined value.

Prints the location of a lint.

Parameters:



34
35
36
37
38
# File 'lib/haml_lint/reporter/utils.rb', line 34

def print_location(lint)
  log.info lint.filename, false
  log.log ':', false
  log.bold lint.line, false
end

This method returns an undefined value.

Prints the description of a lint.

Parameters:



58
59
60
61
62
63
64
65
66
67
68
# File 'lib/haml_lint/reporter/utils.rb', line 58

def print_message(lint)
  if lint.corrected
    log.success('[Corrected] ', false)
  end

  if lint.linter
    log.success("#{lint.linter.name}: ", false)
  end

  log.log lint.message
end

This method returns an undefined value.

Prints a summary of a report when summaries are enabled.

Parameters:



74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/haml_lint/reporter/utils.rb', line 74

def print_summary(report)
  return unless log.summary_enabled

  log.log('')
  print_summary_files(report)

  print_summary_lints(report, is_append: true)

  log.log ' detected', false

  print_summary_corrected_lints(report, is_append: true)
  log.log ''
end

This method returns an undefined value.

Prints a summary of the number of lints corrected in a report.

Parameters:

  • report (HamlLint::Report)

    the report to print

  • is_append (Boolean)

    if this is appending to a line. Will preffix with “, ”.



119
120
121
122
123
124
125
126
127
128
129
# File 'lib/haml_lint/reporter/utils.rb', line 119

def print_summary_corrected_lints(report, is_append:)
  lint_count = report.lints.count(&:corrected)
  return if lint_count == 0

  log.log ', ', false if is_append

  lint_message = pluralize('lint', count: lint_count)

  log.info lint_message, false
  log.log ' corrected', false
end

This method returns an undefined value.

Prints a summary of the number of files linted in a report.

Parameters:



92
93
94
# File 'lib/haml_lint/reporter/utils.rb', line 92

def print_summary_files(report)
  log.log "#{pluralize('file', count: report.files.count)} inspected", false
end

This method returns an undefined value.

Prints a summary of the number of lints found in a report.

Parameters:

  • report (HamlLint::Report)

    the report to print

  • is_append (Boolean)

    if this is appending to a line. Will preffix with “, ”.



101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/haml_lint/reporter/utils.rb', line 101

def print_summary_lints(report, is_append:)
  log.log ', ', false if is_append

  lint_count = report.lints.size
  lint_message = pluralize('lint', count: lint_count)

  if lint_count == 0
    log.log lint_message, false
  else
    log.error lint_message, false
  end
end

This method returns an undefined value.

Prints the severity of a lint.

Parameters:



44
45
46
47
48
49
50
51
52
# File 'lib/haml_lint/reporter/utils.rb', line 44

def print_type(lint)
  message = " [#{lint.severity.mark}] "

  if lint.error?
    log.error message, false
  else
    log.warning message, false
  end
end