@@ -106,6 +106,30 @@ type Checker struct {
106106
107107 // If true, checking of of _test.go files is disabled
108108 WithoutTests bool
109+
110+ exclude map [string ]bool
111+ }
112+
113+ func NewChecker () * Checker {
114+ c := Checker {}
115+ c .SetExclude (map [string ]bool {})
116+ return & c
117+ }
118+
119+ func (c * Checker ) SetExclude (l map [string ]bool ) {
120+ // Default exclude for stdlib functions
121+ c .exclude = map [string ]bool {
122+ "math/rand.Read" : true ,
123+ "(*math/rand.Rand).Read" : true ,
124+
125+ "(*bytes.Buffer).Write" : true ,
126+ "(*bytes.Buffer).WriteByte" : true ,
127+ "(*bytes.Buffer).WriteRune" : true ,
128+ "(*bytes.Buffer).WriteString" : true ,
129+ }
130+ for k := range l {
131+ c .exclude [k ] = true
132+ }
109133}
110134
111135func (c * Checker ) logf (msg string , args ... interface {}) {
@@ -160,6 +184,7 @@ func (c *Checker) CheckPackages(paths ...string) error {
160184 blank : c .Blank ,
161185 asserts : c .Asserts ,
162186 lines : make (map [string ][]string ),
187+ exclude : c .exclude ,
163188 errors : []UncheckedError {},
164189 }
165190
@@ -186,22 +211,12 @@ type visitor struct {
186211 blank bool
187212 asserts bool
188213 lines map [string ][]string
214+ exclude map [string ]bool
189215
190216 errors []UncheckedError
191217}
192218
193- func (v * visitor ) builtinIgnoreCall (call * ast.CallExpr ) bool {
194- // TODO(dh): find a better name for this method
195- ignored := map [string ]bool {
196- "math/rand.Read" : true ,
197- "(*math/rand.Rand).Read" : true ,
198-
199- "(*bytes.Buffer).Write" : true ,
200- "(*bytes.Buffer).WriteByte" : true ,
201- "(*bytes.Buffer).WriteRune" : true ,
202- "(*bytes.Buffer).WriteString" : true ,
203- }
204-
219+ func (v * visitor ) excludeCall (call * ast.CallExpr ) bool {
205220 sel , ok := call .Fun .(* ast.SelectorExpr )
206221 if ! ok {
207222 return false
@@ -219,11 +234,11 @@ func (v *visitor) builtinIgnoreCall(call *ast.CallExpr) bool {
219234 // want to support vendored stdlib packages, we need to implement
220235 // FullName with our own logic.
221236 name := fn .FullName ()
222- return ignored [name ]
237+ return v . exclude [name ]
223238}
224239
225240func (v * visitor ) ignoreCall (call * ast.CallExpr ) bool {
226- if v .builtinIgnoreCall (call ) {
241+ if v .excludeCall (call ) {
227242 return true
228243 }
229244
0 commit comments