Class: Ibex::RaccMigration::Report

Inherits:
Object
  • Object
show all
Defined in:
lib/ibex/racc_migration/report.rb,
sig/ibex/racc_migration/report.rbs

Overview

Versioned result of checking one grammar without executing its code.

Constant Summary collapse

SCHEMA_VERSION =

Signature:

  • Integer

Returns:

  • (Integer)
1

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file:, class_name:, findings:) ⇒ Report

Returns a new instance of Report.

RBS:

  • (file: String, class_name: String?, findings: Array[Finding]) -> void

Parameters:

  • file: (String)
  • class_name: (String, nil)
  • findings: (Array[Finding])


54
55
56
57
58
59
# File 'lib/ibex/racc_migration/report.rb', line 54

def initialize(file:, class_name:, findings:)
  @file = file.dup.freeze
  @class_name = class_name&.dup&.freeze
  @findings = findings.dup.freeze
  freeze
end

Instance Attribute Details

#class_nameString? (readonly)

Signature:

  • String?

Returns:

  • (String, nil)


50
51
52
# File 'lib/ibex/racc_migration/report.rb', line 50

def class_name
  @class_name
end

#fileString (readonly)

Signature:

  • String

Returns:

  • (String)


49
50
51
# File 'lib/ibex/racc_migration/report.rb', line 49

def file
  @file
end

#findingsArray[Finding] (readonly)

Signature:

  • Array[Finding]

Returns:



51
52
53
# File 'lib/ibex/racc_migration/report.rb', line 51

def findings
  @findings
end

Instance Method Details

#compatible?Boolean

RBS:

  • () -> bool

Returns:

  • (Boolean)


62
# File 'lib/ibex/racc_migration/report.rb', line 62

def compatible? = @findings.none? { |finding| finding.severity == :error }

#to_hHash[String, untyped]

RBS:

  • () -> Hash[String, untyped]

Returns:

  • (Hash[String, untyped])


65
66
67
68
69
70
71
72
73
74
# File 'lib/ibex/racc_migration/report.rb', line 65

def to_h
  {
    "ibex_migration_check" => "racc",
    "schema_version" => SCHEMA_VERSION,
    "compatible" => compatible?,
    "file" => @file,
    "class_name" => @class_name,
    "findings" => @findings.map(&:to_h)
  }
end

#to_jsonString

RBS:

  • (*untyped) -> String

Parameters:

  • (Object)

Returns:

  • (String)


77
# File 'lib/ibex/racc_migration/report.rb', line 77

def to_json(*) = JSON.pretty_generate(to_h)

#to_textString

RBS:

  • () -> String

Returns:

  • (String)


80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/ibex/racc_migration/report.rb', line 80

def to_text
  return "#{@file}: compatible with the checked racc migration surface\n" if @findings.empty?

  lines = @findings.flat_map do |finding|
    prefix = finding.location ? finding.location.to_s : "#{@file}:1:1"
    [
      "#{prefix}: #{finding.severity}: #{finding.message} [#{finding.code}]",
      "  suggestion: #{finding.suggestion}"
    ]
  end
  "#{lines.join("\n")}\n"
end