Class: Oxc::Diagnostic

Inherits:
Object
  • Object
show all
Defined in:
lib/oxc/diagnostic.rb,
sig/oxc/diagnostic.rbs

Constant Summary collapse

ERROR =

Signature:

  • String

Returns:

  • (String)
"error"
WARNING =

Signature:

  • String

Returns:

  • (String)
"warning"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(severity:, message:, labels:, help: nil, codeframe: nil) ⇒ Diagnostic

: (severity: String, message: String, labels: Array, ?help: String?, ?codeframe: String?) -> void

Parameters:

  • severity: (String)
  • message: (String)
  • labels: (Array[Oxc::Label])
  • help: (String, nil) (defaults to: nil)
  • codeframe: (String, nil) (defaults to: nil)


26
27
28
29
30
31
32
33
34
# File 'lib/oxc/diagnostic.rb', line 26

def initialize(severity:, message:, labels:, help: nil, codeframe: nil)
  @severity = severity
  @message = message
  @labels = labels.freeze
  @help = help
  @codeframe = codeframe

  freeze
end

Instance Attribute Details

#codeframeString? (readonly)

Signature:

  • String?

Returns:

  • (String, nil)


12
13
14
# File 'lib/oxc/diagnostic.rb', line 12

def codeframe
  @codeframe
end

#helpString? (readonly)

Signature:

  • String?

Returns:

  • (String, nil)


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

def help
  @help
end

#labelsArray[Oxc::Label] (readonly)

Signature:

  • Array[Oxc::Label]

Returns:



10
11
12
# File 'lib/oxc/diagnostic.rb', line 10

def labels
  @labels
end

#messageString (readonly)

Signature:

  • String

Returns:

  • (String)


9
10
11
# File 'lib/oxc/diagnostic.rb', line 9

def message
  @message
end

#severityString (readonly)

Signature:

  • String

Returns:

  • (String)


8
9
10
# File 'lib/oxc/diagnostic.rb', line 8

def severity
  @severity
end

Class Method Details

.from_hash(parsed) ⇒ Oxc::Diagnostic

: (Hash[String, untyped]) -> Oxc::Diagnostic

Parameters:

  • (Hash[String, untyped])

Returns:



15
16
17
18
19
20
21
22
23
# File 'lib/oxc/diagnostic.rb', line 15

def self.from_hash(parsed)
  new(
    severity: parsed.fetch("severity"),
    message: parsed.fetch("message"),
    labels: parsed.fetch("labels").map { |label| Label.from_hash(label) },
    help: parsed["help"],
    codeframe: parsed["codeframe"]
  )
end

Instance Method Details

#error?Boolean

: () -> bool

Returns:

  • (Boolean)


37
38
39
# File 'lib/oxc/diagnostic.rb', line 37

def error?
  severity == ERROR
end

#inspectString

: () -> String

Returns:

  • (String)


52
53
54
# File 'lib/oxc/diagnostic.rb', line 52

def inspect
  "#<#{self.class.name} #{severity} #{message.inspect}>"
end

#to_sString

: () -> String

Returns:

  • (String)


47
48
49
# File 'lib/oxc/diagnostic.rb', line 47

def to_s
  message
end

#warning?Boolean

: () -> bool

Returns:

  • (Boolean)


42
43
44
# File 'lib/oxc/diagnostic.rb', line 42

def warning?
  severity == WARNING
end