class ArchSpec::Diagnostic
One reported violation: the rule id, a message, the source location, the evidence ArchSpec found, and a confidence. Formatters and the todo file read these. Its fingerprint is the stable id used to match todo entries and suppress specific findings.
Attributes
Public Class Methods
# File lib/archspec/diagnostic.rb, line 13 def initialize(rule:, message:, location:, evidence:, confidence: :high, reason: nil) @rule = rule @message = message @location = location @evidence = evidence @confidence = confidence @reason = reason end
Public Instance Methods
Source
# File lib/archspec/diagnostic.rb, line 37 def fingerprint(root: nil) path = root ? location.relative_path(root) : location.path Digest::SHA256.hexdigest( [rule, message, path, evidence].join("\0") )[0, 24] end
Line numbers stay out of the fingerprint so todo entries survive edits that only shift code around.
Source
# File lib/archspec/diagnostic.rb, line 45 def to_h(root:) hash = { id: fingerprint(root: root), rule: rule, message: message, path: location.relative_path(root), line: location.line, column: location.column, end_line: location.end_line, end_column: location.end_column, evidence: evidence, confidence: confidence.to_s } hash[:reason] = reason if reason hash end
Source
# File lib/archspec/diagnostic.rb, line 22 def with_reason(reason) return self unless reason self.class.new( rule: rule, message: message, location: location, evidence: evidence, confidence: confidence, reason: reason ) end