Documentation
¶
Overview ¶
Package format implements standard formatting of CUE configurations.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Node ¶
Node formats node in canonical cue fmt style and writes the result to dst.
The node type must be *ast.File, []ast.Decl, ast.Expr, ast.Decl, or ast.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 ¶
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.
Types ¶
type Option ¶
type Option func(c *config)
An Option sets behavior of the formatter.
func IndentPrefix ¶ added in v0.4.0
IndentPrefix specifies the number of tabstops to use as a prefix for every line.
func Simplify ¶
func Simplify() Option
Simplify allows the formatter to simplify output, such as removing unnecessary quotes.
func TabIndent ¶
TabIndent specifies whether to use tabs for indentation independent of UseSpaces.
This option is set to true by default.
func UseSpaces ¶
UseSpaces specifies that tabs should be converted to spaces and sets the default tab width.
This option is set to 8 by default.
func Version ¶ added in v0.17.0
Version specifies the CUE language version to use when formatting. This affects which canonical style is applied when combined with Simplify; for instance, as of v0.17.0 commas between list elements on separate lines are omitted when simplifying. An empty version string means the version is taken from the *ast.File node being formatted, falling back to conservative behavior (same as pre-v0.17.0: always emit explicit commas). The version must be a valid semantic version string as checked by [semver.IsValid].