Class: Rigor::FlowContribution::Conflict

Inherits:
Object
  • Object
show all
Defined in:
lib/rigor/flow_contribution/conflict.rb

Instance Method Summary collapse

Constructor Details

#initialize(target:, edge:, kind:, reason:, provenances:, message:) ⇒ Conflict

Returns a new instance of Conflict.



26
27
28
29
30
31
32
33
34
35
# File 'lib/rigor/flow_contribution/conflict.rb', line 26

def initialize(target:, edge:, kind:, reason:, provenances:, message:)
  unless CONFLICT_VALID_REASONS.include?(reason)
    raise ArgumentError,
          "FlowContribution::Conflict reason must be one of " \
          "#{CONFLICT_VALID_REASONS.inspect}, got #{reason.inspect}"
  end

  super(target: target, edge: edge, kind: kind, reason: reason,
        provenances: provenances.dup.freeze, message: message.to_s.dup.freeze)
end

Instance Method Details

#to_diagnostic(path:, line:, column:, severity: :error) ⇒ Object

ADR-7 § "Slice 5-C" — converts the conflict into a Rigor::Analysis::Diagnostic for the run result. Carries source_family: :contribution_merge so the qualified-rule formatter (slice 5 formatter half, ef730b2) prefixes the rule id with contribution_merge. and the JSON output side-bands source_family + rule for plugin attribution.

The rule identifier is the kebab-case form of the conflict reason (return_type_collapsereturn-type-collapse, etc.) so the qualified rule reads [contribution_merge.return-type-collapse] in the standard text stream.



56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/rigor/flow_contribution/conflict.rb', line 56

def to_diagnostic(path:, line:, column:, severity: :error)
  require_relative "../analysis/diagnostic" unless defined?(Rigor::Analysis::Diagnostic)
  Rigor::Analysis::Diagnostic.new(
    path: path,
    line: line,
    column: column,
    message: message,
    severity: severity,
    rule: reason.to_s.tr("_", "-"),
    source_family: :contribution_merge
  )
end

#to_hObject



37
38
39
40
41
42
43
44
45
46
# File 'lib/rigor/flow_contribution/conflict.rb', line 37

def to_h
  {
    "target" => target.to_s,
    "edge" => edge.to_s,
    "kind" => kind.to_s,
    "reason" => reason.to_s,
    "sources" => provenances.map { |p| p.respond_to?(:to_h) ? p.to_h : p.to_s },
    "message" => message
  }
end