Go

Go

Made by DeepSource

Don't use fmt.Sprintf("%s", x) unnecessarily SCC-S1025

Anti-pattern
Major
Autofix

There are more accessible and efficient ways of getting a value's string representation in many instances. Whenever a value's underlying type is a string already, or the type has a String() method, they should be used directly.

Given the following shared definitions:

type T1 string
type T2 int

func (T2) String() string { return "Hello, world" }

var x string
var y T1
var z T2

Bad practice

fmt.Sprintf("%s", x)
fmt.Sprintf("%s", y)
fmt.Sprintf("%s", z)

Recommended

x
string(y)
z.String()