Skip to content

Commit

Permalink
gometalinter: some fixes for unparam
Browse files Browse the repository at this point in the history
But we still can't enable it as there are more [uninteresting] warnings.

Update #538
  • Loading branch information
dvyukov committed May 3, 2018
1 parent 9fe5658 commit a630fd8
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 29 deletions.
3 changes: 1 addition & 2 deletions .gometalinter.json
Expand Up @@ -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"
]
Expand Down
6 changes: 3 additions & 3 deletions pkg/compiler/compiler.go
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
16 changes: 6 additions & 10 deletions pkg/compiler/consts.go
Expand Up @@ -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)
}
}
Expand All @@ -182,27 +182,24 @@ 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)
}
}
}
})
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)
}
}
}
Expand All @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions prog/hints.go
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions vm/gce/gce.go
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
}
Expand Down Expand Up @@ -473,15 +473,15 @@ 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)
}
output, err := osutil.RunCmd(time.Minute, "", bin, args...)
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 {
Expand Down
16 changes: 8 additions & 8 deletions vm/isolated/isolated.go
Expand Up @@ -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 {
Expand All @@ -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()

Expand All @@ -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 {
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down

0 comments on commit a630fd8

Please sign in to comment.