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.
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 |
#print_lint(lint) ⇒ void
This method returns an undefined value.
Prints the lint with its location and severity.
24 25 26 27 28 |
# File 'lib/haml_lint/reporter/utils.rb', line 24 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.
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 |
#print_message(lint) ⇒ void
This method returns an undefined value.
Prints the description of a lint.
58 59 60 61 62 63 64 |
# File 'lib/haml_lint/reporter/utils.rb', line 58 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.
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 |
#print_summary_files(report) ⇒ void
This method returns an undefined value.
Prints a summary of the number of files linted in a report.
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 |
#print_summary_lints(report) ⇒ void
This method returns an undefined value.
Prints a summary of the number of lints found in a report.
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 = 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.
44 45 46 47 48 49 50 51 52 |
# File 'lib/haml_lint/reporter/utils.rb', line 44 def print_type(lint) = " [#{lint.severity.mark}] " if lint.error? log.error , false else log.warning , false end end |