Class: Jshint::Reporters::Junit
- Inherits:
-
Object
- Object
- Jshint::Reporters::Junit
- Defined in:
- lib/jshint/reporters/junit.rb
Overview
Outputs a lint report in JUnit XML formt
Instance Attribute Summary collapse
-
#output ⇒ String
readonly
The report output.
Instance Method Summary collapse
-
#escape(text) ⇒ String
Escapes the text given for XML.
-
#initialize(results = {}) ⇒ Junit
constructor
Sets up the output string for the final report.
-
#print_errors_for_code(code, errors) ⇒ void
Appends new error elements to the Report output.
-
#report ⇒ String
Loops through all the errors and generates the report.
Constructor Details
#initialize(results = {}) ⇒ Junit
Sets up the output string for the final report
12 13 14 15 |
# File 'lib/jshint/reporters/junit.rb', line 12 def initialize(results = {}) @results = results @output = '' end |
Instance Attribute Details
#output ⇒ String (readonly)
Returns the report output.
7 8 9 |
# File 'lib/jshint/reporters/junit.rb', line 7 def output @output end |
Instance Method Details
#escape(text) ⇒ String
Escapes the text given for XML.
88 89 90 |
# File 'lib/jshint/reporters/junit.rb', line 88 def escape(text) REXML::Text.new(text, false, nil, false).to_s end |
#print_errors_for_code(code, errors) ⇒ void
This method returns an undefined value.
Appends new error elements to the Report output
</testcase>
74 75 76 77 78 79 80 81 82 |
# File 'lib/jshint/reporters/junit.rb', line 74 def print_errors_for_code(code, errors) name = (code, errors) output << " <testcase classname=\"jshint.#{code}\" name=\"#{escape(name)}\">\n" errors.each do |error| output << (code, error) end output << " </testcase>\n" output end |
#report ⇒ String
Loops through all the errors and generates the report
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/jshint/reporters/junit.rb', line 26 def report @output = <<-TEMPLATE <?xml version="1.0" encoding="UTF-8"?> <testsuites> <testsuite name="#{File.basename(Dir.pwd)}" timestamp="#{DateTime.now}"> TEMPLATE # Group according to the errors. error_groups = {} @results.each do |file, errors| errors.each do |error| next unless error && error['code'] error_groups[error['code']] ||= [] error_groups[error['code']] << { file: file, line: error['line'], character: error['character'], message: error['reason'] } end end # Combine all the errors and the tests for which we have messages. Combine both together. all_codes = error_groups.keys + TESTS.keys all_codes.each do |code| print_errors_for_code(code, error_groups.fetch(code, [])) end @output <<= <<-TEMPLATE </testsuite> </testsuites> TEMPLATE output end |