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

*: fix nakedret lint #16601

Merged
merged 1 commit into from
Sep 18, 2023
Merged

*: fix nakedret lint #16601

merged 1 commit into from
Sep 18, 2023

Conversation

fuweid
Copy link
Member

@fuweid fuweid commented Sep 17, 2023

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 - Thanks @fuweid 👍🏻

@ahrtr
Copy link
Member

ahrtr commented Sep 17, 2023

Almost all the named return parameters are bad examples. The only exception is the one used in wal.go, it makes sense, because it makes the meaning of the returned value more clear.

So suggest to convert all the named return parameter to naked return parameters except the wal.go.

Reference: https://github.com/golang/go/wiki/CodeReviewComments#named-result-parameters

@fuweid
Copy link
Member Author

fuweid commented Sep 17, 2023

@ahrtr sorry for the late reply. The nakedret is used to detect the named return lint issue. The code change is caused by nakedret. I think we can keep the named return var for retErr check in defer or interface documentation. In this patch, you can see SelfCert is long function. Multiple naked return branches are far away from the declaration. IMO, it's hard to review the code when there is any change. And even if err isn't nil, the function still return non-empty value. Even though the func-invoker should not use the non-empty value if the err isn't nil, it's still confuse.

Maybe we can improve the https://github.com/alexkohler/nakedret/blob/564f756361f1c6a648f759199ab7c03c59cae6dc/cmd/nakedret/main.go#L16 to config max function length which the nakedret tolerances. Or if it's not useful in etcd repo, we can consider to remove the lint.

cc @jmhbnz @serathius

@@ -104,7 +104,7 @@ type tlsKeepaliveListener struct {
func (l *tlsKeepaliveListener) Accept() (c net.Conn, err error) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
func (l *tlsKeepaliveListener) Accept() (c net.Conn, err error) {
func (l *tlsKeepaliveListener) Accept() (net.Conn, error) {

@ahrtr
Copy link
Member

ahrtr commented Sep 17, 2023

To be clearer, the PR makes sense to me. I was requesting to make change something like #16601 (comment). The only exception is the named return parameter used in wal.go, it makes sense, so let's keep it as it's.

@ahrtr
Copy link
Member

ahrtr commented Sep 17, 2023

Sorry for the confusion, I should be more clearer in the first place.

Signed-off-by: Wei Fu <fuweid89@gmail.com>
@@ -245,7 +250,7 @@ func prepareData(cfg config.ServerConfig) (err error) {
func createWALFileWithSnapshotRecord(cfg config.ServerConfig, snapshotTerm, snapshotIndex uint64) (err error) {
Copy link
Member Author

Choose a reason for hiding this comment

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

The err is used in defer so keep it here.

Copy link
Member

Choose a reason for hiding this comment

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

ack

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

@ahrtr ahrtr merged commit 700411d into etcd-io:main Sep 18, 2023
27 checks passed
@jmhbnz jmhbnz mentioned this pull request Sep 25, 2023
9 tasks
@fuweid fuweid deleted the fix-nakedret-lint branch September 30, 2023 01:57
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