format

package
v0.37.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 30, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package format formats Kukel source (kukel fmt): it re-indents lines and normalizes the spaces between tokens. Line breaks and comments stay where they are, and at most one blank line in a row is kept. A line that continues a statement outside brackets is indented one level more than its first line (see continues). A statement that starts with if, while, do, for, switch, try or with gets a blank line before it (breathing space), unless it starts a block or follows a label (see breathe).

The result is checked: read again, it must give the same tokens and comments as the input, or Source refuses it (so formatting can never change a program).

Index

Constants

View Source
const Indent = "    "

Indent is one level of indentation.

Variables

This section is empty.

Functions

func Source

func Source(file string, src []byte) ([]byte, error)

Source formats one source file. A file that does not parse is not formatted: the syntax error is returned.

func SourceWith added in v0.37.0

func SourceWith(file string, src []byte, opt Options) ([]byte, error)

SourceWith formats one source file as Source does, with the choices of opt.

Types

type Options added in v0.37.0

type Options struct {
	// Strict (kukel fmt -strict) puts braces around the statement of each
	// if, else, for, while, do and with that has none (not around the if
	// of an else if, nor around a local declaration or a case label, which
	// may not stand there: such a program stays an error), and puts every
	// function and member function definition on several lines: each
	// statement of its blocks on a line of its own, also in a function
	// that fits on one (f() { return 1; }). Function literals keep their
	// lines (they get the braces); empty blocks stay {}.
	Strict bool
}

Options are the choices of kukel fmt beyond its fixed layout.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL