Pentiment.Report (pentiment v0.1.5)

A ready-to-use diagnostic struct with a builder API.

Report is the default implementation of Pentiment.Diagnostic and provides a convenient builder pattern for constructing diagnostics incrementally.

Examples

# Simple error
Pentiment.Report.error("Unexpected token")
|> Pentiment.Report.with_code("PARSE001")
|> Pentiment.Report.with_source("input.txt")
|> Pentiment.Report.with_label(Pentiment.Label.primary(span, "here"))

# Warning with multiple labels and help
Pentiment.Report.warning("Unused variable `x`")
|> Pentiment.Report.with_labels([
  Pentiment.Label.primary(def_span, "defined here"),
  Pentiment.Label.secondary(scope_span, "in this scope")
])
|> Pentiment.Report.with_help("prefix with underscore: `_x`")

Builder Functions

All with_* functions return the modified report, allowing for chaining:

Summary

Functions

Creates a new report with the given severity and message.

Creates an error report.

Creates a hint report.

Creates an info report.

Creates a warning report.

Sets the error code.

Adds a help message.

Adds a single label.

Adds multiple labels.

Sets the primary source identifier.

Types

severity()

@type severity() :: :error | :warning | :info | :hint

t()

@type t() :: %Pentiment.Report{
  code: String.t() | nil,
  help: [String.t()],
  labels: [Pentiment.Label.t()],
  message: String.t(),
  notes: [String.t()],
  severity: severity(),
  source: String.t() | nil
}

Functions

build(severity, message)

@spec build(severity(), String.t()) :: t()

Creates a new report with the given severity and message.

Examples

iex> Pentiment.Report.build(:error, "Something went wrong")
%Pentiment.Report{severity: :error, message: "Something went wrong"}

error(message)

@spec error(String.t()) :: t()

Creates an error report.

Examples

iex> Pentiment.Report.error("Type mismatch")
%Pentiment.Report{severity: :error, message: "Type mismatch"}

hint(message)

@spec hint(String.t()) :: t()

Creates a hint report.

Examples

iex> Pentiment.Report.hint("Consider using pattern matching")
%Pentiment.Report{severity: :hint, message: "Consider using pattern matching"}

info(message)

@spec info(String.t()) :: t()

Creates an info report.

Examples

iex> Pentiment.Report.info("Compiling module")
%Pentiment.Report{severity: :info, message: "Compiling module"}

warning(message)

@spec warning(String.t()) :: t()

Creates a warning report.

Examples

iex> Pentiment.Report.warning("Unused variable")
%Pentiment.Report{severity: :warning, message: "Unused variable"}

with_code(report, code)

@spec with_code(t(), String.t()) :: t()

Sets the error code.

Examples

iex> report |> Pentiment.Report.with_code("E0001")

with_help(report, message)

@spec with_help(t(), String.t()) :: t()

Adds a help message.

Examples

iex> report |> Pentiment.Report.with_help("Try using `trunc/1`")

with_label(report, label)

@spec with_label(t(), Pentiment.Label.t()) :: t()

Adds a single label.

Examples

iex> report |> Pentiment.Report.with_label(Label.primary(span, "error here"))

with_labels(report, new_labels)

@spec with_labels(t(), [Pentiment.Label.t()]) :: t()

Adds multiple labels.

Examples

iex> report |> Pentiment.Report.with_labels([
...>   Label.secondary(decl_span, "declared here"),
...>   Label.primary(use_span, "used here")
...> ])

with_note(report, message)

@spec with_note(t(), String.t()) :: t()

Adds a note.

Examples

iex> report |> Pentiment.Report.with_note("Function expects integer arguments")

with_source(report, source)

@spec with_source(t(), String.t()) :: t()

Sets the primary source identifier.

Examples

iex> report |> Pentiment.Report.with_source("lib/my_app.ex")