Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code cleanup #17

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand All @@ -58,7 +60,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) {
Expand Down Expand Up @@ -121,14 +123,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))
Expand All @@ -149,5 +151,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)
}