Skip to content

Commit

Permalink
Avoid naked returns
Browse files Browse the repository at this point in the history
  • Loading branch information
prymitive committed Nov 18, 2022
1 parent d7a2e93 commit dfb54d8
Show file tree
Hide file tree
Showing 32 changed files with 78 additions and 75 deletions.
3 changes: 3 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ linters:
- gocritic
- importas
- maligned
- nakedret
- prealloc
- promlinter
- unconvert
Expand All @@ -40,3 +41,5 @@ linters-settings:
local-prefixes: github.com/cloudflare/pint
gofumpt:
extra-rules: true
nakedret:
max-func-lines: 0
2 changes: 1 addition & 1 deletion cmd/pint/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,5 +119,5 @@ func verifyOwners(entries []discovery.Entry) (reports []reporter.Report) {
},
})
}
return
return reports
}
2 changes: 1 addition & 1 deletion internal/checks/alerts_comparison.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (c ComparisonCheck) Check(ctx context.Context, path string, rule parser.Rul
Severity: Warning,
})

return
return problems
}

func hasComparision(n promParser.Node) *promParser.BinaryExpr {
Expand Down
4 changes: 2 additions & 2 deletions internal/checks/alerts_count.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (c AlertsCheck) Check(ctx context.Context, path string, rule parser.Rule, e
Text: text,
Severity: severity,
})
return
return problems
}

if len(qr.Series.Ranges) > 0 {
Expand Down Expand Up @@ -105,5 +105,5 @@ func (c AlertsCheck) Check(ctx context.Context, path string, rule parser.Rule, e
Text: fmt.Sprintf("%s would trigger %d alert(s) in the last %s", promText(c.prom.Name(), qr.URI), alerts, output.HumanizeDuration(delta)),
Severity: Information,
})
return
return problems
}
4 changes: 2 additions & 2 deletions internal/checks/alerts_for.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (c AlertsForChecksFor) Check(ctx context.Context, path string, rule parser.
Text: fmt.Sprintf("invalid duration: %s", err),
Severity: Bug,
})
return
return problems
}

if d == 0 {
Expand All @@ -60,5 +60,5 @@ func (c AlertsForChecksFor) Check(ctx context.Context, path string, rule parser.
})
}

return
return problems
}
2 changes: 1 addition & 1 deletion internal/checks/alerts_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ func checkMetricLabels(msg, name, text string, metricLabels []string, excludeLab
}
}

return
return msgs
}

func absentLabels(f utils.PromQLFragment) []string {
Expand Down
2 changes: 1 addition & 1 deletion internal/checks/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func textAndSeverityFromError(err error, reporter, prom string, s Severity) (tex
}
severity = s
}
return
return text, severity
}

func promText(name, uri string) string {
Expand Down
2 changes: 1 addition & 1 deletion internal/checks/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ func generateSampleStream(labels map[string]string, from, until time.Time, step
})
from = from.Add(step)
}
return
return s
}

func checkErrorBadData(name, uri, err string) string {
Expand Down
10 changes: 5 additions & 5 deletions internal/checks/promql_aggregation.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (c AggregationCheck) Check(ctx context.Context, path string, rule parser.Ru
})
}

return
return problems
}

func (c AggregationCheck) checkNode(node *parser.PromQLNode) (problems []exprProblem) {
Expand All @@ -103,7 +103,7 @@ func (c AggregationCheck) checkNode(node *parser.PromQLNode) (problems []exprPro
if !n.Without && !c.keep && len(n.Grouping) == 0 {
// most outer aggregation is stripping a label that we want to get rid of
// we can skip further checks
return
return problems
}

var found bool
Expand Down Expand Up @@ -132,7 +132,7 @@ func (c AggregationCheck) checkNode(node *parser.PromQLNode) (problems []exprPro
// most outer aggregation is stripping a label that we want to get rid of
// we can skip further checks
if found && !c.keep {
return
return problems
}
} else {
if found && !c.keep {
Expand All @@ -152,7 +152,7 @@ func (c AggregationCheck) checkNode(node *parser.PromQLNode) (problems []exprPro
// most outer aggregation is stripping a label that we want to get rid of
// we can skip further checks
if !found && !c.keep {
return
return problems
}
}
}
Expand All @@ -177,5 +177,5 @@ NEXT:
problems = append(problems, c.checkNode(child)...)
}

return
return problems
}
4 changes: 2 additions & 2 deletions internal/checks/promql_fragile.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (c FragileCheck) Check(ctx context.Context, path string, rule parser.Rule,
Severity: Warning,
})
}
return
return problems
}

func (c FragileCheck) checkNode(node *parser.PromQLNode) (problems []exprProblem) {
Expand Down Expand Up @@ -96,5 +96,5 @@ NEXT:
problems = append(problems, c.checkNode(child)...)
}

return
return problems
}
4 changes: 2 additions & 2 deletions internal/checks/promql_range_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (c RangeQueryCheck) Check(ctx context.Context, path string, rule parser.Rul
})
}

return
return problems
}

func (c RangeQueryCheck) checkNode(ctx context.Context, node *parser.PromQLNode, retention time.Duration, uri string) (problems []exprProblem) {
Expand All @@ -104,5 +104,5 @@ func (c RangeQueryCheck) checkNode(ctx context.Context, node *parser.PromQLNode,
problems = append(problems, c.checkNode(ctx, child, retention, uri)...)
}

return
return problems
}
4 changes: 2 additions & 2 deletions internal/checks/promql_rate.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (c RateCheck) Check(ctx context.Context, path string, rule parser.Rule, ent
})
}

return
return problems
}

func (c RateCheck) checkNode(ctx context.Context, node *parser.PromQLNode, cfg *promapi.ConfigResult, done *completedList) (problems []exprProblem) {
Expand Down Expand Up @@ -127,7 +127,7 @@ func (c RateCheck) checkNode(ctx context.Context, node *parser.PromQLNode, cfg *
problems = append(problems, c.checkNode(ctx, child, cfg, done)...)
}

return
return problems
}

type completedList struct {
Expand Down
2 changes: 1 addition & 1 deletion internal/checks/promql_regexp.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,5 @@ func (c RegexpCheck) Check(ctx context.Context, path string, rule parser.Rule, e
}
}

return
return problems
}
8 changes: 4 additions & 4 deletions internal/checks/promql_series.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ func (c SeriesCheck) Check(ctx context.Context, path string, rule parser.Rule, e
}
}

return
return problems
}

func (c SeriesCheck) queryProblem(err error, selector string, expr parser.PromQLExpr) Problem {
Expand Down Expand Up @@ -507,7 +507,7 @@ func getSelectors(n *parser.PromQLNode) (selectors []promParser.VectorSelector)
selectors = append(selectors, getSelectors(child)...)
}

return
return selectors
}

func stripLabels(selector promParser.VectorSelector) promParser.VectorSelector {
Expand Down Expand Up @@ -582,7 +582,7 @@ func oldest(ranges []promapi.MetricTimeRange) (ts time.Time) {
ts = r.Start
}
}
return
return ts
}

func newest(ranges []promapi.MetricTimeRange) (ts time.Time) {
Expand All @@ -591,5 +591,5 @@ func newest(ranges []promapi.MetricTimeRange) (ts time.Time) {
ts = r.End
}
}
return
return ts
}
2 changes: 1 addition & 1 deletion internal/checks/promql_syntax.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@ func (c SyntaxCheck) Check(ctx context.Context, path string, rule parser.Rule, e
Severity: Fatal,
})
}
return
return problems
}
4 changes: 2 additions & 2 deletions internal/checks/promql_vector_matching.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (c VectorMatchingCheck) Check(ctx context.Context, path string, rule parser
})
}

return
return problems
}

func (c VectorMatchingCheck) checkNode(ctx context.Context, node *parser.PromQLNode) (problems []exprProblem) {
Expand Down Expand Up @@ -198,7 +198,7 @@ NEXT:
problems = append(problems, c.checkNode(ctx, child)...)
}

return
return problems
}

func (c VectorMatchingCheck) seriesLabels(ctx context.Context, query string, ignored ...model.LabelName) (labelSets, error) {
Expand Down
6 changes: 3 additions & 3 deletions internal/checks/query_cost.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (c CostCheck) Check(ctx context.Context, path string, rule parser.Rule, ent
expr := rule.Expr()

if expr.SyntaxError != nil {
return
return problems
}

query := fmt.Sprintf("count(%s)", expr.Value.Value)
Expand All @@ -62,7 +62,7 @@ func (c CostCheck) Check(ctx context.Context, path string, rule parser.Rule, ent
Text: text,
Severity: severity,
})
return
return problems
}

var series int
Expand Down Expand Up @@ -95,5 +95,5 @@ func (c CostCheck) Check(ctx context.Context, path string, rule parser.Rule, ent
Text: fmt.Sprintf("%s returned %d result(s)%s%s", promText(c.prom.Name(), qr.URI), series, estimate, above),
Severity: severity,
})
return
return problems
}
16 changes: 8 additions & 8 deletions internal/checks/rule_label.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (c LabelCheck) Check(ctx context.Context, path string, rule parser.Rule, en
problems = append(problems, c.checkAlertingRule(rule)...)
}

return
return problems
}

func (c LabelCheck) checkRecordingRule(rule parser.Rule) (problems []Problem) {
Expand All @@ -58,7 +58,7 @@ func (c LabelCheck) checkRecordingRule(rule parser.Rule) (problems []Problem) {
Severity: c.severity,
})
}
return
return problems
}

val := rule.RecordingRule.Labels.GetValue(c.key)
Expand All @@ -72,12 +72,12 @@ func (c LabelCheck) checkRecordingRule(rule parser.Rule) (problems []Problem) {
Severity: c.severity,
})
}
return
return problems
}

problems = append(problems, c.checkValue(rule, val)...)

return
return problems
}

func (c LabelCheck) checkAlertingRule(rule parser.Rule) (problems []Problem) {
Expand All @@ -91,7 +91,7 @@ func (c LabelCheck) checkAlertingRule(rule parser.Rule) (problems []Problem) {
Severity: c.severity,
})
}
return
return problems
}

val := rule.AlertingRule.Labels.GetValue(c.key)
Expand All @@ -105,12 +105,12 @@ func (c LabelCheck) checkAlertingRule(rule parser.Rule) (problems []Problem) {
Severity: c.severity,
})
}
return
return problems
}

problems = append(problems, c.checkValue(rule, val)...)

return
return problems
}

func (c LabelCheck) checkValue(rule parser.Rule, val *parser.YamlNode) (problems []Problem) {
Expand All @@ -123,5 +123,5 @@ func (c LabelCheck) checkValue(rule parser.Rule, val *parser.YamlNode) (problems
Severity: c.severity,
})
}
return
return problems
}
2 changes: 1 addition & 1 deletion internal/checks/rule_link.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,5 +126,5 @@ func (c RuleLinkCheck) Check(ctx context.Context, path string, rule parser.Rule,
log.Debug().Str("uri", uri).Str("status", resp.Status).Msg("Link request returned a valid status code")
}

return
return problems
}
4 changes: 2 additions & 2 deletions internal/checks/rule_reject.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (c Reject) Check(ctx context.Context, path string, rule parser.Rule, entrie
problems = append(problems, c.reject(rule, ann, "annotation")...)
}
}
return
return problems
}

func (c Reject) reject(rule parser.Rule, label *parser.YamlKeyValue, kind string) (problems []Problem) {
Expand All @@ -82,5 +82,5 @@ func (c Reject) reject(rule parser.Rule, label *parser.YamlKeyValue, kind string
Severity: c.severity,
})
}
return
return problems
}
2 changes: 1 addition & 1 deletion internal/checks/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func newTemplateContext(rule parser.Rule) (c TemplateContext) {
}
}
}
return
return c
}

type TemplateContext struct {
Expand Down
4 changes: 2 additions & 2 deletions internal/config/match.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,15 +249,15 @@ func parseDurationMatch(expr string) (dm durationMatch, err error) {
parts := strings.SplitN(expr, opSeparator, 2)
if len(parts) == 2 {
if dm.op, err = parseMatchOperation(parts[0]); err != nil {
return
return dm, err
}
dm.dur, err = parseDuration(parts[1])
} else {
dm.op = opEqual
dm.dur, err = parseDuration(expr)
}

return
return dm, err
}

type durationMatch struct {
Expand Down
2 changes: 1 addition & 1 deletion internal/config/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ func (p Parser) CompileRelaxed() (r []*regexp.Regexp) {
for _, pattern := range p.Relaxed {
r = append(r, regexp.MustCompile("^"+pattern+"$"))
}
return
return r
}
Loading

0 comments on commit dfb54d8

Please sign in to comment.