Skip to content
FutureBlitz

    Install

    Tools

    The formatter

    The one style fb fmt and editors format FutureBlitz code in, rule by rule.

    fb fmt, and editors through fb’s language server, format code in one style, the standard library’s. It has no options but the line width, project.toml’s [format] width, 100 without it, counted in the columns a terminal shows: two for an East Asian wide character, and none for a combining mark.

    The formatter changes only the spaces between tokens and where long lines break, so code means what it meant. It checks this: it parses what it wrote and compares its tokens and tree with the original’s, and leaves a file it would change otherwise as it is. A file that doesn’t parse is left as it is, with its errors. Formatting twice gives what formatting once does.

    Indentation

    • Four spaces a block.
    • A Select’s Cases are a block, and their bodies a block deeper. So are a Property’s Get and Set, an Enum’s members, and an Extern block’s Functions.
    • A declaration’s Where lines are a step deeper than it.
    • Else, ElseIf, Case, Catch, Finally, Until, and End lines go back to their block’s level, and End Function) after a lambda’s block goes back to the statement the lambda is in.

    Spaces

    • One around binary operators, =, =>, and a ternary’s ? and :, and one after a comma and any other :.
    • None inside parentheses, brackets, or a Map’s braces, {"a": 1}, and none before a call’s or an index’s bracket.
    • None after a prefix -, !, or ~, around ., ?., and .., or between a name and its type arguments, Map<K, V>().
    • A nullable’s ?, and As? and Try?, touch what’s before them. An Operator’s name touches its parameters, Operator []=(.
    • Inside a string, nothing changes; an interpolation’s code is spaced as code.

    Blank lines

    At most one in a row, none at the start of the file or of a block, and none before a block’s end. A file ends with one line break, \r\n when its first line ends that way.

    Comments

    Comments stay where they are. One on its own line takes the indentation of the line after it, and one after code is one space after it. Their text is kept, but for spaces at their end.

    Lines that go on

    A statement goes on to another line only after a comma, an operator, =, =>, or an opening bracket, and inside brackets also before a ternary’s :.

    • Inside brackets, the next line lines up one past the innermost open bracket.
    • Outside brackets, it lines up with the start of the statement’s expression: after = or =>, or after Return, If, ElseIf, While, Until, Throw, Case, Select, Lock, Implements, Throws, or In.
    • A bracket that ends its line has what’s inside it four spaces deeper than that line, and a declaration’s parameters eight, so they stand apart from its body. A closing bracket that starts a line goes at the indentation of the line it opened on.

    Long lines

    The author’s line breaks inside a statement stay; lines are never joined. A line wider than the width breaks at the best place on it:

    1. at a comma or a ternary’s :, then at an operator, the loosest first, each at the outermost bracket level and the latest there;
    2. after = or => outside brackets, when all that follows fits on the next line;
    3. after an opening bracket, when nothing else fits;
    4. after = or =>, last.

    When what comes after the best break still doesn’t fit, the next best is tried. A statement that can’t fit at any break, as with a long string, keeps its line, with only its spacing and indentation fixed.

    #If

    Lines from an outermost #If to its #End If are left as written, so formatting is the same whatever is defined, and the code between them is laid out as code. An #If has to hold whole statements: one that holds part of one, as a block’s first line, leaves the file unformatted, and fb fmt says so.

    Constraints

    One constraint on one of a declaration’s own type parameters goes inline, <T: Hashable>. More than one, a &, or one that relates two type parameters, S: Iterator<T>, goes on Where lines. The formatter doesn’t move them, since that changes the tree: the compiler warns about the other form, with a fix your editor offers.

    Report an issue with this page or with FutureBlitz on GitHub.