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

test: make Go code lint stricter #8068

Closed
gyuho opened this issue Jun 8, 2017 · 7 comments
Closed

test: make Go code lint stricter #8068

gyuho opened this issue Jun 8, 2017 · 7 comments
Assignees

Comments

@gyuho
Copy link
Contributor

gyuho commented Jun 8, 2017

Possible addition to our format tests

Either use external tools or propose to cmd/vet team

@gyuho gyuho added this to the unplanned milestone Jun 8, 2017
@heyitsanthony
Copy link
Contributor

Unused function arguments would be a good one, CI should have caught this bug from #8074:

func (dec *messageDecoder) decodeLimit(numBytes uint64) (raftpb.Message, error) {
        var m raftpb.Message
        var l uint64
        if err := binary.Read(dec.r, binary.BigEndian, &l); err != nil {
                return m, err
        }
        if l > readBytesLimit {
                return m, ErrExceedSizeLimit
        }
        buf := make([]byte, int(l))
        if _, err := io.ReadFull(dec.r, buf); err != nil {
                return m, err
        }
        return m, m.Unmarshal(buf)
}

@gyuho
Copy link
Contributor Author

gyuho commented Jun 20, 2017

TODO: try https://github.com/mvdan/unparam.

@heyitsanthony
Copy link
Contributor

Gave it a spin, totally broken. Can't recognize import renaming. The ignore policy seems too weak anyway; if an argument is unused and not given an underscore name, there's still a bunch of ways it'll let that pass, even though it probably shouldn't...

@mvdan
Copy link

mvdan commented Jun 25, 2017

Hey, original author here. If you find any issues in particular, please file issues with a small example to reproduce them.

I realise the tool likely has some false negatives and positives, but it's impossible (or near impossible?) to have a perfect solution given how arguments might be used in lots of subtle ways.

But of course, I'm sure the tool can do better :) Happy to help if you give me concrete issues.

@mvdan
Copy link

mvdan commented Aug 27, 2017

Friendly ping - still happy to look into false positives or negatives if you'd give me pointers.

@mvdan
Copy link

mvdan commented Nov 16, 2017

I have been improving the tool the past couple of weeks, and I've been using etcd as one of the sources for ideas on how to improve.

Last week, the number of warnings was upwards of 100. Now, it's down to 31:

client/cancelreq.go:11:22: requestCanceler - tr is unused
clientv3/concurrency/election.go:49:33: ResumeElection - pfx is unused
contrib/recipes/key.go:47:56: newUniqueKV - result 0 (*github.com/coreos/etcd/contrib/recipes.RemoteKV) is never used
etcdctl/ctlv3/command/del_command.go:56:15: getDelOp - cmd is unused
etcdctl/ctlv3/command/get_command.go:77:15: getGetOp - cmd is unused
etcdctl/ctlv3/command/migrate_command.go:240:46: writeStore - result 0 (uint64) is never used
etcdctl/ctlv3/command/put_command.go:79:15: getPutOp - cmd is unused
etcdserver/api/v2http/capability.go:25:24: capabilityHandler - c always receives "auth"
etcdserver/api/v2http/client.go:624:48: trimErrorPrefix - result 0 (error) is just parameter err
etcdserver/api/v2http/metrics.go:67:59: reportRequestCompleted - response is unused
etcdserver/api/v2v3/store.go:94:56: (*v2v3Store).getDir - sorted is unused
etcdserver/auth/auth_requests.go:108:45: (*store).requestResource - dir always receives false
etcdserver/auth/auth_requests.go:151:45: (*store).deleteResource - result 0 (github.com/coreos/etcd/etcdserver.Response) is never used
etcdserver/raft.go:302:57: (*raftNode).processMessages - result 0 ([]github.com/coreos/etcd/raft/raftpb.Message) is just parameter ms
integration/bridge.go:203:25: (*bridge).ioCopy - bc is unused
integration/cluster.go:422:32: (*cluster).waitNoLeader - t is unused
integration/cluster.go:646:24: (*member).Clone - t is unused
integration/cluster.go:843:23: (*member).Stop - t is unused
integration/cluster.go:851:28: checkLeaderTransition - t is unused
integration/cluster.go:928:34: (*member).InjectPartition - t is unused
integration/cluster.go:936:35: (*member).RecoverPartition - t is unused
mvcc/kvstore_txn.go:222:45: (*storeTxnWrite).delete - rev is unused
pkg/transport/listener.go:52:14: wrapTLS - addr is unused
raft/log.go:94:44: (*raftLog).append - result 0 (uint64) is never used
tools/functional-tester/etcd-agent/rpc.go:49:40: (*Agent).RPCStop - reply is unused
tools/functional-tester/etcd-agent/rpc.go:70:43: (*Agent).RPCCleanup - reply is unused
tools/functional-tester/etcd-agent/rpc.go:80:45: (*Agent).RPCTerminate - reply is unused
tools/functional-tester/etcd-agent/rpc.go:89:39: (*Agent).RPCDropPort - reply is unused
tools/functional-tester/etcd-agent/rpc.go:98:42: (*Agent).RPCRecoverPort - reply is unused
tools/functional-tester/etcd-agent/rpc.go:107:43: (*Agent).RPCSetLatency - reply is unused
tools/functional-tester/etcd-agent/rpc.go:119:49: (*Agent).RPCRemoveLatency - reply is unused

Except the *Agent ones which seem a bit weird, the rest all look like real warnings to me.

Whether or not the signature of exported funcs can be changed is a different aspect - the tool does nothing about that, at the moment. Thinking of adding a flag, defaulting to assuming that backwards compatibility cannot be broken.

@gyuho
Copy link
Contributor Author

gyuho commented May 2, 2018

@mvdan We will integrate https://github.com/mvdan/unparam in CI. Seems useful!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

4 participants
@mvdan @gyuho @heyitsanthony and others