should use strings.Contains(file, valdRepo) instead
311 url += "#L" + strconv.Itoa(line)
312 case func() bool {
313 idx = strings.Index(file, goSrc)
314 return idx >= 0 && strings.Index(file, valdRepo) >= 0315 }():
316 url = strings.Replace(file[idx+goSrcLen:]+"#L"+strconv.Itoa(line), valdRepo, "https://"+valdRepo+"/blob/"+i.detail.GitCommit, -1)
317 case strings.HasPrefix(file, valdRepo):
Description
Prefer using strings.Contains(s, substr)
instead of
strings.Index(s, substr) != -1
to check if substr
is within s
.
To find the starting index of a substring within a string, the strings
package
in the standard library provides the Index
function. To check whether a string
contains a substring, the strings
package provides a Contains
function, a
wrapper on top of the strings.Index
function. While either of the functions
could be used for checking the existence of a substring, the strings.Contains
the function is more readable.
Bad practice
if strings.Index(x, y) != -1 {}
Recommended
if strings.Contains(x, y) {}