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
-
#pluralize(word, count: 1) ⇒ String
Pluralizes a word based on a count.
-
#print_lint(lint) ⇒ void
Prints the lint with its location and severity.
-
#print_location(lint) ⇒ void
Prints the location of a lint.
-
#print_message(lint) ⇒ void
Prints the description of a lint.
-
#print_summary(report) ⇒ void
Prints a summary of a report when summaries are enabled.
-
#print_summary_files(report) ⇒ void
Prints a summary of the number of files linted in a report.
-
#print_summary_lints(report) ⇒ void
Prints a summary of the number of lints found in a report.
-
#print_type(lint) ⇒ void
Prints the severity of a lint.
Instance Method Details
#pluralize(word, count: 1) ⇒ String
Pluralizes a word based on a count.
10 11 12 13 14 15 16 |
# File 'lib/haml_lint/reporter/utils.rb', line 10 def pluralize(word, count: 1) if count.zero? || count > 1 "#{count} #{word}s" else "#{count} #{word}" end end |
#print_lint(lint) ⇒ void
This method returns an undefined value.
Prints the lint with its location and severity.
22 23 24 25 26 |
# File 'lib/haml_lint/reporter/utils.rb', line 22 def print_lint(lint) print_location(lint) print_type(lint) (lint) end |
#print_location(lint) ⇒ void
This method returns an undefined value.
Prints the location of a lint.
32 33 34 35 36 |
# File 'lib/haml_lint/reporter/utils.rb', line 32 def print_location(lint) log.info lint.filename, false log.log ':', false log.bold lint.line, false end |
#print_message(lint) ⇒ void
This method returns an undefined value.
Prints the description of a lint.
56 57 58 59 60 61 62 |
# File 'lib/haml_lint/reporter/utils.rb', line 56 def (lint) if lint.linter log.success("#{lint.linter.name}: ", false) end log.log lint. end |
#print_summary(report) ⇒ void
This method returns an undefined value.
Prints a summary of a report when summaries are enabled.
68 69 70 71 72 73 74 75 |
# File 'lib/haml_lint/reporter/utils.rb', line 68 def print_summary(report) return unless log.summary_enabled print_summary_files(report) print_summary_lints(report) log.log ' detected' end |
#print_summary_files(report) ⇒ void
This method returns an undefined value.
Prints a summary of the number of files linted in a report.
81 82 83 |
# File 'lib/haml_lint/reporter/utils.rb', line 81 def print_summary_files(report) log.log "\n#{pluralize('file', count: report.files.count)} inspected, ", false end |
#print_summary_lints(report) ⇒ void
This method returns an undefined value.
Prints a summary of the number of lints found in a report.
89 90 91 92 93 94 95 96 97 98 |
# File 'lib/haml_lint/reporter/utils.rb', line 89 def print_summary_lints(report) lint_count = report.lints.size = pluralize('lint', count: lint_count) if lint_count == 0 log.log , false else log.error , false end end |
#print_type(lint) ⇒ void
This method returns an undefined value.
Prints the severity of a lint.
42 43 44 45 46 47 48 49 50 |
# File 'lib/haml_lint/reporter/utils.rb', line 42 def print_type(lint) = " [#{lint.severity.mark}] " if lint.error? log.error , false else log.warning , false end end |