This page groups representative before-and-after examples by scenario. The point is not that every construct is formatted the same way, but that the formatter chooses between flat, fill, packed, aligned, and one-per-line layouts based on the rendered result.
Before:
local point={x=1,y=2}After:
local point = { x = 1, y = 2 }Small stable structures stay on one line, with spacing and separators normalized.
Before:
some_function(first_arg, second_arg, third_arg, fourth_arg)After:
some_function(
first_arg, second_arg, third_arg,
fourth_arg
)This keeps the argument list compact without immediately forcing one argument per line.
Before:
cannotload("attempt to load a text chunk", load(read1(x), "modname", "b", {}))After:
cannotload(
"attempt to load a text chunk",
load(read1(x), "modname", "b", {})
)The outer call expands because of width pressure, but short nested calls are not blown apart unnecessarily.
Before:
local f = function(a -- first
, b)
return a + b
endAfter:
local f = function(a -- first
, b)
return a + b
endInline comments in parameter lists are treated conservatively because rewriting them can change how the signature reads.
Before:
local t = { a = 1, b = 2, c = 3 }After:
local t = { a = 1, b = 2, c = 3 }Before:
local t = { alpha, beta, gamma, delta }After:
local t = {
alpha, beta, gamma,
delta
}The formatter tries a compact multi-line distribution before falling back to one item per line.
Before:
local t = { user = { name = "a", age = 1 }, enabled = true }After:
local t = { user = { name = "a", age = 1 }, enabled = true }Having a nested table is not enough on its own to force full expansion.
Before:
local value = aaaa + bbbb + cccc + dddd + eeee + ffffAfter:
local value = aaaa + bbbb
+ cccc + dddd
+ eeee + ffffBinary-chain candidates are scored with the real first-line prefix width, so long anchors such as local value = affect candidate selection.
Before:
for key, value in first_long_expr, second_long_expr, third_long_expr, fourth_long_expr, fifth_long_expr do
print(key, value)
endAfter:
for key, value in first_long_expr,
second_long_expr, third_long_expr,
fourth_long_expr, fifth_long_expr do
print(key, value)
endThis keeps the first item attached to the keyword line and then packs later items more evenly.
Before:
builder:set_name(name):set_age(age):build()After:
builder
:set_name(name)
:set_age(age)
:build()When fill or packed layouts are clearly worse, the formatter still falls back to one segment per line.
Before:
foo(
alpha, -- first
beta -- second
)After:
foo(
alpha, -- first
beta -- second
)Trailing comments are aligned only when the input already signals alignment intent. The formatter does not manufacture wide alignment blocks across unrelated code.
Before:
if ready then -- inline comment
work()
endAfter:
if ready then -- inline comment
work()
endMoving this kind of comment into the body changes how the control flow reads, so the formatter preserves the header structure.