Class: TRuby::ErrorReporter
- Inherits:
-
Object
- Object
- TRuby::ErrorReporter
- Defined in:
- lib/t_ruby/error_reporter.rb
Instance Attribute Summary collapse
-
#diagnostics ⇒ Object
readonly
Returns the value of attribute diagnostics.
Instance Method Summary collapse
- #add(diagnostic) ⇒ Object
- #add_parse_error(error, file:, source: nil) ⇒ Object
- #add_scan_error(error, file:, source: nil) ⇒ Object
- #add_type_check_error(error, file:, source: nil) ⇒ Object
- #clear ⇒ Object
- #error_count ⇒ Object
- #has_errors? ⇒ Boolean
-
#initialize(formatter: nil) ⇒ ErrorReporter
constructor
A new instance of ErrorReporter.
- #report ⇒ Object
Constructor Details
#initialize(formatter: nil) ⇒ ErrorReporter
Returns a new instance of ErrorReporter.
7 8 9 10 11 |
# File 'lib/t_ruby/error_reporter.rb', line 7 def initialize(formatter: nil) @diagnostics = [] @formatter = formatter || DiagnosticFormatter.new @source_cache = {} end |
Instance Attribute Details
#diagnostics ⇒ Object (readonly)
Returns the value of attribute diagnostics.
5 6 7 |
# File 'lib/t_ruby/error_reporter.rb', line 5 def diagnostics @diagnostics end |
Instance Method Details
#add(diagnostic) ⇒ Object
13 14 15 |
# File 'lib/t_ruby/error_reporter.rb', line 13 def add(diagnostic) @diagnostics << diagnostic end |
#add_parse_error(error, file:, source: nil) ⇒ Object
22 23 24 25 |
# File 'lib/t_ruby/error_reporter.rb', line 22 def add_parse_error(error, file:, source: nil) source ||= load_source(file) add(Diagnostic.from_parse_error(error, file: file, source: source)) end |
#add_scan_error(error, file:, source: nil) ⇒ Object
27 28 29 30 |
# File 'lib/t_ruby/error_reporter.rb', line 27 def add_scan_error(error, file:, source: nil) source ||= load_source(file) add(Diagnostic.from_scan_error(error, file: file, source: source)) end |
#add_type_check_error(error, file:, source: nil) ⇒ Object
17 18 19 20 |
# File 'lib/t_ruby/error_reporter.rb', line 17 def add_type_check_error(error, file:, source: nil) source ||= load_source(file) add(Diagnostic.from_type_check_error(error, file: file, source: source)) end |
#clear ⇒ Object
44 45 46 47 |
# File 'lib/t_ruby/error_reporter.rb', line 44 def clear @diagnostics.clear @source_cache.clear end |
#error_count ⇒ Object
36 37 38 |
# File 'lib/t_ruby/error_reporter.rb', line 36 def error_count @diagnostics.count { |d| d.severity == Diagnostic::SEVERITY_ERROR } end |
#has_errors? ⇒ Boolean
32 33 34 |
# File 'lib/t_ruby/error_reporter.rb', line 32 def has_errors? @diagnostics.any? { |d| d.severity == Diagnostic::SEVERITY_ERROR } end |
#report ⇒ Object
40 41 42 |
# File 'lib/t_ruby/error_reporter.rb', line 40 def report @formatter.format_all(@diagnostics) end |