JustBash.Formatter (JustBash v0.4.0)

View Source

Bash code formatter.

Converts a bash AST back into formatted bash source code. This enables parsing bash scripts and outputting them in a consistent, readable format.

Usage

{:ok, ast} = JustBash.parse("echo   hello    world")
formatted = JustBash.Formatter.format(ast)
# "echo hello world"

Options

  • :indent - Indentation string (default: " " - two spaces)
  • :max_line_length - Maximum line length for wrapping (default: 80)

Summary

Functions

Format an AST into bash source code.

Types

option()

@type option() :: {:indent, String.t()} | {:max_line_length, pos_integer()}

options()

@type options() :: [option()]

Functions

format(script, opts \\ [])

@spec format(JustBash.AST.Script.t(), options()) :: String.t()

Format an AST into bash source code.

Examples

{:ok, ast} = JustBash.parse("if true; then echo yes; fi")
JustBash.Formatter.format(ast)
# "if true; then\n  echo yes\nfi"