View Source Ash.ResourceFormatter (ash v1.53.3)

Formats Ash resources. WARNING: This is untested, use at your own risk! do not run without commiting your code first!

Currently, it is very simple, and will only reorder the outermost sections according to some rules.

Plugin

Include the plugin into your .formatter.exs like so plugins: [Ash.ResourceFormatter].

If no configuration is provided, it will sort all top level DSL sections alphabetically.

Section Order

To provide a custom section order (for both ash and any extensions), add configuration to your app, for example:

config :ash, :formatter,
  section_order: [
    :resource,
    :postgres,
    :attributes,
    :relationships,
    :aggregates,
    :calculations
  ]

Any sections found in your resource that aren't in that list will be left in the order that they were in, the sections in the list will be sorted "around" those sections. E.g the following list: [:code_interface, :attributes] can be interpreted as "ensure that code_interface comes before attributes, and don't change the rest".

Using something other than Ash.Resource

The resource formatter triggers when it sees a use Ash.Resource in a module. In some cases, you may be "use"ing a different module, e.g use MyApp.Resource. To support this, you can configure the using_modules, like so:

config :ash, :formatter,
  using_modules: [Ash.Resource, MyApp.Resource]

Link to this section Summary

Functions

Callback implementation for Mix.Tasks.Format.features/1.

Callback implementation for Mix.Tasks.Format.format/2.

Copy of Macro.prewalk/2 w/ a branch accumulator

Copy of Macro.prewalk/3 w/ a branch accumulator

A copy of the corresponding Macro.traverse function that has a separate accumulator that only goes down each branch, only for pre

Link to this section Functions

Callback implementation for Mix.Tasks.Format.features/1.

Callback implementation for Mix.Tasks.Format.format/2.

Copy of Macro.prewalk/2 w/ a branch accumulator

Link to this function

prewalk(ast, acc, branch_acc, fun)

View Source

Copy of Macro.prewalk/3 w/ a branch accumulator

Link to this function

traverse(ast, acc, branch_acc, pre, post)

View Source

A copy of the corresponding Macro.traverse function that has a separate accumulator that only goes down each branch, only for pre