From a630fd8b418650f8df52aead511ec4d27ca48ad2 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Thu, 3 May 2018 15:48:26 +0200 Subject: gometalinter: some fixes for unparam But we still can't enable it as there are more [uninteresting] warnings. Update #538 --- .gometalinter.json | 3 +-- pkg/compiler/compiler.go | 6 +++--- pkg/compiler/consts.go | 16 ++++++---------- prog/hints.go | 4 ++-- vm/gce/gce.go | 8 ++++---- vm/isolated/isolated.go | 16 ++++++++-------- 6 files changed, 24 insertions(+), 29 deletions(-) diff --git a/.gometalinter.json b/.gometalinter.json index d919247b6..d2a375082 100644 --- a/.gometalinter.json +++ b/.gometalinter.json @@ -21,9 +21,8 @@ ], "exclude": [ "don't use underscores in Go names", - "don't use ALL_CAPS in Go names", + "sys/(akaros|freebsd|fuchsia|linux|netbsd|test|windows)/init.* don't use ALL_CAPS in Go names", "exported .* should have comment", - "comment on exported type", "comment on .* should be of the form", "sys/(akaros|freebsd|fuchsia|linux|netbsd|test|windows)/(386|amd64|arm|arm64|ppc64le|32|64).go.* should not use dot imports" ] diff --git a/pkg/compiler/compiler.go b/pkg/compiler/compiler.go index 809de5bd5..f49576561 100644 --- a/pkg/compiler/compiler.go +++ b/pkg/compiler/compiler.go @@ -176,7 +176,7 @@ func (comp *compiler) parseUnionAttrs(n *ast.Struct) (varlen bool, size uint64) } varlen = true case "size": - size = comp.parseSizeAttr(n, attr) + size = comp.parseSizeAttr(attr) default: comp.error(attr.Pos, "unknown union %v attribute %v", n.Name.Name, attr.Ident) @@ -215,7 +215,7 @@ func (comp *compiler) parseStructAttrs(n *ast.Struct) (packed bool, size, align } align = a case attr.Ident == "size": - size = comp.parseSizeAttr(n, attr) + size = comp.parseSizeAttr(attr) default: comp.error(attr.Pos, "unknown struct %v attribute %v", n.Name.Name, attr.Ident) @@ -224,7 +224,7 @@ func (comp *compiler) parseStructAttrs(n *ast.Struct) (packed bool, size, align return } -func (comp *compiler) parseSizeAttr(n *ast.Struct, attr *ast.Type) uint64 { +func (comp *compiler) parseSizeAttr(attr *ast.Type) uint64 { if len(attr.Args) != 1 { comp.error(attr.Pos, "%v attribute is expected to have 1 argument", attr.Ident) return sizeUnassigned diff --git a/pkg/compiler/consts.go b/pkg/compiler/consts.go index 1b008bd4f..79bf84e70 100644 --- a/pkg/compiler/consts.go +++ b/pkg/compiler/consts.go @@ -170,7 +170,7 @@ func (comp *compiler) patchConsts(consts map[string]uint64) { n := decl.(*ast.IntFlags) var values []*ast.Int for _, v := range n.Values { - if comp.patchIntConst(v.Pos, &v.Value, &v.Ident, consts, nil) { + if comp.patchIntConst(&v.Value, &v.Ident, consts, nil) { values = append(values, v) } } @@ -182,10 +182,9 @@ func (comp *compiler) patchConsts(consts map[string]uint64) { args []*ast.Type, _ prog.IntTypeCommon) { for i, arg := range args { if desc.Args[i].Type.Kind == kindInt { - comp.patchIntConst(arg.Pos, &arg.Value, - &arg.Ident, consts, &missing) + comp.patchIntConst(&arg.Value, &arg.Ident, consts, &missing) if arg.HasColon { - comp.patchIntConst(arg.Pos2, &arg.Value2, + comp.patchIntConst(&arg.Value2, &arg.Ident2, consts, &missing) } } @@ -193,16 +192,14 @@ func (comp *compiler) patchConsts(consts map[string]uint64) { }) if n, ok := decl.(*ast.Resource); ok { for _, v := range n.Values { - comp.patchIntConst(v.Pos, &v.Value, - &v.Ident, consts, &missing) + comp.patchIntConst(&v.Value, &v.Ident, consts, &missing) } } if n, ok := decl.(*ast.Struct); ok { for _, attr := range n.Attrs { if attr.Ident == "size" { sz := attr.Args[0] - comp.patchIntConst(sz.Pos, &sz.Value, - &sz.Ident, consts, &missing) + comp.patchIntConst(&sz.Value, &sz.Ident, consts, &missing) } } } @@ -227,8 +224,7 @@ func (comp *compiler) patchConsts(consts map[string]uint64) { } } -func (comp *compiler) patchIntConst(pos ast.Pos, val *uint64, id *string, - consts map[string]uint64, missing *string) bool { +func (comp *compiler) patchIntConst(val *uint64, id *string, consts map[string]uint64, missing *string) bool { if *id == "" { return true } diff --git a/prog/hints.go b/prog/hints.go index b16d50dad..11c7b697b 100644 --- a/prog/hints.go +++ b/prog/hints.go @@ -75,11 +75,11 @@ func (p *Prog) MutateWithHints(callIndex int, comps CompMap, exec func(p *Prog)) exec(p) } ForeachArg(c, func(arg Arg, _ *ArgCtx) { - generateHints(p, comps, c, arg, execValidate) + generateHints(comps, arg, execValidate) }) } -func generateHints(p *Prog, compMap CompMap, c *Call, arg Arg, exec func()) { +func generateHints(compMap CompMap, arg Arg, exec func()) { typ := arg.Type() if typ == nil || typ.Dir() == DirOut { return diff --git a/vm/gce/gce.go b/vm/gce/gce.go index 7f3281382..843072cff 100644 --- a/vm/gce/gce.go +++ b/vm/gce/gce.go @@ -192,7 +192,7 @@ func (inst *instance) Forward(port int) (string, error) { func (inst *instance) Copy(hostSrc string) (string, error) { vmDst := "./" + filepath.Base(hostSrc) args := append(sshArgs(inst.debug, inst.sshKey, "-P", 22), hostSrc, inst.sshUser+"@"+inst.ip+":"+vmDst) - if _, err := runCmd(inst.debug, "scp", args...); err != nil { + if err := runCmd(inst.debug, "scp", args...); err != nil { return "", err } return vmDst, nil @@ -359,7 +359,7 @@ func (pool *Pool) waitInstanceBoot(name, ip, sshKey, sshUser, gceKey string) err return fmt.Errorf("shutdown in progress") } args := append(sshArgs(pool.env.Debug, sshKey, "-p", 22), sshUser+"@"+ip, pwd) - if _, err := runCmd(pool.env.Debug, "ssh", args...); err == nil { + if err := runCmd(pool.env.Debug, "ssh", args...); err == nil { return nil } } @@ -473,7 +473,7 @@ func uploadImageToGCS(localImage, gcsImage string) error { return nil } -func runCmd(debug bool, bin string, args ...string) ([]byte, error) { +func runCmd(debug bool, bin string, args ...string) error { if debug { log.Logf(0, "running command: %v %#v", bin, args) } @@ -481,7 +481,7 @@ func runCmd(debug bool, bin string, args ...string) ([]byte, error) { if debug { log.Logf(0, "result: %v\n%s", err, output) } - return output, err + return err } func sshArgs(debug bool, sshKey, portArg string, port int) []string { diff --git a/vm/isolated/isolated.go b/vm/isolated/isolated.go index 449228192..8ab3eb9bf 100644 --- a/vm/isolated/isolated.go +++ b/vm/isolated/isolated.go @@ -115,15 +115,16 @@ func (inst *instance) Forward(port int) (string, error) { return fmt.Sprintf("127.0.0.1:%v", port), nil } -func (inst *instance) ssh(command string) ([]byte, error) { +func (inst *instance) ssh(command string) error { if inst.debug { log.Logf(0, "executing ssh %+v", command) } rpipe, wpipe, err := osutil.LongPipe() if err != nil { - return nil, err + return err } + // TODO(dvyukov): who is closing rpipe? args := append(inst.sshArgs("-p"), inst.target, command) if inst.debug { @@ -134,7 +135,7 @@ func (inst *instance) ssh(command string) ([]byte, error) { cmd.Stderr = wpipe if err := cmd.Start(); err != nil { wpipe.Close() - return nil, err + return err } wpipe.Close() @@ -155,14 +156,13 @@ func (inst *instance) ssh(command string) ([]byte, error) { if inst.debug { log.Logf(0, "ssh failed: %v\n%s", err, out) } - return nil, fmt.Errorf("ssh %+v failed: %v\n%s", args, err, out) + return fmt.Errorf("ssh %+v failed: %v\n%s", args, err, out) } close(done) if inst.debug { log.Logf(0, "ssh returned") } - out, _ := ioutil.ReadAll(rpipe) - return out, nil + return nil } func (inst *instance) repair() error { @@ -199,7 +199,7 @@ func (inst *instance) waitForSSH(timeout int) error { if !vmimpl.SleepInterruptible(time.Second) { return fmt.Errorf("shutdown in progress") } - if _, err = inst.ssh("pwd"); err == nil { + if err = inst.ssh("pwd"); err == nil { return nil } if time.Since(start).Seconds() > float64(timeout) { @@ -217,7 +217,7 @@ func (inst *instance) waitForReboot(timeout int) error { return fmt.Errorf("shutdown in progress") } // If it fails, then the reboot started - if _, err = inst.ssh("pwd"); err != nil { + if err = inst.ssh("pwd"); err != nil { return nil } if time.Since(start).Seconds() > float64(timeout) { -- cgit mrf-deployment