Skip to content

Commit 303ae4a

Browse files
chavacavachavacava
andauthored
refactor: remove useless failure slice declaration (#1141)
Co-authored-by: chavacava <[email protected]>
1 parent 7f769f8 commit 303ae4a

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

rule/redundant_build_tag.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,26 @@ type RedundantBuildTagRule struct{}
1313
// `//go:build` comments are automatically added by gofmt when Go 1.17+ is used.
1414
// See https://pkg.go.dev/cmd/go#hdr-Build_constraints
1515
func (*RedundantBuildTagRule) Apply(file *lint.File, arguments lint.Arguments) []lint.Failure {
16-
var failures []lint.Failure
17-
1816
for _, group := range file.AST.Comments {
1917
hasGoBuild := false
2018
for _, comment := range group.List {
2119
if strings.HasPrefix(comment.Text, "//go:build ") {
2220
hasGoBuild = true
2321
continue
2422
}
23+
2524
if hasGoBuild && strings.HasPrefix(comment.Text, "// +build ") {
26-
failures = append(failures, lint.Failure{
25+
return []lint.Failure{{
2726
Category: "style",
2827
Confidence: 1,
2928
Node: comment,
3029
Failure: `The build tag "// +build" is redundant since Go 1.17 and can be removed`,
31-
})
32-
return failures
30+
}}
3331
}
3432
}
3533
}
3634

37-
return failures
35+
return []lint.Failure{}
3836
}
3937

4038
// Name returns the rule name.

0 commit comments

Comments
 (0)