File: terminal.rb

package info (click to toggle)
ruby-html-proofer 5.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 22,524 kB
  • sloc: ruby: 4,389; sh: 8; makefile: 4; javascript: 1; php: 1
file content (33 lines) | stat: -rw-r--r-- 1,000 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# frozen_string_literal: true

module HTMLProofer
  class Reporter
    class Terminal < HTMLProofer::Reporter
      def report
        msg = failures.each_with_object([]) do |(check_name, failures), arr|
          str = ["For the #{check_name} check, the following failures were found:\n"]

          failures.each do |failure|
            path_str = blank?(failure.path) ? "" : "At #{failure.path}"

            line_str = failure.line.nil? ? "" : ":#{failure.line}"

            path_and_line = "#{path_str}#{line_str}"
            path_and_line = blank?(path_and_line) ? "" : "* #{path_and_line}:\n\n"

            status_str = failure.status.nil? ? "" : " (status code #{failure.status})"

            indent = blank?(path_and_line) ? "* " : "  "
            str << <<~MSG
              #{path_and_line}#{indent}#{failure.description}#{status_str}
            MSG
          end

          arr << str.join("\n")
        end

        @logger.log(:error, msg.join("\n"))
      end
    end
  end
end