Skip to content

Commit

Permalink
strip comments (the proper way?)
Browse files Browse the repository at this point in the history
Updates #6

Signed-off-by: Iskander Sharipov <quasilyte@gmail.com>
  • Loading branch information
quasilyte committed Jan 24, 2019
1 parent 605dffd commit b6a4683
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion cmd/go-normalize/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ func main() {
if err != nil {
log.Panicf("loadfile: %v", err)
}
f.Comments = nil
normalizationConfig := &astnorm.Config{
Info: info,
}
Expand All @@ -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.
Expand Down

0 comments on commit b6a4683

Please sign in to comment.