FreedomFormatter (freedom_formatter v1.2.1) View Source

Freedom Formatter is a fork of Elixir's code formatter, with added freedom.

It respects .formatter.exs and supports all features of the standard code formatter, as well as additional features unlikely to arrive soon in core Elixir.

Usage

Install:

{:freedom_formatter, "~> 1.0", only: :dev}

Run:

mix fformat

Why

Elixir's code formatter does not intend to support trailing commas, or indeed any additional settings, until at least January 2019. See Elixir issues #7689 and #6646 for more information.

Thanks to software freedom, we can use tomorrow's formatter today.

Project Goals

  • To provide a compatible alternative to the Elixir formatter, available separately from the core Elixir distribution
  • To allow developers and teams to benefit from standardized code formatting while retaining a style they find more productive
  • To be a testbed for new formatting features and options, maintaining the easiest possible path to possible inclusion in core Elixir.

Added features

Freedom Formatter supports all Elixir's standard code formatting options, as well as:

  • :trailing_comma - if set true, multi-line list, map, and struct literals will include a trailing comma after the last item or pair in the data structure. Does not affect argument lists, tuples, or lists/maps/structs rendered on a single line.

Thanks

Thanks to José Valim for hacking together a code formatter and getting it almost perfect. :)

Link to this section Summary

Link to this section Functions

Link to this function

format_file!(file, opts \\ [])

View Source (since 1.6.0)

Specs

format_file!(
  binary(),
  keyword()
) :: iodata()

Formats a file.

See format_string!/2 for more information on code formatting and available options.

Link to this function

format_string!(string, opts \\ [])

View Source (since 1.6.0)

Specs

format_string!(
  binary(),
  keyword()
) :: iodata()

See Code.format_string!/2