Autoformatting of Ash-related code

I always have issues with getting formatting for Ash-related code to work - I’ve seen it working before, I’ve gotten it working before, but always struggle getting it working on a new project.

I have a brand new Phoenix 1.7.10 app set up, with the latest versions of Ash, AshPostgres and AshPhoenix. I’ve added the deps and the plugin to my .formatter.exs -

  import_deps: [:ecto, :ecto_sql, :phoenix, :ash, :ash_postgres, :ash_phoenix],
  subdirectories: ["priv/*/migrations"],
  plugins: [Phoenix.LiveView.HTMLFormatter, Spark.Formatter],
  inputs: ["*.{heex,ex,exs}", "{config,lib,test}/**/*.{heex,ex,exs}", "priv/*/seeds.exs"]

But when I do things like add parentheses to functions that shouldn’t have any, or rearrange the top-level blocks in a resource, they don’t get formatted the way they should when I run mix format.

Formatting is still working, because if I add things like heaps of extra blank lines they get stripped, it’s just the Ash-specific stuff that doesn’t seem to be working.:frowning:

I believe you have to add at minimum an empty config for the things you want to get formatted, and also use the remove_parens?: true option.


config :spark, :formatter,
  remove_parens?: true,
  "Ash.Resource": [
     section_order: [....]

Oh that works perfectly! (And yes I can see that in the other apps that the formatting works in)

That’s not mentioned in any of the Getting Started guides that talk about setting up the formatter - I’ll see where it will fit and add it.

1 Like