Class: RedQuilt::Diagnostic

Inherits:
Object
  • Object
show all
Defined in:
lib/red_quilt/diagnostic.rb

Overview

A single warning / error raised while parsing or rendering a document. Diagnostics are collected on the Document and never interrupt processing — every parse / render call still produces a tree and HTML, even if it emitted diagnostics along the way.

severity: :info / :warning / :error rule: a short Symbol identifying the rule (e.g. :unsafe_url,

:missing_reference) so callers can filter / silence

message: human-readable explanation source_span: optional SourceSpan, points at the offending byte range

Constant Summary collapse

SEVERITIES =
%i[info warning error].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(severity:, rule:, message:, source_span: nil) ⇒ Diagnostic

Returns a new instance of Diagnostic.



19
20
21
22
23
24
25
26
27
28
# File 'lib/red_quilt/diagnostic.rb', line 19

def initialize(severity:, rule:, message:, source_span: nil)
  unless SEVERITIES.include?(severity)
    raise ArgumentError, "unknown severity: #{severity.inspect}"
  end

  @severity = severity
  @rule = rule
  @message = message
  @source_span = source_span
end

Instance Attribute Details

#messageObject (readonly)

Returns the value of attribute message.



17
18
19
# File 'lib/red_quilt/diagnostic.rb', line 17

def message
  @message
end

#ruleObject (readonly)

Returns the value of attribute rule.



17
18
19
# File 'lib/red_quilt/diagnostic.rb', line 17

def rule
  @rule
end

#severityObject (readonly)

Returns the value of attribute severity.



17
18
19
# File 'lib/red_quilt/diagnostic.rb', line 17

def severity
  @severity
end

#source_spanObject (readonly)

Returns the value of attribute source_span.



17
18
19
# File 'lib/red_quilt/diagnostic.rb', line 17

def source_span
  @source_span
end

Instance Method Details

#==(other) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/red_quilt/diagnostic.rb', line 39

def ==(other)
  other.is_a?(Diagnostic) &&
    other.severity == severity &&
    other.rule == rule &&
    other.message == message &&
    other.source_span == source_span
end

#to_hObject



30
31
32
33
34
35
36
37
# File 'lib/red_quilt/diagnostic.rb', line 30

def to_h
  {
    severity: severity,
    rule: rule,
    message: message,
    source_span: source_span && { start_byte: source_span.start_byte, end_byte: source_span.end_byte },
  }
end