go-tools
go-tools copied to clipboard
errcheck: bufio.NewScanner return values that never get .Err() called
There's (apparently) a common mistake where people forget to check bufio.Scanner errors after the loop ends:
func foo(r io.Reader) {
scanner := bufio.NewScanner(r)
for scanner.Scan() {
fmt.Println(scanner.Text())
}
}
Any return value of bufio.NewScanner that doesn't see a call for scanner.Err is a mistake.
To keep analysis simple and avoid false positives, maybe bail out on complex scenarios like where the scanner value is passed outside of the local scope.
See also https://github.com/golang/go/issues/17747.