Module: HamlLint::Reporter::Utils
- Included in:
- DefaultReporter, GithubReporter, 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_corrected_lints(report, is_append:) ⇒ void
Prints a summary of the number of lints corrected in a report.
-
#print_summary_files(report) ⇒ void
Prints a summary of the number of files linted in a report.
-
#print_summary_lints(report, is_append:) ⇒ 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 65 66 67 68 |
# File 'lib/haml_lint/reporter/utils.rb', line 58 def (lint) if lint.corrected log.success('[Corrected] ', false) end 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.
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 |
#print_summary_corrected_lints(report, is_append:) ⇒ void
This method returns an undefined value.
Prints a summary of the number of lints corrected in a report.
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 = pluralize('lint', count: lint_count) log.info , false log.log ' corrected', false end |
#print_summary_files(report) ⇒ void
This method returns an undefined value.
Prints a summary of the number of files linted in a report.
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 |
#print_summary_lints(report, is_append:) ⇒ void
This method returns an undefined value.
Prints a summary of the number of lints found in a report.
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 = 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 |