Debian Codegraph @

simple/s1030/testdata/go1.0/CheckBytesBufferConversions/LintBytesBufferConversions.go

raw
1 package pkg
2
3 import (
4 "bytes"
5 )
6
7 func fn() {
8 buf := bytes.NewBufferString("str")
9 _ = string(buf.Bytes()) //@ diag(`should use buf.String() instead of string(buf.Bytes())`)
10 _ = []byte(buf.String()) //@ diag(`should use buf.Bytes() instead of []byte(buf.String())`)
11
12 m := map[string]*bytes.Buffer{"key": buf}
13 _ = string(m["key"].Bytes()) //@ diag(`should use m["key"].String() instead of string(m["key"].Bytes())`)
14 _ = []byte(m["key"].String()) //@ diag(`should use m["key"].Bytes() instead of []byte(m["key"].String())`)
15
16 var m2 map[string]int
17 _ = m2[string(buf.Bytes())] // no warning, this is more efficient than buf.String()
18
19 string := func(_ interface{}) interface{} {
20 return nil
21 }
22 _ = string(m["key"].Bytes())
23 }