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.
Format files in place
Section titled “Format files in place”bynkc fmt src/counters.bynkbynkc fmt src/*.bynkThis rewrites the named files to canonical form (tab indentation, normalised spacing). For example:
commons demo {type Id=Intfn add(a:Int,b:Int)->Int{a+b}}becomes:
commons demo { type Id = Int
fn add(a: Int, b: Int) -> Int { a + b }}Format via stdin
Section titled “Format via stdin”Pass - to read from stdin and write to stdout — handy for editor integrations:
cat src/counters.bynk | bynkc fmt -Check formatting in CI
Section titled “Check formatting in CI”--check verifies formatting without writing, exiting non-zero if any file is
not already canonical:
bynkc fmt --check src/*.bynkOverride the style for a run
Section titled “Override the style for a run”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:
bynkc fmt --indent spaces --indent-width 4 src/*.bynkbynkc fmt --max-line-width 120 src/*.bynkbynkc fmt --no-trailing-comma src/*.bynk| Flag | Default | Effect |
|---|---|---|
--indent tab|spaces | the project’s, else tab | Tabs are the default so each reader picks their own width in their editor. |
--indent-width N | the project’s, else 2 | Spaces per nesting level. Passing it when the run resolves to tabs is an error rather than a silent no-op. |
--max-line-width COLUMNS | the project’s, else 100 | The soft target a construct wraps to fit. A line with no break point in it (a long string literal) is left long. |
--no-trailing-comma | off | Drops the trailing comma from multi-line records, sums, list literals and exports clauses. --trailing-comma is its opposite. |
--no-config | off | Ignore the project’s [fmt] section for this run. |
Nothing is written to bynk.toml — a flag applies to that run only.
Set a style for the whole project
Section titled “Set a style for the whole project”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 = 4max_line_width = 120The 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:
bynkc fmt --check src/*.bynkTo format to the canonical style whatever project you are standing in — a
release script, say — add --no-config to skip the [fmt] layer.
Related
Section titled “Related”- Set up editor support for format-on-save.
- Reference:
bynk-fmt.