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

chore(linters): Remove blank identifiers and errors which are not needed to be handled #14399

Merged
merged 1 commit into from
Dec 7, 2023
Merged

chore(linters): Remove blank identifiers and errors which are not needed to be handled #14399

merged 1 commit into from
Dec 7, 2023

Conversation

zak-pawel
Copy link
Collaborator

@zak-pawel zak-pawel commented Dec 7, 2023

Summary

Enabled errcheck linter has default exclusion list that looks like this today:

	// bytes
	"(*bytes.Buffer).Write",
	"(*bytes.Buffer).WriteByte",
	"(*bytes.Buffer).WriteRune",
	"(*bytes.Buffer).WriteString",

	// fmt
	"fmt.Print",
	"fmt.Printf",
	"fmt.Println",
	"fmt.Fprint(*bytes.Buffer)",
	"fmt.Fprintf(*bytes.Buffer)",
	"fmt.Fprintln(*bytes.Buffer)",
	"fmt.Fprint(*strings.Builder)",
	"fmt.Fprintf(*strings.Builder)",
	"fmt.Fprintln(*strings.Builder)",
	"fmt.Fprint(os.Stderr)",
	"fmt.Fprintf(os.Stderr)",
	"fmt.Fprintln(os.Stderr)",

	// io
	"(*io.PipeReader).CloseWithError",
	"(*io.PipeWriter).CloseWithError",

	// math/rand
	"math/rand.Read",
	"(*math/rand.Rand).Read",

	// strings
	"(*strings.Builder).Write",
	"(*strings.Builder).WriteByte",
	"(*strings.Builder).WriteRune",
	"(*strings.Builder).WriteString",

	// hash
	"(hash.Hash).Write",

Our .golangci-lint expands it with the following functions:

     "(*hash/maphash.Hash).Write"
     "(*hash/maphash.Hash).WriteByte"
     "(*hash/maphash.Hash).WriteString"

I've reviewed all (hopefully) uses of these functions in the Telegraf code and removed blank identifiers that masked the reluctance to handle errors returned by above functions.
If any of these functions returned an error that was handled, I removed the handling of that error.

Checklist

  • No AI generated code was used in this PR

Related issues

@Hipska

This comment was marked as outdated.

@Hipska Hipska added the ready for final review This pull request has been reviewed and/or tested by multiple users and is ready for a final review. label Dec 7, 2023
Copy link
Member

@srebhan srebhan left a comment

Choose a reason for hiding this comment

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

Awesome @zak-pawel! Thanks for looking into this!

Copy link
Contributor

@powersj powersj left a comment

Choose a reason for hiding this comment

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

@zak-pawel should there be an update to the .golangci file to enable errcheck? Or was this the first in a series of PRs?

@zak-pawel
Copy link
Collaborator Author

should there be an update to the .golangci file to enable errcheck?

@powersj errcheck has been active for a long time.

@powersj
Copy link
Contributor

powersj commented Dec 7, 2023

should there be an update to the .golangci file to enable errcheck?

@powersj errcheck has been active for a long time.

ok, and how do we prevent these in the future? Does check-blank: true need to be turned on as well?

@zak-pawel
Copy link
Collaborator Author

Does check-blank: true need to be turned on as well?

@powersj We may do it (as a part of different PR), but some of the findings (which will need to be addressed in non-test code) are not trivial to fix.

Copy link
Contributor

@powersj powersj left a comment

Choose a reason for hiding this comment

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

I'm going to approve and merge, but not close #13013 until we have a way to ensure additional blank identifiers are added to the code base.

@powersj powersj merged commit aa681be into influxdata:master Dec 7, 2023
22 checks passed
@github-actions github-actions bot added this to the v1.29.0 milestone Dec 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore linter ready for final review This pull request has been reviewed and/or tested by multiple users and is ready for a final review.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants