woodpecker/vendor/github.com/quasilyte/go-ruleguard/ruleguard/goutil/goutil.go
Lukas c28f7cb29f
Add golangci-lint (#502)
Initial part of #435
2021-11-14 21:01:54 +01:00

21 lines
413 B
Go

package goutil
import (
"go/ast"
"go/printer"
"go/token"
"strings"
)
// SprintNode returns the textual representation of n.
// If fset is nil, freshly created file set will be used.
func SprintNode(fset *token.FileSet, n ast.Node) string {
if fset == nil {
fset = token.NewFileSet()
}
var buf strings.Builder
if err := printer.Fprint(&buf, fset, n); err != nil {
return ""
}
return buf.String()
}