If I understand right you want to format in dev mode and therefore you can access Mix. In this case you can use this:
> iex -S mix
iex(1)> {formatter, _opts} = Mix.Tasks.Format.formatter_for_file("source.ex")
{#Function<19.89531025/1 in Mix.Tasks.Format.find_formatter_for_file/2>,
[
sigils: [],
plugins: [FreedomFormatter],
trailing_comma: true,
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"],
locals_without_parens: [noop: 1]
]}
iex(2)> formatter.("""
...(2)> defmodule Foo do
...(2)> def foo do
...(2)> noop 5
...(2)> [
...(2)> 1,
...(2)> 2,
...(2)> ]
...(2)> end
...(2)> end
...(2)> """) |> IO.puts()
defmodule Foo do
def foo do
noop 5
[
1,
2,
]
end
end
:ok
The "source.ex" given to formatter_for_file does not have to be an existing file.


















