[!IMPORTANT]

This fork (@christhekeele) of erlex is the official version currently being released on hex.pm.

Please direct issues and pull requests to this fork, rather than the original (@asummers) repository, which is unmaintained.

Erlex

Converts Erlang style structs and error messages to equivalent Elixir.

Useful for pretty printing things like Dialyzer errors and Observer state.

Version][hex-pm-version-badge]][hex-pm-versions]
[![Documentation][docs-badge]][docs]
[![License][hex-pm-license-badge]][apache-2-license]
[![Downloads][hex-pm-downloads-badge] [Dependencies

👍Test SuiteTest Coverage
ReleaseBuild StatusCoverage Status
LatestBuild StatusCoverage Status

Installation

The package can be installed from Hex by adding erlex to your list of dependencies in mix.exs:

def deps do
  [
    {:erlex, "~> 0.2"},
  ]
end

Usage

Invoke Erlex.pretty_print/1 with the input string.

iex> str = ~S"('Elixir.Plug.Conn':t(),binary() | atom(),'Elixir.Keyword':t() | map()) -> 'Elixir.Plug.Conn':t()"
iex> Erlex.pretty_print(str)
(Plug.Conn.t(), binary() | atom(), Keyword.t() | map()) :: Plug.Conn.t()

While the lion's share of the work is done via invoking Erlex.pretty_print/1, other higher order functions exist for further formatting certain messages by running through the Elixir formatter.

For example, because we know the previous example is a type, we can invoke the Erlex.pretty_print_contract/1 function, which would format that appropriately for very long lines.

iex> str = ~S"('Elixir.Plug.Conn':t(),binary() | atom(),'Elixir.Keyword':t() | map(), map() | atom(), non_neg_integer(), binary(), binary(), binary(), binary(), binary()) -> 'Elixir.Plug.Conn':t()"
iex> Erlex.pretty_print_contract(str)
(
  Plug.Conn.t(),
  binary() | atom(),
  Keyword.t() | map(),
  map() | atom(),
  non_neg_integer(),
  binary(),
  binary(),
  binary(),
  binary(),
  binary()
) :: Plug.Conn.t()

Changelog

Check out the Changelog.

Compatibility

Because this code calls the Elixir formatter, it requires Elixir 1.6+.

We try to test against against all supported combinations of OSs and Elixir and Erlang versions since Elixir 1.6.

We also try to test against upcoming versions of both Elixir and Erlang to get ahead of any changes.

Contributing

We welcome contributions of all kinds! To get started, click here.

Code of Conduct

Be sure to read and follow the code of conduct.