Class: SvgConform::Errors::ValidationIssue

Inherits:
Base
  • Object
show all
Defined in:
lib/svg_conform/errors/validation_issue.rb

Overview

Validation issue (error, warning, or notice)

Represents a single validation issue found during SVG validation. Contains information about the issue including type, rule, node, message, fix, and remediation information.

Instance Attribute Summary collapse

Attributes inherited from Base

#message, #node, #type

Instance Method Summary collapse

Constructor Details

#initialize(type:, rule:, node:, message:, fix: nil, data: {}, requirement_id: nil, severity: nil, violation_type: nil) ⇒ ValidationIssue

Returns a new instance of ValidationIssue.



16
17
18
19
20
21
22
23
24
25
# File 'lib/svg_conform/errors/validation_issue.rb', line 16

def initialize(type:, rule:, node:, message:, fix: nil, data: {},
requirement_id: nil, severity: nil, violation_type: nil)
  super(type: type, node: node, message: message)
  @rule = rule
  @fix = fix
  @data = data
  @requirement_id_override = requirement_id
  @severity = severity
  @violation_type = violation_type || detect_violation_type
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



13
14
15
# File 'lib/svg_conform/errors/validation_issue.rb', line 13

def data
  @data
end

#fixObject (readonly)

Returns the value of attribute fix.



13
14
15
# File 'lib/svg_conform/errors/validation_issue.rb', line 13

def fix
  @fix
end

#requirement_id_overrideObject (readonly)

Returns the value of attribute requirement_id_override.



13
14
15
# File 'lib/svg_conform/errors/validation_issue.rb', line 13

def requirement_id_override
  @requirement_id_override
end

#ruleObject (readonly)

Returns the value of attribute rule.



13
14
15
# File 'lib/svg_conform/errors/validation_issue.rb', line 13

def rule
  @rule
end

#severityObject (readonly)

Returns the value of attribute severity.



13
14
15
# File 'lib/svg_conform/errors/validation_issue.rb', line 13

def severity
  @severity
end

#violation_typeObject (readonly)

Returns the value of attribute violation_type.



13
14
15
# File 'lib/svg_conform/errors/validation_issue.rb', line 13

def violation_type
  @violation_type
end

Instance Method Details

#affects_content?Boolean

Check if this issue affects document content

Returns:

  • (Boolean)


150
151
152
153
154
155
156
157
158
159
# File 'lib/svg_conform/errors/validation_issue.rb', line 150

def affects_content?
  case @violation_type
  when :content_violation, :reference_violation
    true
  when :color_violation, :font_violation, :style_violation, :viewbox_violation, :namespace_violation
    false
  else
    false
  end
end

#apply_fixObject



66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/svg_conform/errors/validation_issue.rb', line 66

def apply_fix
  return false unless fixable?

  begin
    if @fix.respond_to?(:call)
      @fix.call
    else
      @fix.apply
    end
    true
  rescue StandardError
    false
  end
end

#columnObject



58
59
60
# File 'lib/svg_conform/errors/validation_issue.rb', line 58

def column
  @node.respond_to?(:column) ? @node.column : nil
end

#element_nameObject



62
63
64
# File 'lib/svg_conform/errors/validation_issue.rb', line 62

def element_name
  @node.respond_to?(:name) ? @node.name : nil
end

#error?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/svg_conform/errors/validation_issue.rb', line 42

def error?
  @type == :error
end

#fixable?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/svg_conform/errors/validation_issue.rb', line 50

def fixable?
  !@fix.nil?
end

#lineObject



54
55
56
# File 'lib/svg_conform/errors/validation_issue.rb', line 54

def line
  @node.respond_to?(:line) ? @node.line : nil
end

#remediable?Boolean

Check if this issue is remediable

Returns:

  • (Boolean)


82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/svg_conform/errors/validation_issue.rb', line 82

def remediable?
  case @violation_type
  when :color_violation, :font_violation, :content_violation, :reference_violation,
       :namespace_violation, :viewbox_violation, :style_violation
    true
  when :structural_violation
    false
  else
    # Default to remediable for backward compatibility
    true
  end
end

#remediation_confidenceObject

Get the confidence level of automated remediation



112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/svg_conform/errors/validation_issue.rb', line 112

def remediation_confidence
  case @violation_type
  when :color_violation, :font_violation, :style_violation
    :automatic
  when :viewbox_violation, :namespace_violation
    :safe_structural
  when :content_violation, :reference_violation
    :safe_removal
  else
    :manual_review
  end
end

#remediation_typeObject

Get the type of remediation needed



96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/svg_conform/errors/validation_issue.rb', line 96

def remediation_type
  case @violation_type
  when :color_violation, :font_violation
    :convert
  when :content_violation, :reference_violation, :namespace_violation
    :remove
  when :viewbox_violation
    :add
  when :style_violation
    :promote
  else
    :unknown
  end
end

#requirement_idObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/svg_conform/errors/validation_issue.rb', line 27

def requirement_id
  return @requirement_id_override.to_s if @requirement_id_override

  if @rule.respond_to?(:id)
    @rule.id.to_s
  elsif @rule.respond_to?(:class) && @rule.class.respond_to?(:name)
    # Extract ID from class name for requirements
    class_name = @rule.class.name.split("::").last
    class_name.gsub(/Requirement$/, "").downcase.gsub(/([a-z])([A-Z])/,
                                                      '\1_\2').downcase
  else
    "unknown"
  end
end

#suggested_actionObject

Get the suggested action to fix this issue



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/svg_conform/errors/validation_issue.rb', line 126

def suggested_action
  case @violation_type
  when :color_violation
    "Convert color to allowed equivalent using CssColor"
  when :font_violation
    "Map font family to generic equivalent"
  when :content_violation
    "Remove forbidden element or attribute"
  when :reference_violation
    "Remove broken reference or containing element"
  when :namespace_violation
    "Fix namespace declarations and remove invalid elements/attributes"
  when :viewbox_violation
    "Add missing viewBox attribute"
  when :style_violation
    "Promote style properties to attributes"
  when :structural_violation
    "Manual fix required - document structure issue"
  else
    "Apply available remediation"
  end
end

#to_hObject



161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/svg_conform/errors/validation_issue.rb', line 161

def to_h
  {
    type: @type,
    rule: rule_id,
    message: @message,
    line: line,
    column: column,
    element: element_name,
    fixable: fixable?,
    remediable: remediable?,
    violation_type: @violation_type,
    remediation_type: remediation_type,
    remediation_confidence: remediation_confidence,
    suggested_action: suggested_action,
    affects_content: affects_content?,
  }
end

#to_sObject



179
180
181
182
183
184
185
# File 'lib/svg_conform/errors/validation_issue.rb', line 179

def to_s
  location = line ? " at line #{line}" : ""
  location += ":#{column}" if column
  rule_info = rule_id ? " (#{rule_id})" : ""
  remediation_info = remediable? ? " [#{remediation_type}]" : " [NOT REMEDIABLE]"
  "#{@message}#{location}#{rule_info}#{remediation_info}"
end

#warning?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/svg_conform/errors/validation_issue.rb', line 46

def warning?
  @type == :warning
end