Skip to content

Commit

Permalink
Merge pull request #252 from djdv/ignore-maphash
Browse files Browse the repository at this point in the history
exclude maphash methods that "never fail"
  • Loading branch information
dtcaciuc authored Oct 16, 2024
2 parents b832de3 + c277fb1 commit df44f75
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
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

0 comments on commit df44f75

Please sign in to comment.