Class: Reporter::JUnitReporter

Inherits:
Reporter
  • Object
show all
Defined in:
lib/scss_lint_reporter_junit.rb

Instance Method Summary collapse

Instance Method Details

#report_lintsObject


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
# File 'lib/scss_lint_reporter_junit.rb', line 3

def report_lints
  results = lints.group_by(&:filename)
  output = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"

  output << "<testsuite name=\"scsslint\" failures=\"#{results.length}\">\n"
  if !results.length
    output << "  <testcase name=\"Empty\"/>\n"
  end
  results.each do |file_name, errors|
    output << "  <testcase name=#{file_name.encode(xml: :attr)}>\n"
    output << "    <failure message=\"#{errors.length} SCSSLint Failure\">"

    i = 1
    errors.each do |error|
      output << "#{i}. line #{error.location.line}, column #{error.location.column}-" \
        "#{error.location.length}: [#{error.severity}] #{error.linter.name if error.linter}: "\
        "#{error.description.encode(xml: :attr)}"
      i += 1
    end
    output << "</failure>\n"
    output << "  </testcase>\n"
  end
  output << "</testsuite>\n"

  output
end