Class: ArchSpec::Diagnostic
- Inherits:
-
Object
- Object
- ArchSpec::Diagnostic
- Defined in:
- lib/archspec/diagnostic.rb
Overview
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.
Instance Attribute Summary collapse
-
#confidence ⇒ Object
readonly
Returns the value of attribute confidence.
-
#evidence ⇒ Object
readonly
Returns the value of attribute evidence.
-
#location ⇒ Object
readonly
Returns the value of attribute location.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#reason ⇒ Object
readonly
Returns the value of attribute reason.
-
#rule ⇒ Object
readonly
Returns the value of attribute rule.
Instance Method Summary collapse
-
#fingerprint(root: nil) ⇒ Object
Line numbers stay out of the fingerprint so todo entries survive edits that only shift code around.
-
#initialize(rule:, message:, location:, evidence:, confidence: :high, reason: nil) ⇒ Diagnostic
constructor
A new instance of Diagnostic.
- #to_h(root:) ⇒ Object
- #with_reason(reason) ⇒ Object
Constructor Details
#initialize(rule:, message:, location:, evidence:, confidence: :high, reason: nil) ⇒ Diagnostic
Returns a new instance of Diagnostic.
13 14 15 16 17 18 19 20 |
# File 'lib/archspec/diagnostic.rb', line 13 def initialize(rule:, message:, location:, evidence:, confidence: :high, reason: nil) @rule = rule @message = @location = location @evidence = evidence @confidence = confidence @reason = reason end |
Instance Attribute Details
#confidence ⇒ Object (readonly)
Returns the value of attribute confidence.
11 12 13 |
# File 'lib/archspec/diagnostic.rb', line 11 def confidence @confidence end |
#evidence ⇒ Object (readonly)
Returns the value of attribute evidence.
11 12 13 |
# File 'lib/archspec/diagnostic.rb', line 11 def evidence @evidence end |
#location ⇒ Object (readonly)
Returns the value of attribute location.
11 12 13 |
# File 'lib/archspec/diagnostic.rb', line 11 def location @location end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
11 12 13 |
# File 'lib/archspec/diagnostic.rb', line 11 def @message end |
#reason ⇒ Object (readonly)
Returns the value of attribute reason.
11 12 13 |
# File 'lib/archspec/diagnostic.rb', line 11 def reason @reason end |
#rule ⇒ Object (readonly)
Returns the value of attribute rule.
11 12 13 |
# File 'lib/archspec/diagnostic.rb', line 11 def rule @rule end |
Instance Method Details
#fingerprint(root: nil) ⇒ Object
Line numbers stay out of the fingerprint so todo entries survive edits that only shift code around.
37 38 39 40 41 42 43 |
# File 'lib/archspec/diagnostic.rb', line 37 def fingerprint(root: nil) path = root ? location.relative_path(root) : location.path Digest::SHA256.hexdigest( [rule, , path, evidence].join("\0") )[0, 24] end |
#to_h(root:) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/archspec/diagnostic.rb', line 45 def to_h(root:) hash = { id: fingerprint(root: root), rule: rule, 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 |
#with_reason(reason) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/archspec/diagnostic.rb', line 22 def with_reason(reason) return self unless reason self.class.new( rule: rule, message: , location: location, evidence: evidence, confidence: confidence, reason: reason ) end |