Commit ba1943cd authored by Robert Griesemer's avatar Robert Griesemer

go/format: document use of Source better

For #22695.

Change-Id: Idcda3294070aeaeaf940aaf2014b573732fd60a4
Reviewed-on: https://go-review.googlesource.com/80696Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: 's avatarDmitri Shuralyov <shurcool@gmail.com>
parent f09a3d82
......@@ -24,8 +24,8 @@ const parserMode = parser.ParseComments
// The node type must be *ast.File, *printer.CommentedNode, []ast.Decl,
// []ast.Stmt, or assignment-compatible to ast.Expr, ast.Decl, ast.Spec,
// or ast.Stmt. Node does not modify node. Imports are not sorted for
// nodes representing partial source files (i.e., if the node is not an
// *ast.File or a *printer.CommentedNode not wrapping an *ast.File).
// nodes representing partial source files (for instance, if the node is
// not an *ast.File or a *printer.CommentedNode not wrapping 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.
......@@ -79,6 +79,10 @@ func Node(dst io.Writer, fset *token.FileSet, node interface{}) error {
// 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 gofmt (for instance, such as for presubmit checks) should
// execute that gofmt binary instead of calling Source.
//
func Source(src []byte) ([]byte, error) {
fset := token.NewFileSet()
file, sourceAdj, indentAdj, err := parse(fset, "", src, true)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment