github.com/360EntSecGroup-skylar/goreporter@v0.0.0-20180902115603-df1b20f7c5d0/linters/interfacer/README.md (about) 1 # interfacer 2 3 [![GoDoc](https://godoc.org/github.com/mvdan/interfacer?status.svg)](https://godoc.org/github.com/mvdan/interfacer) 4 [![Build Status](https://travis-ci.org/mvdan/interfacer.svg?branch=master)](https://travis-ci.org/mvdan/interfacer) 5 6 A linter that suggests interface types. In other words, it warns about 7 the usage of types that are more specific than necessary. 8 9 go get -u github.com/mvdan/interfacer/cmd/interfacer 10 11 ### Usage 12 13 ```go 14 func ProcessInput(f *os.File) error { 15 b, err := ioutil.ReadAll(f) 16 if err != nil { 17 return err 18 } 19 return processBytes(b) 20 } 21 ``` 22 23 ```sh 24 $ interfacer $(go list ./... | grep -v /vendor/) 25 foo.go:10:19: f can be io.Reader 26 ``` 27 28 ### Basic idea 29 30 This tool inspects the parameters of your functions to see if they fit 31 an interface type that is less specific than the current type. 32 33 The example above illustrates this point. Overly specific interfaces 34 also trigger a warning - if `f` were an `io.ReadCloser`, the same 35 message would appear. 36 37 It suggests interface types defined both in the func's package and the 38 package's imports (two levels; direct imports and their direct imports). 39 40 ### False positives 41 42 To avoid false positives, it never does any suggestions on functions 43 that may be implementing an interface method or a named function type. 44 45 It also skips parameters passed by value (excluding pointers and 46 interfaces) on unexported functions, since that would introduce extra 47 allocations where they are usually not worth the tradeoff. 48 49 ### Suppressing warnings 50 51 If a suggestion is technically correct but doesn't make sense, you can 52 still suppress the warning by mentioning the type in the function name: 53 54 ```go 55 func ProcessInputFile(f *os.File) error { 56 // use as an io.Reader 57 } 58 ```