strings.HasPrefix
with constant strings as arguments GO-W1022There's a possible a bug-risk because of the usage of constant strings as arguments to
strings.HasPrefix
. It implies that the result of strings.HasPrefix
is already known,
and we could have avoided the usage of the function entirely. Especially, the first argument
of the function is not expected to be a constant string literal.
s := "hello world"
if strings.HasPrefix("s", "pre") {
// body
}
s := "hello world"
if strings.HasPrefix(s, "pre") {
// body
}