From 32e503a820314107255501059dd3452e2fba8843 Mon Sep 17 00:00:00 2001 From: Michael Jarvis Date: Fri, 10 Sep 2021 08:54:09 -0500 Subject: [PATCH 1/2] Minor code cleanup --- main.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/main.go b/main.go index 7374b62..657c86e 100644 --- a/main.go +++ b/main.go @@ -58,7 +58,7 @@ func main() { reportError(fmt.Errorf("Could not parse file %s", *file)) } - declarations := []Declaration{} + var declarations []Declaration for _, decl := range fileAst.Decls { switch decl := decl.(type) { @@ -121,14 +121,14 @@ func main() { } } - pkg := []*Declaration{&Declaration{ - fileAst.Name.String(), - "package", - "", - fileAst.Pos(), - fileAst.End(), - declarations, - }} + var pkg []*Declaration + pkg = append(pkg, &Declaration{ + Label: fileAst.Name.String(), + Type: "package", + Start: fileAst.Pos(), + End: fileAst.End(), + Children: declarations, + }) str, _ := json.Marshal(pkg) fmt.Println(string(str)) @@ -149,5 +149,5 @@ func getReceiverType(fset *token.FileSet, decl *ast.FuncDecl) (string, error) { } func reportError(err error) { - fmt.Fprintln(os.Stderr, "error:", err) + _, _ = fmt.Fprintln(os.Stderr, "error:", err) } From f6c3c3bc9fe3888f38c7bedd50a5d07e6a706dbf Mon Sep 17 00:00:00 2001 From: Michael Jarvis Date: Fri, 10 Sep 2021 08:57:12 -0500 Subject: [PATCH 2/2] More code cleanup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit • Omit comparison to bool constants by simplifying code • Correct ineffectual assignment to err in parser.ParseFile() --- main.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index 657c86e..9249450 100644 --- a/main.go +++ b/main.go @@ -33,15 +33,17 @@ func main() { flag.Parse() fset := token.NewFileSet() parserMode := parser.ParseComments - if *importsOnly == true { + if *importsOnly { parserMode = parser.ImportsOnly } var fileAst *ast.File var err error - if *modified == true { - archive, err := buildutil.ParseOverlayArchive(os.Stdin) + if *modified { + + var archive map[string][]byte + archive, err = buildutil.ParseOverlayArchive(os.Stdin) if err != nil { reportError(fmt.Errorf("failed to parse -modified archive: %v", err)) }