mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Chore/fix lint issues (#27704)
* Chore: Fix linting issues Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
This commit is contained in:
parent
ffc11cb63c
commit
a5d9196a53
@ -201,9 +201,9 @@ func (c *StorageClient) FileUpload(ctx context.Context, container, blobName stri
|
||||
func escape(content string) string {
|
||||
content = url.QueryEscape(content)
|
||||
// the Azure's behavior uses %20 to represent whitespace instead of + (plus)
|
||||
content = strings.Replace(content, "+", "%20", -1)
|
||||
content = strings.ReplaceAll(content, "+", "%20")
|
||||
// the Azure's behavior uses slash instead of + %2F
|
||||
content = strings.Replace(content, "%2F", "/", -1)
|
||||
content = strings.ReplaceAll(content, "%2F", "/")
|
||||
|
||||
return content
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ var netClient = &http.Client{
|
||||
|
||||
func (u *WebdavUploader) PublicURL(filename string) string {
|
||||
if strings.Contains(u.public_url, "${file}") {
|
||||
return strings.Replace(u.public_url, "${file}", filename, -1)
|
||||
return strings.ReplaceAll(u.public_url, "${file}", filename)
|
||||
}
|
||||
|
||||
publicURL, _ := url.Parse(u.public_url)
|
||||
|
@ -48,14 +48,14 @@ func (im *InternalMetricsService) parseGraphiteSettings() error {
|
||||
ErrorHandling: graphitebridge.ContinueOnError,
|
||||
}
|
||||
|
||||
safeInstanceName := strings.Replace(setting.InstanceName, ".", "_", -1)
|
||||
safeInstanceName := strings.ReplaceAll(setting.InstanceName, ".", "_")
|
||||
prefix := graphiteSection.Key("prefix").Value()
|
||||
|
||||
if prefix == "" {
|
||||
prefix = "prod.grafana.%(instance_name)s."
|
||||
}
|
||||
|
||||
bridgeCfg.Prefix = strings.Replace(prefix, "%(instance_name)s", safeInstanceName, -1)
|
||||
bridgeCfg.Prefix = strings.ReplaceAll(prefix, "%(instance_name)s", safeInstanceName)
|
||||
|
||||
im.graphiteCfg = bridgeCfg
|
||||
return nil
|
||||
|
@ -28,7 +28,7 @@ type UsageReport struct {
|
||||
}
|
||||
|
||||
func (uss *UsageStatsService) GetUsageReport() (UsageReport, error) {
|
||||
version := strings.Replace(setting.BuildVersion, ".", "_", -1)
|
||||
version := strings.ReplaceAll(setting.BuildVersion, ".", "_")
|
||||
|
||||
metrics := map[string]interface{}{}
|
||||
|
||||
|
@ -93,7 +93,7 @@ func function(pc uintptr) []byte {
|
||||
if period := bytes.Index(name, dot); period >= 0 {
|
||||
name = name[period+1:]
|
||||
}
|
||||
name = bytes.Replace(name, centerDot, dot, -1)
|
||||
name = bytes.ReplaceAll(name, centerDot, dot)
|
||||
return name
|
||||
}
|
||||
|
||||
|
@ -41,7 +41,7 @@ func getPluginLogoUrl(pluginType, path, baseUrl string) string {
|
||||
}
|
||||
|
||||
func (fp *FrontendPluginBase) setPathsBasedOnApp(app *AppPlugin) {
|
||||
appSubPath := strings.Replace(strings.Replace(fp.PluginDir, app.PluginDir, "", 1), "\\", "/", -1)
|
||||
appSubPath := strings.ReplaceAll(strings.Replace(fp.PluginDir, app.PluginDir, "", 1), "\\", "/")
|
||||
fp.IncludedInAppId = app.Id
|
||||
fp.BaseUrl = app.BaseUrl
|
||||
|
||||
|
@ -95,7 +95,7 @@ func (sn *SensuNotifier) Notify(evalContext *alerting.EvalContext) error {
|
||||
bodyJSON := simplejson.New()
|
||||
bodyJSON.Set("ruleId", evalContext.Rule.ID)
|
||||
// Sensu alerts cannot have spaces in them
|
||||
bodyJSON.Set("name", strings.Replace(evalContext.Rule.Name, " ", "_", -1))
|
||||
bodyJSON.Set("name", strings.ReplaceAll(evalContext.Rule.Name, " ", "_"))
|
||||
// Sensu alerts require a source. We set it to the user-specified value (optional),
|
||||
// else we fallback and use the grafana ruleID.
|
||||
if sn.Source != "" {
|
||||
|
@ -13,7 +13,7 @@ package alerting
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//// returns the new last tick seen
|
||||
// returns the new last tick seen
|
||||
// func assertAdvanceUntil(ticker *Ticker, last, desiredLast time.Time, offset, wait time.Duration, t *testing.T) time.Time {
|
||||
// for {
|
||||
// select {
|
||||
|
@ -363,10 +363,9 @@ func (server *Server) getSearchRequest(
|
||||
|
||||
search := ""
|
||||
for _, login := range logins {
|
||||
query := strings.Replace(
|
||||
query := strings.ReplaceAll(
|
||||
server.Config.SearchFilter,
|
||||
"%s", ldap.EscapeFilter(login),
|
||||
-1,
|
||||
)
|
||||
|
||||
search += query
|
||||
@ -509,10 +508,9 @@ func (server *Server) requestMemberOf(entry *ldap.Entry) ([]string, error) {
|
||||
)
|
||||
}
|
||||
|
||||
filter := strings.Replace(
|
||||
filter := strings.ReplaceAll(
|
||||
config.GroupSearchFilter, "%s",
|
||||
ldap.EscapeFilter(filterReplace),
|
||||
-1,
|
||||
)
|
||||
|
||||
server.log.Info("Searching for user's groups", "filter", filter)
|
||||
|
@ -23,9 +23,7 @@ func validateTimeRange(item *annotations.Item) error {
|
||||
item.Epoch = item.EpochEnd
|
||||
}
|
||||
if item.EpochEnd < item.Epoch {
|
||||
tmp := item.Epoch
|
||||
item.Epoch = item.EpochEnd
|
||||
item.EpochEnd = tmp
|
||||
item.Epoch, item.EpochEnd = item.EpochEnd, item.Epoch
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -65,9 +65,9 @@ func addAnnotationMig(mg *Migrator) {
|
||||
Name: "tags", Type: DB_NVarchar, Nullable: true, Length: 500,
|
||||
}))
|
||||
|
||||
///
|
||||
/// Annotation tag
|
||||
///
|
||||
//
|
||||
// Annotation tag
|
||||
//
|
||||
annotationTagTable := Table{
|
||||
Name: "annotation_tag",
|
||||
Columns: []*Column{
|
||||
|
@ -40,7 +40,9 @@ func TestMigrations(t *testing.T) {
|
||||
has, err := x.SQL(sql).Get(&r)
|
||||
So(err, ShouldBeNil)
|
||||
So(has, ShouldBeTrue)
|
||||
expectedMigrations := mg.MigrationsCount() //we currently skip to migrations. We should rewrite skipped migrations to write in the log as well. until then we have to keep this
|
||||
// we currently skip to migrations. We should rewrite skipped migrations to write in the log as well.
|
||||
// until then we have to keep this
|
||||
expectedMigrations := mg.MigrationsCount()
|
||||
So(r.Count, ShouldEqual, expectedMigrations)
|
||||
|
||||
mg = NewMigrator(x)
|
||||
|
@ -423,9 +423,9 @@ type AnnotationCleanupSettings struct {
|
||||
}
|
||||
|
||||
func envKey(sectionName string, keyName string) string {
|
||||
sN := strings.ToUpper(strings.Replace(sectionName, ".", "_", -1))
|
||||
sN = strings.Replace(sN, "-", "_", -1)
|
||||
kN := strings.ToUpper(strings.Replace(keyName, ".", "_", -1))
|
||||
sN := strings.ToUpper(strings.ReplaceAll(sectionName, ".", "_"))
|
||||
sN = strings.ReplaceAll(sN, "-", "_")
|
||||
kN := strings.ToUpper(strings.ReplaceAll(keyName, ".", "_"))
|
||||
envKey := fmt.Sprintf("GF_%s_%s", sN, kN)
|
||||
return envKey
|
||||
}
|
||||
|
@ -320,7 +320,7 @@ func interpolateFilterWildcards(value string) string {
|
||||
matches := strings.Count(value, "*")
|
||||
switch {
|
||||
case matches == 2 && strings.HasSuffix(value, "*") && strings.HasPrefix(value, "*"):
|
||||
value = strings.Replace(value, "*", "", -1)
|
||||
value = strings.ReplaceAll(value, "*", "")
|
||||
value = fmt.Sprintf(`has_substring("%s")`, value)
|
||||
case matches == 1 && strings.HasPrefix(value, "*"):
|
||||
value = strings.Replace(value, "*", "", 1)
|
||||
@ -332,8 +332,8 @@ func interpolateFilterWildcards(value string) string {
|
||||
value = string(wildcardRegexRe.ReplaceAllFunc([]byte(value), func(in []byte) []byte {
|
||||
return []byte(strings.Replace(string(in), string(in), `\\`+string(in), 1))
|
||||
}))
|
||||
value = strings.Replace(value, "*", ".*", -1)
|
||||
value = strings.Replace(value, `"`, `\\"`, -1)
|
||||
value = strings.ReplaceAll(value, "*", ".*")
|
||||
value = strings.ReplaceAll(value, `"`, `\\"`)
|
||||
value = fmt.Sprintf(`monitoring.regex.full_match("^%s$")`, value)
|
||||
}
|
||||
|
||||
|
@ -141,8 +141,8 @@ func (c *baseClientImpl) encodeBatchRequests(requests []*multiRequest) ([]byte,
|
||||
}
|
||||
|
||||
body := string(reqBody)
|
||||
body = strings.Replace(body, "$__interval_ms", strconv.FormatInt(r.interval.Milliseconds(), 10), -1)
|
||||
body = strings.Replace(body, "$__interval", r.interval.Text, -1)
|
||||
body = strings.ReplaceAll(body, "$__interval_ms", strconv.FormatInt(r.interval.Milliseconds(), 10))
|
||||
body = strings.ReplaceAll(body, "$__interval", r.interval.Text)
|
||||
|
||||
payload.WriteString(body + "\n")
|
||||
}
|
||||
|
@ -277,11 +277,11 @@ func formatDate(t time.Time, pattern string) string {
|
||||
if strings.Contains(formatted, "<std") {
|
||||
isoYear, isoWeek := t.ISOWeek()
|
||||
isoYearShort := fmt.Sprintf("%d", isoYear)[2:4]
|
||||
formatted = strings.Replace(formatted, "<stdIsoYear>", fmt.Sprintf("%d", isoYear), -1)
|
||||
formatted = strings.Replace(formatted, "<stdIsoYearShort>", isoYearShort, -1)
|
||||
formatted = strings.Replace(formatted, "<stdWeekOfYear>", fmt.Sprintf("%02d", isoWeek), -1)
|
||||
formatted = strings.ReplaceAll(formatted, "<stdIsoYear>", fmt.Sprintf("%d", isoYear))
|
||||
formatted = strings.ReplaceAll(formatted, "<stdIsoYearShort>", isoYearShort)
|
||||
formatted = strings.ReplaceAll(formatted, "<stdWeekOfYear>", fmt.Sprintf("%02d", isoWeek))
|
||||
|
||||
formatted = strings.Replace(formatted, "<stdUnix>", fmt.Sprintf("%d", t.Unix()), -1)
|
||||
formatted = strings.ReplaceAll(formatted, "<stdUnix>", fmt.Sprintf("%d", t.Unix()))
|
||||
|
||||
day := t.Weekday()
|
||||
dayOfWeekIso := int(day)
|
||||
@ -289,9 +289,9 @@ func formatDate(t time.Time, pattern string) string {
|
||||
dayOfWeekIso = 7
|
||||
}
|
||||
|
||||
formatted = strings.Replace(formatted, "<stdDayOfWeek>", fmt.Sprintf("%d", day), -1)
|
||||
formatted = strings.Replace(formatted, "<stdDayOfWeekISO>", fmt.Sprintf("%d", dayOfWeekIso), -1)
|
||||
formatted = strings.Replace(formatted, "<stdDayOfYear>", fmt.Sprintf("%d", t.YearDay()), -1)
|
||||
formatted = strings.ReplaceAll(formatted, "<stdDayOfWeek>", fmt.Sprintf("%d", day))
|
||||
formatted = strings.ReplaceAll(formatted, "<stdDayOfWeekISO>", fmt.Sprintf("%d", dayOfWeekIso))
|
||||
formatted = strings.ReplaceAll(formatted, "<stdDayOfYear>", fmt.Sprintf("%d", t.YearDay()))
|
||||
|
||||
quarter := 4
|
||||
|
||||
@ -304,8 +304,8 @@ func formatDate(t time.Time, pattern string) string {
|
||||
quarter = 3
|
||||
}
|
||||
|
||||
formatted = strings.Replace(formatted, "<stdQuarter>", fmt.Sprintf("%d", quarter), -1)
|
||||
formatted = strings.Replace(formatted, "<stdHourNoZero>", fmt.Sprintf("%d", t.Hour()), -1)
|
||||
formatted = strings.ReplaceAll(formatted, "<stdQuarter>", fmt.Sprintf("%d", quarter))
|
||||
formatted = strings.ReplaceAll(formatted, "<stdHourNoZero>", fmt.Sprintf("%d", t.Hour()))
|
||||
}
|
||||
|
||||
if ltr {
|
||||
|
@ -484,7 +484,7 @@ func (rp *responseParser) getSeriesName(series *tsdb.TimeSeries, target *Query,
|
||||
for name, pipelineAgg := range metric.PipelineVariables {
|
||||
for _, m := range target.Metrics {
|
||||
if m.ID == pipelineAgg {
|
||||
metricName = strings.Replace(metricName, "params."+name, describeMetric(m.Type, m.Field), -1)
|
||||
metricName = strings.ReplaceAll(metricName, "params."+name, describeMetric(m.Type, m.Field))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -178,17 +178,17 @@ func formatTimeRange(input string) string {
|
||||
if input == "now" {
|
||||
return input
|
||||
}
|
||||
return strings.Replace(strings.Replace(strings.Replace(input, "now", "", -1), "m", "min", -1), "M", "mon", -1)
|
||||
return strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll(input, "now", ""), "m", "min"), "M", "mon")
|
||||
}
|
||||
|
||||
func fixIntervalFormat(target string) string {
|
||||
rMinute := regexp.MustCompile(`'(\d+)m'`)
|
||||
target = rMinute.ReplaceAllStringFunc(target, func(m string) string {
|
||||
return strings.Replace(m, "m", "min", -1)
|
||||
return strings.ReplaceAll(m, "m", "min")
|
||||
})
|
||||
rMonth := regexp.MustCompile(`'(\d+)M'`)
|
||||
target = rMonth.ReplaceAllStringFunc(target, func(M string) string {
|
||||
return strings.Replace(M, "M", "mon", -1)
|
||||
return strings.ReplaceAll(M, "M", "mon")
|
||||
})
|
||||
return target
|
||||
}
|
||||
|
@ -30,10 +30,10 @@ func (query *Query) Build(queryContext *tsdb.TsdbQuery) (string, error) {
|
||||
calculator := tsdb.NewIntervalCalculator(&tsdb.IntervalOptions{})
|
||||
interval := calculator.Calculate(queryContext.TimeRange, query.Interval)
|
||||
|
||||
res = strings.Replace(res, "$timeFilter", query.renderTimeFilter(queryContext), -1)
|
||||
res = strings.Replace(res, "$interval", interval.Text, -1)
|
||||
res = strings.Replace(res, "$__interval_ms", strconv.FormatInt(interval.Milliseconds(), 10), -1)
|
||||
res = strings.Replace(res, "$__interval", interval.Text, -1)
|
||||
res = strings.ReplaceAll(res, "$timeFilter", query.renderTimeFilter(queryContext))
|
||||
res = strings.ReplaceAll(res, "$interval", interval.Text)
|
||||
res = strings.ReplaceAll(res, "$__interval_ms", strconv.FormatInt(interval.Milliseconds(), 10))
|
||||
res = strings.ReplaceAll(res, "$__interval", interval.Text)
|
||||
return res, nil
|
||||
}
|
||||
|
||||
@ -68,7 +68,7 @@ func (query *Query) renderTags() []string {
|
||||
case "<", ">":
|
||||
textValue = tag.Value
|
||||
default:
|
||||
textValue = fmt.Sprintf("'%s'", strings.Replace(tag.Value, `\`, `\\`, -1))
|
||||
textValue = fmt.Sprintf("'%s'", strings.ReplaceAll(tag.Value, `\`, `\\`))
|
||||
}
|
||||
|
||||
res = append(res, fmt.Sprintf(`%s"%s" %s %s`, str, tag.Key, tag.Operator, textValue))
|
||||
|
@ -25,7 +25,7 @@ func init() {
|
||||
}
|
||||
|
||||
func characterEscape(s string, escapeChar string) string {
|
||||
return strings.Replace(s, escapeChar, url.QueryEscape(escapeChar), -1)
|
||||
return strings.ReplaceAll(s, escapeChar, url.QueryEscape(escapeChar))
|
||||
}
|
||||
|
||||
func newMysqlQueryEndpoint(datasource *models.DataSource) (tsdb.TsdbQueryEndpoint, error) {
|
||||
|
@ -58,7 +58,7 @@ func newPostgresQueryEndpoint(datasource *models.DataSource) (tsdb.TsdbQueryEndp
|
||||
|
||||
// escape single quotes and backslashes in Postgres connection string parameters.
|
||||
func escape(input string) string {
|
||||
return strings.Replace(strings.Replace(input, `\`, `\\`, -1), "'", `\'`, -1)
|
||||
return strings.ReplaceAll(strings.ReplaceAll(input, `\`, `\\`), "'", `\'`)
|
||||
}
|
||||
|
||||
func generateConnectionString(datasource *models.DataSource, logger log.Logger) (string, error) {
|
||||
|
@ -207,10 +207,10 @@ var Interpolate = func(query *tsdb.Query, timeRange *tsdb.TimeRange, sql string)
|
||||
}
|
||||
interval := sqlIntervalCalculator.Calculate(timeRange, minInterval)
|
||||
|
||||
sql = strings.Replace(sql, "$__interval_ms", strconv.FormatInt(interval.Milliseconds(), 10), -1)
|
||||
sql = strings.Replace(sql, "$__interval", interval.Text, -1)
|
||||
sql = strings.Replace(sql, "$__unixEpochFrom()", fmt.Sprintf("%d", timeRange.GetFromAsSecondsEpoch()), -1)
|
||||
sql = strings.Replace(sql, "$__unixEpochTo()", fmt.Sprintf("%d", timeRange.GetToAsSecondsEpoch()), -1)
|
||||
sql = strings.ReplaceAll(sql, "$__interval_ms", strconv.FormatInt(interval.Milliseconds(), 10))
|
||||
sql = strings.ReplaceAll(sql, "$__interval", interval.Text)
|
||||
sql = strings.ReplaceAll(sql, "$__unixEpochFrom()", fmt.Sprintf("%d", timeRange.GetFromAsSecondsEpoch()))
|
||||
sql = strings.ReplaceAll(sql, "$__unixEpochTo()", fmt.Sprintf("%d", timeRange.GetToAsSecondsEpoch()))
|
||||
|
||||
return sql, nil
|
||||
}
|
||||
|
@ -218,7 +218,7 @@ func init() {
|
||||
queryRes := tsdb.NewQueryResult()
|
||||
|
||||
stringInput := query.Model.Get("stringInput").MustString()
|
||||
stringInput = strings.Replace(stringInput, " ", "", -1)
|
||||
stringInput = strings.ReplaceAll(stringInput, " ", "")
|
||||
|
||||
values := []null.Float{}
|
||||
for _, strVal := range strings.Split(stringInput, ",") {
|
||||
|
@ -61,7 +61,7 @@ func Encrypt(payload []byte, secret string) ([]byte, error) {
|
||||
// The IV needs to be unique, but not secure. Therefore it's common to
|
||||
// include it at the beginning of the ciphertext.
|
||||
ciphertext := make([]byte, saltLength+aes.BlockSize+len(payload))
|
||||
copy(ciphertext[:saltLength], []byte(salt))
|
||||
copy(ciphertext[:saltLength], salt)
|
||||
iv := ciphertext[saltLength : saltLength+aes.BlockSize]
|
||||
if _, err := io.ReadFull(rand.Reader, iv); err != nil {
|
||||
return nil, err
|
||||
|
Loading…
Reference in New Issue
Block a user