Module: Spoom::Sorbet::Errors

Defined in:
lib/spoom/sorbet/errors.rb

Defined Under Namespace

Classes: Error, Parser

Constant Summary collapse

DEFAULT_ERROR_URL_BASE =
"https://srb.help/"

Class Method Summary collapse

Class Method Details

.sort_errors_by_code(errors) ⇒ Object

: (Array errors) -> Array



13
14
15
# File 'lib/spoom/sorbet/errors.rb', line 13

def sort_errors_by_code(errors)
  errors.sort_by { |e| [e.code, e.file, e.line, e.message] }
end

.to_junit_xml(errors) ⇒ Object

: (Array) -> REXML::Document



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/spoom/sorbet/errors.rb', line 18

def to_junit_xml(errors)
  testsuite_element = REXML::Element.new("testsuite")
  testsuite_element.add_attributes(
    "name" => "Sorbet",
    "failures" => errors.size,
  )

  if errors.empty?
    # Avoid creating an empty report when there are no errors so that
    # reporting tools know that the type checking ran successfully.
    testcase_element = testsuite_element.add_element("testcase")
    testcase_element.add_attributes(
      "name" => "Typecheck",
      "tests" => 1,
    )
  else
    errors.each do |error|
      testsuite_element.add_element(error.to_junit_xml_element)
    end
  end

  doc = REXML::Document.new
  doc << REXML::XMLDecl.new
  doc.add_element(testsuite_element)

  doc
end