github.com/vanstinator/golangci-lint@v0.0.0-20240223191551-cc572f00d9d1/test/testdata/perfsprint.go (about)

     1  //golangcitest:args -Eperfsprint
     2  package testdata
     3  
     4  import (
     5  	"fmt" // want "Fix imports"
     6  )
     7  
     8  func TestPerfsprint() {
     9  	var (
    10  		s   string
    11  		err error
    12  		b   bool
    13  		i   int
    14  		i64 int64
    15  		ui  uint
    16  	)
    17  
    18  	fmt.Sprintf("%s", s) // want "fmt.Sprintf can be replaced with just using the string"
    19  	fmt.Sprint(s)        // want "fmt.Sprint can be replaced with just using the string"
    20  	fmt.Sprintf("%s", err)
    21  	fmt.Sprint(err)
    22  	fmt.Sprintf("%t", b)           // want "fmt.Sprintf can be replaced with faster strconv.FormatBool"
    23  	fmt.Sprint(b)                  // want "fmt.Sprint can be replaced with faster strconv.FormatBool"
    24  	fmt.Sprintf("%d", i)           // want "fmt.Sprintf can be replaced with faster strconv.Itoa"
    25  	fmt.Sprint(i)                  // want "fmt.Sprint can be replaced with faster strconv.Itoa"
    26  	fmt.Sprintf("%d", i64)         // want "fmt.Sprintf can be replaced with faster strconv.FormatInt"
    27  	fmt.Sprint(i64)                // want "fmt.Sprint can be replaced with faster strconv.FormatInt"
    28  	fmt.Sprintf("%d", ui)          // want "fmt.Sprintf can be replaced with faster strconv.FormatUint"
    29  	fmt.Sprint(ui)                 // want "fmt.Sprint can be replaced with faster strconv.FormatUint"
    30  	fmt.Sprintf("%x", []byte{'a'}) // want "fmt.Sprintf can be replaced with faster hex.EncodeToString"
    31  	fmt.Errorf("hello")            // want "fmt.Errorf can be replaced with errors.New"
    32  	fmt.Sprintf("Hello %s", s)     // want "fmt.Sprintf can be replaced with string addition"
    33  
    34  	fmt.Sprint("test", 42)
    35  	fmt.Sprint(42, 42)
    36  	fmt.Sprintf("test") // want "fmt.Sprintf can be replaced with just using the string"
    37  	fmt.Sprintf("%v")   // want "fmt.Sprintf can be replaced with just using the string"
    38  	fmt.Sprintf("%d")   // want "fmt.Sprintf can be replaced with just using the string"
    39  	fmt.Sprintf("%d", 42, 42)
    40  	fmt.Sprintf("%#d", 42)
    41  	fmt.Sprintf("value %d", 42)
    42  	fmt.Sprintf("val%d", 42)
    43  	fmt.Sprintf("%s %v", "hello", "world")
    44  	fmt.Sprintf("%#v", 42)
    45  	fmt.Sprintf("%T", struct{ string }{})
    46  	fmt.Sprintf("%%v", 42)
    47  	fmt.Sprintf("%3d", 42)
    48  	fmt.Sprintf("% d", 42)
    49  	fmt.Sprintf("%-10d", 42)
    50  	fmt.Sprintf("%[2]d %[1]d\n", 11, 22)
    51  	fmt.Sprintf("%[3]*.[2]*[1]f", 12.0, 2, 6)
    52  	fmt.Sprintf("%d %d %#[1]x %#x", 16, 17)
    53  }