Class: Herb::Embedded::Diagnostic
- Inherits:
-
Object
- Object
- Herb::Embedded::Diagnostic
- Defined in:
- lib/herb/embedded/diagnostic.rb
Overview
A single lint offense. Shaped to match upstream Herb::Diagnostic / Herb::LintOffense (marcoroth/herb#455, unmerged): #to_h's key set mirrors that class's #to_h exactly, so this drops into its socket without rewriting every consumer if/when that PR lands. #file, #line, #column, and #correctable? are this gem's own convenience accessors on top of that shape — upstream has no per-file scope (a single Herb.lint call is per-source) and derives correctability from a rule's static autocorrectable flag rather than a reader.
Constant Summary collapse
- SEVERITIES =
%i[error warning info hint].freeze
- DEFAULT_SEVERITY =
:error
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#location ⇒ Object
readonly
Returns the value of attribute location.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#rule ⇒ Object
readonly
Returns the value of attribute rule.
-
#severity ⇒ Object
readonly
Returns the value of attribute severity.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Class Method Summary collapse
-
.from_js(hash, file:) ⇒ Object
rubocop:enable Metrics/ParameterLists.
Instance Method Summary collapse
- #column ⇒ Object
- #correctable? ⇒ Boolean
-
#initialize(file:, rule:, message:, severity:, location:, code: nil, source: nil, correctable: false) ⇒ Diagnostic
constructor
rubocop:disable Metrics/ParameterLists -- value object, one flat field per keyword.
- #line ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(file:, rule:, message:, severity:, location:, code: nil, source: nil, correctable: false) ⇒ Diagnostic
rubocop:disable Metrics/ParameterLists -- value object, one flat field per keyword
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/herb/embedded/diagnostic.rb', line 20 def initialize(file:, rule:, message:, severity:, location:, code: nil, source: nil, correctable: false) @file = file @rule = rule @message = @severity = SEVERITIES.include?(severity) ? severity : DEFAULT_SEVERITY @location = location @code = code @source = source @correctable = correctable end |
Instance Attribute Details
#code ⇒ Object (readonly)
Returns the value of attribute code.
17 18 19 |
# File 'lib/herb/embedded/diagnostic.rb', line 17 def code @code end |
#file ⇒ Object (readonly)
Returns the value of attribute file.
17 18 19 |
# File 'lib/herb/embedded/diagnostic.rb', line 17 def file @file end |
#location ⇒ Object (readonly)
Returns the value of attribute location.
17 18 19 |
# File 'lib/herb/embedded/diagnostic.rb', line 17 def location @location end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
17 18 19 |
# File 'lib/herb/embedded/diagnostic.rb', line 17 def @message end |
#rule ⇒ Object (readonly)
Returns the value of attribute rule.
17 18 19 |
# File 'lib/herb/embedded/diagnostic.rb', line 17 def rule @rule end |
#severity ⇒ Object (readonly)
Returns the value of attribute severity.
17 18 19 |
# File 'lib/herb/embedded/diagnostic.rb', line 17 def severity @severity end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
17 18 19 |
# File 'lib/herb/embedded/diagnostic.rb', line 17 def source @source end |
Class Method Details
.from_js(hash, file:) ⇒ Object
rubocop:enable Metrics/ParameterLists
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/herb/embedded/diagnostic.rb', line 32 def self.from_js(hash, file:) new( file: file, rule: hash["rule"], message: hash["message"], severity: hash["severity"]&.to_sym, location: hash["location"], code: hash["code"], source: hash["source"], correctable: !hash["autofixContext"].nil?, ) end |
Instance Method Details
#column ⇒ Object
49 50 51 |
# File 'lib/herb/embedded/diagnostic.rb', line 49 def column location&.dig("start", "column") end |
#correctable? ⇒ Boolean
53 54 55 |
# File 'lib/herb/embedded/diagnostic.rb', line 53 def correctable? @correctable end |
#line ⇒ Object
45 46 47 |
# File 'lib/herb/embedded/diagnostic.rb', line 45 def line location&.dig("start", "line") end |
#to_h ⇒ Object
57 58 59 60 61 62 63 64 65 66 |
# File 'lib/herb/embedded/diagnostic.rb', line 57 def to_h { message: , location: location, severity: severity, code: code, source: source, rule: rule, } end |