MCPcopy
hub / github.com/hashicorp/hcl / Format

Function Format

hclwrite/public.go:41–48  ·  view source on GitHub ↗

Format takes source code and performs simple whitespace changes to transform it to a canonical layout style. Format skips constructing an AST and works directly with tokens, so it is less expensive than formatting via the AST for situations where no other changes will be made. It also ignores synta

(src []byte)

Source from the content-addressed store, hash-verified

39// to partial source code, although the result in that case may not be
40// desirable.
41func Format(src []byte) []byte {
42 tokens := lexConfig(src)
43 format(tokens)
44 buf := &bytes.Buffer{}
45 //nolint:errcheck // FIXME: Propogate errors upward.
46 tokens.WriteTo(buf)
47 return buf.Bytes()
48}

Callers 2

processFileFunction · 0.92
TestRoundTripFormatFunction · 0.85

Calls 4

lexConfigFunction · 0.85
formatFunction · 0.85
WriteToMethod · 0.45
BytesMethod · 0.45

Tested by 1

TestRoundTripFormatFunction · 0.68