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
# File 'lib/haml_lint/reporter/utils.rb', line 58

def print_message(lint)
  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:


70
71
72
73
74
75
76
77
# File 'lib/haml_lint/reporter/utils.rb', line 70

def print_summary(report)
  return unless log.summary_enabled

  print_summary_files(report)
  print_summary_lints(report)

  log.log ' detected'
end

This method returns an undefined value.

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

Parameters:


83
84
85
# File 'lib/haml_lint/reporter/utils.rb', line 83

def print_summary_files(report)
  log.log "\n#{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:


91
92
93
94
95
96
97
98
99
100
# File 'lib/haml_lint/reporter/utils.rb', line 91

def print_summary_lints(report)
  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