From 7257655c2e6c5a07ac55776929c620c232b63f5b Mon Sep 17 00:00:00 2001 From: zimt28 <1764689+zimt28@users.noreply.github.com> Date: Sun, 10 Jan 2021 13:44:34 +0100 Subject: [PATCH] Use ecto_sql formatter settings --- lib/migration_generator/migration_generator.ex | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/migration_generator/migration_generator.ex b/lib/migration_generator/migration_generator.ex index 78ad849a..cb341800 100644 --- a/lib/migration_generator/migration_generator.ex +++ b/lib/migration_generator/migration_generator.ex @@ -509,7 +509,7 @@ defmodule AshPostgres.MigrationGenerator do defp format(string, opts) do if opts.format do - Code.format_string!(string) + Code.format_string!(string, locals_without_parens: ecto_sql_locals_without_parens()) else string end @@ -526,6 +526,17 @@ defmodule AshPostgres.MigrationGenerator do reraise exception, __STACKTRACE__ end + defp ecto_sql_locals_without_parens do + path = File.cwd!() |> Path.join("deps/ecto_sql/.formatter.exs") + + if File.exists?(path) do + {opts, _} = Code.eval_file(path) + Keyword.get(opts, :locals_without_parens, []) + else + [] + end + end + defp streamline(ops, acc \\ []) defp streamline([], acc), do: Enum.reverse(acc)