gitee.com/wgliang/goreporter@v0.0.0-20180902115603-df1b20f7c5d0/linters/simpler/testdata/LintStringCopy.go (about)

     1  package pkg
     2  
     3  import "fmt"
     4  
     5  type S1 string
     6  
     7  func (S1) String() string { return "hi" }
     8  
     9  type S2 string
    10  
    11  func (S2) Error() string { return "hi" }
    12  
    13  func fn(s string) {
    14  	_ = string([]byte(s)) // MATCH "should use s instead of string([]byte(s))"
    15  	_ = "" + s            // MATCH /should use s instead of "" \+ s/
    16  	_ = s + ""            // MATCH /should use s instead of s \+ ""/
    17  	_ = fmt.Sprint(s)     // MATCH "should use s instead of fmt.Sprint(s)"
    18  
    19  	_ = s
    20  	_ = s + "foo"
    21  	_ = s == ""
    22  	_ = s != ""
    23  	_ = "" +
    24  		"really long lines follow" +
    25  		"that need pretty formatting"
    26  	var a1 S1
    27  	var a2 S2
    28  	_ = fmt.Sprint(a1)
    29  	_ = fmt.Sprint(a2)
    30  
    31  	_ = string([]rune(s))
    32  	{
    33  		string := func(v interface{}) string {
    34  			return "foo"
    35  		}
    36  		_ = string([]byte(s))
    37  	}
    38  	{
    39  		type byte rune
    40  		_ = string([]byte(s))
    41  	}
    42  	{
    43  		type T []byte
    44  		var x T
    45  		_ = string([]byte(x))
    46  	}
    47  }