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:
with_code/2- Set an error codewith_source/2- Set the primary sourcewith_label/2- Add a single labelwith_labels/2- Add multiple labelswith_help/2- Add a help messagewith_note/2- Add a note
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.
Adds a note.
Sets the primary source identifier.
Types
Functions
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"}
Creates an error report.
Examples
iex> Pentiment.Report.error("Type mismatch")
%Pentiment.Report{severity: :error, message: "Type mismatch"}
Creates a hint report.
Examples
iex> Pentiment.Report.hint("Consider using pattern matching")
%Pentiment.Report{severity: :hint, message: "Consider using pattern matching"}
Creates an info report.
Examples
iex> Pentiment.Report.info("Compiling module")
%Pentiment.Report{severity: :info, message: "Compiling module"}
Creates a warning report.
Examples
iex> Pentiment.Report.warning("Unused variable")
%Pentiment.Report{severity: :warning, message: "Unused variable"}
Sets the error code.
Examples
iex> report |> Pentiment.Report.with_code("E0001")
Adds a help message.
Examples
iex> report |> Pentiment.Report.with_help("Try using `trunc/1`")
@spec with_label(t(), Pentiment.Label.t()) :: t()
Adds a single label.
Examples
iex> report |> Pentiment.Report.with_label(Label.primary(span, "error here"))
@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")
...> ])
Adds a note.
Examples
iex> report |> Pentiment.Report.with_note("Function expects integer arguments")
Sets the primary source identifier.
Examples
iex> report |> Pentiment.Report.with_source("lib/my_app.ex")