Magic Trailing Comma
Magic Trailing Comma is a feature inspired by the Black formatter.
When you add a trailing comma to the last element, Tombi treats it as an explicit hint to expand into multiple lines and keeps the trailing comma after formatting.
This keeps diffs clean when new elements are added later, while respecting the author's intent when no trailing comma is present.
Basic Usage
When there is no trailing comma, Tombi automatically folds the array:
# Before formatting
items = [
"aaaa",
"bbbb",
"cccc"
]
# After formatting
items = ["aaaa", "bbbb", "cccc"]
If the line width is too wide, the array will be expanded to multiple lines, but the final element does not receive a trailing comma automatically.
# Before formatting
items = ["aaaa", "bbbb", "cccc", "dddd", "eeee", "ffff", "gggg", "hhhh", "iiii","jjjj"]
# After formatting
items = [
"aaaa",
"bbbb",
"cccc",
"dddd",
"eeee",
"ffff",
"gggg",
"hhhh",
"iiii",
"jjjj"
]
Alternatively, you can force it to expand to multiple lines by adding a comma to the last element of the array.
The formatter preserves that trailing comma in the expanded form.
# Before formatting
dependencies = ["tombi", "biome", "prettier",]
# After formatting
dependencies = [
"tombi",
"biome",
"prettier",
]
Magic Trailing Comma for Inline Tables
In TOML v1.1.0, Magic Trailing Comma will also be enabled for Inline Tables, and the same trailing-comma hint applies.
# Before formatting
items = { a = 1, b = 2, c = 3, }
# After formatting
items = {
a = 1,
b = 2,
c = 3,
}