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

Review not needed and missing blank identifiers used for error #13013

Closed
zak-pawel opened this issue Apr 3, 2023 · 1 comment · Fixed by #15518
Closed

Review not needed and missing blank identifiers used for error #13013

zak-pawel opened this issue Apr 3, 2023 · 1 comment · Fixed by #15518
Assignees
Labels
feature request Requests for new plugin and for new features to existing plugins linter

Comments

@zak-pawel
Copy link
Collaborator

zak-pawel commented Apr 3, 2023

Use Case

errcheck linter has default exclusion list (which can be extended in .golangci.yml)
https://github.com/kisielk/errcheck/blob/master/errcheck/excludes.go#L11

	// 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",

Expected behavior

For excluded functions, there is no need to simulate handling error by using _ := function1(...), or _, _ := function2(...).
Remove blank identifiers for such cases (to find them something like this can be used: grep -nr '_, _ = (\w\+\.)\+Write' * ).

Additional info

Also, it would be good to handle errors properly for cases when blank identifier is used for non-excluded functions.

This configuration can find such cases:

linters-settings:
  errcheck:
    # report about assignment of errors to blank identifier: `num, _ := strconv.Atoi(numStr)`.
    # Such cases aren't reported by default.
    # Default: false
    check-blank: true
@zak-pawel zak-pawel added feature request Requests for new plugin and for new features to existing plugins linter labels Apr 3, 2023
@powersj
Copy link
Contributor

powersj commented Apr 3, 2023

next steps: look at the current state of the repo using the suggested grep, either create PR or come up with proposal for next step

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Requests for new plugin and for new features to existing plugins linter
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants