# `OXC.Diagnostic`
[🔗](https://github.com/elixir-volt/oxc_ex/blob/v0.19.0/lib/oxc/diagnostic.ex#L1)

Errors and lint findings as Elixir `t:Code.diagnostic/1` maps.

Every OXC error and lint finding uses this shape:

    %{
      file: "app.ts",
      severity: :error,
      message: "Unexpected token",
      position: {2, 11},
      span: {2, 12},
      source: nil,
      stacktrace: []
    }

`position` is the 1-based `{line, column}` where the problem starts and `span`
is where it ends, with columns counted in characters. Diagnostics without a
source location use `position: 0` and `span: nil`, as Elixir does.

Some diagnostics carry extra keys:

  * `:details` — help text suggesting a fix
  * `:rule` — the lint rule that reported the finding
  * `:labels` — secondary locations, each with `:position`, `:span`, and `:message`
  * `:fixes` — lint fixes as `t:OXC.patch/0` maps, ready for `OXC.patch_string/2`
  * `:suggestions` — alternative type-aware fixes, each with a `:message` and `:fixes`

# `label`

```elixir
@type label() :: %{position: position(), span: position(), message: String.t() | nil}
```

# `position`

```elixir
@type position() :: {line :: pos_integer(), column :: pos_integer()}
```

# `raw`

```elixir
@type raw() :: %{
  :message =&gt; String.t(),
  optional(:help) =&gt; String.t() | nil,
  optional(:labels) =&gt; [
    {non_neg_integer(), non_neg_integer(), String.t() | nil}
  ],
  optional(:severity) =&gt; :error | :warning,
  optional(:rule) =&gt; String.t(),
  optional(:fixes) =&gt; [{non_neg_integer(), non_neg_integer(), String.t()}],
  optional(:suggestions) =&gt; [
    %{
      message: String.t(),
      fixes: [{non_neg_integer(), non_neg_integer(), String.t()}]
    }
  ],
  optional(atom()) =&gt; term()
}
```

A native error: message, help, and byte-range labels with the primary label first.

# `t`

```elixir
@type t() :: Code.diagnostic(:error | :warning)
```

# `format`

```elixir
@spec format(t()) :: String.t()
```

Format a diagnostic as `file:line:column: message`, like Elixir compiler output.

# `from_raw`

```elixir
@spec from_raw([raw() | String.t()], String.t() | nil, iodata() | nil) :: [t()]
```

Build diagnostics from native errors reported for `source` in `file`.

Pass `nil` for `source` when the errors do not refer to a single source text.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
