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)
| 39 | // to partial source code, although the result in that case may not be |
| 40 | // desirable. |
| 41 | func 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 | } |