From b6a46837838f11541a687fb3c1d211f0df6b7f22 Mon Sep 17 00:00:00 2001 From: Iskander Sharipov Date: Fri, 25 Jan 2019 00:15:11 +0300 Subject: [PATCH] strip comments (the proper way?) Updates #6 Signed-off-by: Iskander Sharipov --- cmd/go-normalize/main.go | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/cmd/go-normalize/main.go b/cmd/go-normalize/main.go index 70ed3f7..297f94a 100644 --- a/cmd/go-normalize/main.go +++ b/cmd/go-normalize/main.go @@ -28,7 +28,6 @@ func main() { if err != nil { log.Panicf("loadfile: %v", err) } - f.Comments = nil normalizationConfig := &astnorm.Config{ Info: info, } @@ -40,6 +39,28 @@ func main() { } func normalizeFile(cfg *astnorm.Config, f *ast.File) *ast.File { + // Strip comments. + f.Doc = nil + ast.Inspect(f, func(n ast.Node) bool { + switch n := n.(type) { + case *ast.FuncDecl: + n.Doc = nil + case *ast.GenDecl: + n.Doc = nil + case *ast.Field: + n.Doc = nil + case *ast.ImportSpec: + n.Doc = nil + case *ast.ValueSpec: + n.Doc = nil + case *ast.TypeSpec: + n.Doc = nil + default: + } + return true + }) + f.Comments = nil + for _, decl := range f.Decls { // TODO(quasilyte): could also normalize global vars, // consts and type defs, but funcs are OK for the POC.