View Source Spark.Formatter (spark v0.2.18)

Formats Spark modules.

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: [Spark.Formatter].

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

Section Order

To provide a custom section order, add configuration to your app, for example:

config :spark, :formatter,
  # This option is a bit experimental
  # Worst case it could introduce some easy-to-fix syntax errors.
  # Its been used on a few big projects without issue.
  # Regardless, before you run this for the first time, commit any other changes you have.
  remove_parens?: true,

  "Ash.Resource": [
    section_order: [
      :resource,
      :postgres,
      :attributes,
      :relationships,
      :aggregates,
      :calculations
    ]
  ],
  "MyApp.Resource": [
    # Use this if you use a module that is not the spark DSL itself.
    # For example, you might have a "base" that you use instead that sets some simple defaults.

    # This tells us what the actual thing is so we know what extensions are included automatically.
    type: Ash.Resource,

    # Tell us what extensions might be added under the hood
    extensions: [MyApp.ResourceExtension],
    section_order: [...]
  ]

Any sections found 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".

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