go: cuelang.org/go/cue/format Index | Files

package format

import "cuelang.org/go/cue/format"

Package format implements standard formatting of CUE configurations.


Package Files

format.go import.go node.go printer.go simplify.go

func Node Uses

func Node(node ast.Node, opt ...Option) ([]byte, error)

Node formats node in canonical cue fmt style and writes the result to dst.

The node type must be *ast.File, []syntax.Decl, syntax.Expr, syntax.Decl, or syntax.Spec. Node does not modify node. Imports are not sorted for nodes representing partial source files (for instance, if the node is not an *ast.File).

The function may return early (before the entire result is written) and return a formatting error, for instance due to an incorrect AST.

func Source Uses

func Source(b []byte, opt ...Option) ([]byte, error)

Source formats src in canonical cue fmt style and returns the result or an (I/O or syntax) error. src is expected to be a syntactically correct CUE source file, or a list of CUE declarations or statements.

If src is a partial source file, the leading and trailing space of src is applied to the result (such that it has the same leading and trailing space as src), and the result is indented by the same amount as the first line of src containing code. Imports are not sorted for partial source files.

Caution: Tools relying on consistent formatting based on the installed version of cue (for instance, such as for presubmit checks) should execute that cue binary instead of calling Source.

type Option Uses

type Option func(c *config)

An Option sets behavior of the formatter.

func Simplify Uses

func Simplify() Option

Simplify allows the formatter to simplify output, such as removing unnecessary quotes.

func TabIndent Uses

func TabIndent(indent bool) Option

TabIndent specifies whether to use tabs for indentation independent of UseSpaces.

func UseSpaces Uses

func UseSpaces(tabwidth int) Option

UseSpaces specifies that tabs should be converted to spaces and sets the default tab width.

Package format imports 15 packages (graph) and is imported by 25 packages. Updated 2020-09-22. Refresh now. Tools for package owners.