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

exclude maphash methods that "never fail" #252

Merged
merged 2 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions errcheck/excludes.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ var DefaultExcludedSymbols = []string{

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

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

// ReadExcludes reads an excludes file, a newline delimited file that lists
Expand Down
17 changes: 17 additions & 0 deletions testdata/hash.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package main

import (
"crypto/sha256"
"hash/maphash"
)

func ignoreHashReturns() {
sha256.New().Write([]byte{}) // EXCLUDED
}

func ignoreHashMapReturns() {
var hasher maphash.Hash
hasher.Write(nil) // EXCLUDED
hasher.WriteByte(0) // EXCLUDED
hasher.WriteString("") // EXCLUDED
}
2 changes: 0 additions & 2 deletions testdata/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"bytes"
"crypto/sha256"
"fmt"
"io"
"math/rand"
Expand Down Expand Up @@ -147,7 +146,6 @@ func main() {
b2.Write(nil)
rand.Read(nil)
mrand.Read(nil)
sha256.New().Write([]byte{})
pr, pw := io.Pipe()
pr.CloseWithError(nil)
pw.CloseWithError(nil)
Expand Down
Loading