github.com/mvdan/interfacer@v0.0.0-20180901003855-c20040233aed/README.md (about) 1 # interfacer 2 3 [![GoDoc](https://godoc.org/mvdan.cc/interfacer?status.svg)](https://godoc.org/mvdan.cc/interfacer) 4 [![Build Status](https://travis-ci.org/mvdan/interfacer.svg?branch=master)](https://travis-ci.org/mvdan/interfacer) 5 6 **Deprecated**: A tool that suggests interfaces is prone to bad suggestions, so 7 its usefulness in real code is limited. This tool will remain available as a 8 proof of concept, and for others to examine and learn from. 9 10 A linter that suggests interface types. In other words, it warns about 11 the usage of types that are more specific than necessary. 12 13 go get -u mvdan.cc/interfacer 14 15 Note that this linter's suggestions tend to be subjective, as interfaces 16 are not always the better option. You should select the proposed changes 17 that make sense in your codebase, instead of following all of them 18 blindly. 19 20 ### Usage 21 22 ```go 23 func ProcessInput(f *os.File) error { 24 b, err := ioutil.ReadAll(f) 25 if err != nil { 26 return err 27 } 28 return processBytes(b) 29 } 30 ``` 31 32 ```sh 33 $ interfacer ./... 34 foo.go:10:19: f can be io.Reader 35 ``` 36 37 ### Basic idea 38 39 This tool inspects the parameters of your functions to see if they fit 40 an interface type that is less specific than the current type. 41 42 The example above illustrates this point. Overly specific interfaces 43 also trigger a warning - if `f` were an `io.ReadCloser`, the same 44 message would appear. 45 46 It suggests interface types defined both in the func's package and the 47 package's imports (two levels; direct imports and their direct imports). 48 49 ### False positives 50 51 To avoid false positives, it never does any suggestions on functions 52 that may be implementing an interface method or a named function type. 53 54 It also skips parameters passed by value (excluding pointers and 55 interfaces) on unexported functions, since that would introduce extra 56 allocations where they are usually not worth the tradeoff. 57 58 ### Suppressing warnings 59 60 If a suggestion is technically correct but doesn't make sense, you can 61 still suppress the warning by mentioning the type in the function name: 62 63 ```go 64 func ProcessInputFile(f *os.File) error { 65 // use as an io.Reader 66 } 67 ```