Class: Lilac::CLI::LintWarning

Inherits:
Object
  • Object
show all
Defined in:
lib/lilac/cli/lint/lint_warning.rb

Overview

Value object for a single cross-reference lint warning. Centralises the multi-line format so all current and future warning kinds (signal-not-declared, method-not-defined, future dead-signal, ...) render identically:

lilac: lint warning in <file>:<line>
<body>
<declared_label>: a, b, c.
Did you mean: <suggestion>?

declared and suggestion are optional — when empty/nil the corresponding lines are omitted so single-fact warnings stay compact.

suggestion is rendered verbatim as an indented bullet — callers add their own framing ("Did you mean: ..." / "Use ..." / etc.) so the same warning shape carries both typo hints and corrective advice.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(at:, body:, declared_label: nil, declared: [], suggestion: nil, severity: :warning) ⇒ LintWarning

severity: is :warning (default — non-fatal, build continues) or :error (fatal — build fails with non-zero exit code). Errors are reserved for violations that runtime would raise (so the build/runtime severity stays aligned).



28
29
30
31
32
33
34
35
# File 'lib/lilac/cli/lint/lint_warning.rb', line 28

def initialize(at:, body:, declared_label: nil, declared: [], suggestion: nil, severity: :warning)
  @at = at
  @body = body
  @declared_label = declared_label
  @declared = declared
  @suggestion = suggestion
  @severity = severity
end

Instance Attribute Details

#severityObject (readonly)

Returns the value of attribute severity.



37
38
39
# File 'lib/lilac/cli/lint/lint_warning.rb', line 37

def severity
  @severity
end

Instance Method Details

#error?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/lilac/cli/lint/lint_warning.rb', line 39

def error?
  @severity == :error
end

#to_sObject



43
44
45
46
47
48
49
50
# File 'lib/lilac/cli/lint/lint_warning.rb', line 43

def to_s
  label = error? ? "lint error" : "lint warning"
  parts = ["lilac: #{label} in #{@at}"]
  @body.to_s.each_line { |l| parts << "  #{l.chomp}" }
  parts << "  #{@declared_label}: #{@declared.join(', ')}." if @declared_label && !@declared.empty?
  parts << "  #{@suggestion}" if @suggestion
  parts.join("\n")
end