Magic Trailing Comma
Magic Trailing Comma is a feature inspired by the Black formatter, which automatically adds trailing commas to arrays and tables that span multiple lines.
This feature makes version control more efficient by ensuring clean diffs when adding new elements in the future.
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, it will be expanded to multiple lines.
# 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.
# 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.
# Before formatting
items = { a = 1, b = 2, c = 3, }
# After formatting
items = {
a = 1,
b = 2,
c = 3,
}