Skip to content

Format your code with `bynk-fmt`

Goal: format Bynk source to the canonical style.

Bynk’s formatter is built into the compiler as bynkc fmt.

Terminal window
bynkc fmt src/counters.bynk
bynkc fmt src/*.bynk

This rewrites the named files to canonical form (tab indentation, normalised spacing). For example:

commons demo {
type Id=Int
fn add(a:Int,b:Int)->Int{a+b}
}

becomes:

commons demo {
type Id = Int
fn add(a: Int, b: Int) -> Int { a + b }
}

Pass - to read from stdin and write to stdout — handy for editor integrations:

Terminal window
cat src/counters.bynk | bynkc fmt -

--check verifies formatting without writing, exiting non-zero if any file is not already canonical:

Terminal window
bynkc fmt --check src/*.bynk

Bynk has one canonical style, and the default output is it. When a house style or a narrower terminal genuinely calls for something else, four flags override the style for that invocation:

Terminal window
bynkc fmt --indent spaces --indent-width 4 src/*.bynk
bynkc fmt --max-line-width 120 src/*.bynk
bynkc fmt --no-trailing-comma src/*.bynk
FlagDefaultEffect
--indent tab|spacesthe project’s, else tabTabs are the default so each reader picks their own width in their editor.
--indent-width Nthe project’s, else 2Spaces per nesting level. Passing it when the run resolves to tabs is an error rather than a silent no-op.
--max-line-width COLUMNSthe project’s, else 100The soft target a construct wraps to fit. A line with no break point in it (a long string literal) is left long.
--no-trailing-commaoffDrops the trailing comma from multi-line records, sums, list literals and exports clauses. --trailing-comma is its opposite.
--no-configoffIgnore the project’s [fmt] section for this run.

Nothing is written to bynk.toml — a flag applies to that run only.

Put it in the project’s bynk.toml and every fmt run picks it up, along with format-on-save in the editor:

[fmt]
indent = "spaces"
indent_width = 4
max_line_width = 120

The manifest is found by walking up from each file being formatted, so a command that spans two projects gives each its own style. A flag on the command line overrides the field it names and leaves the rest of the section in force; the resolution order is defaults → [fmt] → flags.

--check judges files against those resolved options, so a project on a non-default style has a CI gate that can actually pass:

Terminal window
bynkc fmt --check src/*.bynk

To format to the canonical style whatever project you are standing in — a release script, say — add --no-config to skip the [fmt] layer.