Class: Rigor::Analysis::Diagnostic

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

Constant Summary collapse

DEFAULT_SOURCE_FAMILY =

The default source family. Matches the existing analyzer- internal rule families; serialised as ‘“builtin”` and is the baseline against which non-default families are recognised.

:builtin

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path:, line:, column:, message:, severity: :error, rule: nil, source_family: DEFAULT_SOURCE_FAMILY) ⇒ Diagnostic

‘rule:` is the stable identifier (a kebab-case string) of the diagnostic’s source rule. It is used by the configuration and the in-source ‘# rigor:disable <rule>` suppression comment system to identify diagnostics by category. Diagnostics not produced by `CheckRules` (parse errors, path errors, internal analyzer errors) may leave `rule` as nil and stay unsuppressible.

‘source_family:` names the producer of the rule. The default `:builtin` covers analyzer-internal rules; future families like `:rbs_extended`, `:generated`, or `“plugin.<id>”` (per ADR-2 § “Plugin Diagnostic Provenance”) let consumers distinguish where a diagnostic originated without committing to the plugin API itself. rubocop:disable Metrics/ParameterLists



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/rigor/analysis/diagnostic.rb', line 28

def initialize(path:, line:, column:, message:, severity: :error, rule: nil,
               source_family: DEFAULT_SOURCE_FAMILY)
  # rubocop:enable Metrics/ParameterLists
  @path = path
  @line = line
  @column = column
  @message = message
  @severity = severity
  @rule = rule
  @source_family = source_family
end

Instance Attribute Details

#columnObject (readonly)

Returns the value of attribute column.



11
12
13
# File 'lib/rigor/analysis/diagnostic.rb', line 11

def column
  @column
end

#lineObject (readonly)

Returns the value of attribute line.



11
12
13
# File 'lib/rigor/analysis/diagnostic.rb', line 11

def line
  @line
end

#messageObject (readonly)

Returns the value of attribute message.



11
12
13
# File 'lib/rigor/analysis/diagnostic.rb', line 11

def message
  @message
end

#pathObject (readonly)

Returns the value of attribute path.



11
12
13
# File 'lib/rigor/analysis/diagnostic.rb', line 11

def path
  @path
end

#ruleObject (readonly)

Returns the value of attribute rule.



11
12
13
# File 'lib/rigor/analysis/diagnostic.rb', line 11

def rule
  @rule
end

#severityObject (readonly)

Returns the value of attribute severity.



11
12
13
# File 'lib/rigor/analysis/diagnostic.rb', line 11

def severity
  @severity
end

#source_familyObject (readonly)

Returns the value of attribute source_family.



11
12
13
# File 'lib/rigor/analysis/diagnostic.rb', line 11

def source_family
  @source_family
end

Instance Method Details

#error?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/rigor/analysis/diagnostic.rb', line 40

def error?
  severity == :error
end

#qualified_ruleObject

The fully-qualified rule identifier — ‘<source_family>.<rule>` when the source is non-default, or just `<rule>` for the `:builtin` family. Returns nil when `rule` itself is nil (e.g. parse errors and internal-analyzer errors).



48
49
50
51
52
53
# File 'lib/rigor/analysis/diagnostic.rb', line 48

def qualified_rule
  return nil if rule.nil?
  return rule if source_family == DEFAULT_SOURCE_FAMILY

  "#{source_family}.#{rule}"
end

#to_hObject



55
56
57
58
59
60
61
62
63
64
65
# File 'lib/rigor/analysis/diagnostic.rb', line 55

def to_h
  {
    "path" => path,
    "line" => line,
    "column" => column,
    "severity" => severity.to_s,
    "rule" => rule,
    "source_family" => source_family.to_s,
    "message" => message
  }
end

#to_sObject



67
68
69
# File 'lib/rigor/analysis/diagnostic.rb', line 67

def to_s
  "#{path}:#{line}:#{column}: #{severity}: #{message}"
end