Class: Rigor::FlowContribution::Conflict

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

rubocop:disable Metrics/ParameterLists



32
33
34
35
36
37
38
39
40
41
# File 'lib/rigor/flow_contribution/conflict.rb', line 32

def initialize(target:, edge:, kind:, reason:, provenances:, message:) # rubocop:disable Metrics/ParameterLists
  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 Attribute Details

#edgeObject (readonly)

Returns the value of attribute edge

Returns:

  • (Object)

    the current value of edge



31
32
33
# File 'lib/rigor/flow_contribution/conflict.rb', line 31

def edge
  @edge
end

#kindObject (readonly)

Returns the value of attribute kind

Returns:

  • (Object)

    the current value of kind



31
32
33
# File 'lib/rigor/flow_contribution/conflict.rb', line 31

def kind
  @kind
end

#messageObject (readonly)

Returns the value of attribute message

Returns:

  • (Object)

    the current value of message



31
32
33
# File 'lib/rigor/flow_contribution/conflict.rb', line 31

def message
  @message
end

#provenancesObject (readonly)

Returns the value of attribute provenances

Returns:

  • (Object)

    the current value of provenances



31
32
33
# File 'lib/rigor/flow_contribution/conflict.rb', line 31

def provenances
  @provenances
end

#reasonObject (readonly)

Returns the value of attribute reason

Returns:

  • (Object)

    the current value of reason



31
32
33
# File 'lib/rigor/flow_contribution/conflict.rb', line 31

def reason
  @reason
end

#targetObject (readonly)

Returns the value of attribute target

Returns:

  • (Object)

    the current value of target



31
32
33
# File 'lib/rigor/flow_contribution/conflict.rb', line 31

def target
  @target
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_collapse` →`return-type-collapse`, etc.) so the qualified rule reads `[contribution_merge.return-type-collapse]` in the standard text stream.



67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/rigor/flow_contribution/conflict.rb', line 67

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



43
44
45
46
47
48
49
50
51
52
# File 'lib/rigor/flow_contribution/conflict.rb', line 43

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