Skip to content

Commit df44f75

Browse files
authored
Merge pull request #252 from djdv/ignore-maphash
exclude maphash methods that "never fail"
2 parents b832de3 + c277fb1 commit df44f75

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

errcheck/excludes.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ var DefaultExcludedSymbols = []string{
4747

4848
// hash
4949
"(hash.Hash).Write",
50+
51+
// hash/maphash
52+
"(*hash/maphash.Hash).Write",
53+
"(*hash/maphash.Hash).WriteByte",
54+
"(*hash/maphash.Hash).WriteString",
5055
}
5156

5257
// ReadExcludes reads an excludes file, a newline delimited file that lists

testdata/hash.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package main
2+
3+
import (
4+
"crypto/sha256"
5+
"hash/maphash"
6+
)
7+
8+
func ignoreHashReturns() {
9+
sha256.New().Write([]byte{}) // EXCLUDED
10+
}
11+
12+
func ignoreHashMapReturns() {
13+
var hasher maphash.Hash
14+
hasher.Write(nil) // EXCLUDED
15+
hasher.WriteByte(0) // EXCLUDED
16+
hasher.WriteString("") // EXCLUDED
17+
}

testdata/main.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package main
22

33
import (
44
"bytes"
5-
"crypto/sha256"
65
"fmt"
76
"io"
87
"math/rand"
@@ -147,7 +146,6 @@ func main() {
147146
b2.Write(nil)
148147
rand.Read(nil)
149148
mrand.Read(nil)
150-
sha256.New().Write([]byte{})
151149
pr, pw := io.Pipe()
152150
pr.CloseWithError(nil)
153151
pw.CloseWithError(nil)

0 commit comments

Comments
 (0)