View Source FilterFormatter (FilterFormatter v0.1.1)

Format arbitrary files and sigils through external filter programs.

This is a mix format plugin which filters user-configurable sigils and files by piping their contents to a given command line program. The program is expected to read input via stdin and produce formatter output on stdout. An exit code of 0 is considered success, any other exit code is considered failure.

Setup

Add it as plugin to your .formatter.exs file. Specify sigils/file extensions to filter and a command line to use for filtering in a :filter_formatter option.

[
  plugins: [FilterFormatter],
  filter_formatter: [
    [
      sigils: [:SQL],
      executable: "sqlformat",
      args: ["format", "-", "--dialect", "postgres", "--nocolor", "--disable-progress-bar"]
    ]
  ]
]

Options

The only supported option is :filter_formatter which takes a list of configurations, each describing a list of sigils/file extensions and the command line to use for filtering. Each configuration is a keyword list, supporting the following keys:

  • :sigils- a list of stoms identifying sigils for which content should be filtered.

  • :extensions - a list of extensions (including the dot, e.g. .md or .sql) identifying files to be filtered. Make sure to also include these files in the :inputs option of .formatter.exs!

  • :executable - required; a filter program to invoke for formatting. If just a file name is given, the program is expected to be found via the PATH environment variable.

  • :args - optional; a list of binaries with arguments to pass to the executable.

At least one of :sigils and :extensions should be specified.