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

*: enable and fix unparam lint #16622

Merged
merged 1 commit into from
Oct 18, 2023
Merged

Conversation

fuweid
Copy link
Member

@fuweid fuweid commented Sep 20, 2023

Part of #15549

Highlight of changes:

1. transport/listener_test.go:44:32: fakeCertificateParserFunc - cert always receives tls.Certificate{} (nil)

fakeCertificateParserFunc returns tls.Certificate{} by default.

2. retry_interceptor.go:381:22: withRetryPolicy - rp always receives repeatable (0) (unparam) func withRetryPolicy(rp retryPolicy) retryOption {

Uses the following code to fix

func withRepeatablePolicy() retryOption {
	return retryOption{applyFunc: func(o *options) {
		o.retryPolicy = repeatable
	}}
}

3. history.go:349:22: staleGetRequest - key always receives "key" (unparam) func staleGetRequest(key string, revision int64) EtcdRequest {

Changed one model operation's key from key to key1.

4. member_test.go:84:40: newTestMemberAsLearner - peerURLs always receives nil (unparam) func newTestMemberAsLearner(id uint64, peerURLs []string, name string, clientURLs []string) *Member {

Changed nil to []string{} to fix the lint issue.

diff --git a/server/etcdserver/api/membership/cluster_test.go b/server/etcdserver/api/membership/cluster_test.go
index a3ad87013db..b06d3302475 100644
--- a/server/etcdserver/api/membership/cluster_test.go
+++ b/server/etcdserver/api/membership/cluster_test.go
@@ -544,7 +544,7 @@ func TestClusterAddMemberAsLearner(t *testing.T) {
 	st := mockstore.NewRecorder()
 	c := newTestCluster(t, nil)
 	c.SetStore(st)
-	c.AddMember(newTestMemberAsLearner(1, nil, "node1", nil), true)
+	c.AddMember(newTestMemberAsLearner(1, []string{}, "node1", []string{"http://node1"}), true)
 
 	wactions := []testutil.Action{
 		{
@@ -552,7 +552,7 @@ func TestClusterAddMemberAsLearner(t *testing.T) {
 			Params: []any{
 				path.Join(StoreMembersPrefix, "1", "raftAttributes"),
 				false,
-				`{"peerURLs":null,"isLearner":true}`,
+				`{"peerURLs":[],"isLearner":true}`,
 				false,
 				v2store.TTLOptionSet{ExpireTime: v2store.Permanent},
 			},

Please read https://github.com/etcd-io/etcd/blob/main/CONTRIBUTING.md#contribution-flow.

@@ -24,6 +24,7 @@ linters:
- stylecheck
- unused
- unconvert # Remove unnecessary type conversions
- unparam
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note, this is new check that was not enabled before, so this is not part of #16610 and should start from community discussion whether we want to adopt unparam check at all.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. Let me fix all the existing lint issues and then discuss this one.

@fuweid fuweid changed the title *: fix unparam lint [WIP] *: fix unparam lint Sep 20, 2023
@fuweid fuweid force-pushed the fix-unparam-lint branch 3 times, most recently from 313be92 to bc815e7 Compare October 9, 2023 15:37
@fuweid fuweid changed the title [WIP] *: fix unparam lint *: enable and fix unparam lint Oct 10, 2023
@fuweid fuweid marked this pull request as ready for review October 10, 2023 03:16
@fuweid
Copy link
Member Author

fuweid commented Oct 10, 2023

ping @ahrtr @serathius @jmhbnz

@@ -538,8 +538,7 @@ func mustHTTPListener(lg *zap.Logger, m cmux.CMux, tlsinfo *transport.TLSInfo, c
func mustNewHTTPClient(lg *zap.Logger) *http.Client {
transport, err := newHTTPTransport(grpcProxyCA, grpcProxyCert, grpcProxyKey)
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
lg.Fatal("failed to new http transport", zap.Error(err))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not the same, it changes the exit code and the output.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 let's try not to change anything unrelated to this PR.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lg.Fatal exits with code 1. Yes, I should not update the output.
Updated with removing the lg *zap.Logger since no function uses lg.

Copy link
Member

@ahrtr ahrtr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

thx @fuweid

Copy link
Member

@jmhbnz jmhbnz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - Great to tidy and tighten this up, thanks @fuweid.

@fuweid
Copy link
Member Author

fuweid commented Oct 11, 2023

Is it ready to move on?

@fuweid
Copy link
Member Author

fuweid commented Oct 12, 2023

ping @serathius @ahrtr

@ahrtr
Copy link
Member

ahrtr commented Oct 12, 2023

ping @serathius @ahrtr

Sorry for the delay. I already approved the PR, and leave it to @serathius to take another look and merge, since he raised comment/concern #16622 (comment) previously

@fuweid
Copy link
Member Author

fuweid commented Oct 12, 2023

Thanks for the comment.

As far as I know, the test script has been refactored several times and I believe we miss some of them. The unparam_pass isn't introduced in this pr. The pr just enables it.

The lint did find some unparam issues. It has strict rule, especially when we write test code. But it could help us to find some issues in test code.

In my opinion, based on the fact that it's not new lint in the repo, we can enable it and evaluate it for a while. If it's annoying, we can consider to disable it.

Signed-off-by: Wei Fu <fuweid89@gmail.com>
@fuweid
Copy link
Member Author

fuweid commented Oct 17, 2023

ping @serathius ~

@serathius serathius merged commit 11edde9 into etcd-io:main Oct 18, 2023
27 checks passed
@fuweid fuweid deleted the fix-unparam-lint branch October 18, 2023 08:56
@fuweid
Copy link
Member Author

fuweid commented Oct 18, 2023

Thanks! @serathius

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

Successfully merging this pull request may close these issues.

4 participants