JustBash.Formatter (JustBash v0.4.0)
View SourceBash 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
@type option() :: {:indent, String.t()} | {:max_line_length, pos_integer()}
@type options() :: [option()]
Functions
@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"