# `DialyzerJson.WarningEncoder`
[🔗](https://github.com/ZenHive/dialyzer_json/blob/main/lib/dialyzer_json/warning_encoder.ex#L1)

Encodes Dialyzer warnings to JSON-serializable maps.

Dialyzer warnings come as tuples:
`{tag, {file, location}, {warning_type, args}}`

This module converts them to structured maps suitable for JSON encoding.

# `encoded_warning`

```elixir
@type encoded_warning() :: %{
  file: String.t(),
  line: non_neg_integer(),
  column: non_neg_integer() | nil,
  warning_type: String.t(),
  message: String.t(),
  raw_message: String.t(),
  function: String.t() | nil,
  module: String.t() | nil,
  fix_hint: String.t()
}
```

JSON-serializable warning map

# `location`

```elixir
@type location() :: non_neg_integer() | {non_neg_integer(), non_neg_integer()}
```

Location can be line number or {line, column}

# `warning`

```elixir
@type warning() :: {atom(), {charlist() | binary(), location()}, {atom(), list()}}
```

A raw Dialyzer warning tuple

# `encode_warning`

```elixir
@spec encode_warning(warning()) :: encoded_warning()
```

Encodes a single Dialyzer warning to a JSON-serializable map.

## Example

    iex> warning = {:warn_return_no_exit, {~c"lib/foo.ex", 10}, {:no_return, [:only_normal, :bar, 2]}}
    iex> encoded = DialyzerJson.WarningEncoder.encode_warning(warning)
    iex> encoded.file
    "lib/foo.ex"
    iex> encoded.warning_type
    "no_return"
    iex> encoded.function
    "bar/2"

# `encode_warnings`

```elixir
@spec encode_warnings([warning()]) :: [encoded_warning()]
```

Encodes a list of Dialyzer warnings to JSON-serializable maps.

## Examples

    warnings = [{:warn_return_no_exit, {'lib/foo.ex', 10}, {:no_return, [:only_normal, :foo, 2]}}]
    encode_warnings(warnings)
    [%{file: "lib/foo.ex", line: 10, warning_type: "no_return", ...}]

---

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