KScript docs
EN

Formatting

Turning rules off

Each thing the formatter does is a rule you can turn off under format.rules (true/false, or "on"/"off"). Every rule is on unless you list it:

Rule What it does When it's off
indent Indents elements by nesting. Lines keep the indentation they have.
statement_per_line Puts each statement (and block-level element) on its own line. Line breaks only change where there already was whitespace, so one-liners like <for ...><echo>$i</echo></for> stay.
tidy_tags One space between attributes, <x /> for self-closing tags. Start tags are kept exactly as written.
wrap_attributes One attribute per line for long start tags, and for tags already written that way. Tags are never wrapped or joined.
trim_trailing_whitespace Removes spaces at the ends of lines of text. They're kept.
collapse_blank_lines Shrinks runs of blank lines to max_blank_lines. Blank lines are kept.
final_newline Ends the file with exactly one newline. The file ends as it did.
spacing .kscript files: adds a missing space after commas and colons, around = and =>, and before a block's {. Spacing inside lines is kept.
brace_style .kscript files: } else {, } catch { on one line. else and catch stay on the line they're on.
wrap_chains .kscript files: puts each call of a -> chain or |> pipe that runs past print_width on its own line. Chains stay on one line.
wrap_bodies .kscript files: moves a long one-line function's body (and a long lambda's, when it is a call's only argument) to the line after its =>. Bodies stay on the => line.
wrap_comments .kscript files: breaks a // or /// comment line that runs past print_width between words. Comments stay as written.
wrap_strings .kscript files: breaks a string that runs past print_width at a space, ending the line with \ so the break isn't part of the string. Long strings stay on one line.

In .kscript files, tidy_tags does nothing, wrap_attributes lays out long calls, arrays, maps and model options, and statement_per_line opens up one-line blocks and splits ;.

JSON
{
  "format": {
    "rules": { "statement_per_line": false, "wrap_attributes": false }
  }
}

"enabled": false turns formatting off for the whole project: kscript fmt skips its files and Format Document makes no changes. format.exclude leaves particular files and folders alone.

Edit this page on GitHub