DialyzerJson.WarningEncoder (dialyzer_json v0.2.0)

Copy Markdown View Source

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.

Summary

Types

JSON-serializable warning map

Location can be line number or {line, column}

A raw Dialyzer warning tuple

Functions

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

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

Types

encoded_warning()

@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()

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

Location can be line number or {line, column}

warning()

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

A raw Dialyzer warning tuple

Functions

encode_warning(arg)

@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(warnings)

@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", ...}]