Skip to content

Commit

Permalink
Merge branch 'master' into feature/use-errors-new
Browse files Browse the repository at this point in the history
  • Loading branch information
chavacava authored Nov 20, 2024
2 parents 182296f + 303ae4a commit 8692e83
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
1 change: 0 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ var allRules = append([]lint.Rule{
&rule.CommentsDensityRule{},
&rule.FileLengthLimitRule{},
&rule.FilenameFormatRule{},
&rule.UseErrorsNewRule{},
&rule.RedundantBuildTagRule{},
&rule.UseErrorsNewRule{},
}, defaultRules...)
Expand Down
12 changes: 5 additions & 7 deletions rule/redundant_build_tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,26 @@ type RedundantBuildTagRule struct{}
// `//go:build` comments are automatically added by gofmt when Go 1.17+ is used.
// See https://pkg.go.dev/cmd/go#hdr-Build_constraints
func (*RedundantBuildTagRule) Apply(file *lint.File, arguments lint.Arguments) []lint.Failure {
var failures []lint.Failure

for _, group := range file.AST.Comments {
hasGoBuild := false
for _, comment := range group.List {
if strings.HasPrefix(comment.Text, "//go:build ") {
hasGoBuild = true
continue
}
if hasGoBuild && strings.HasPrefix(comment.Text, "// +build ") {
failures = append(failures, lint.Failure{

if hasGoBuild && strings.HasPrefix(comment.Text, "// +build ") {
return []lint.Failure{{
Category: "style",
Confidence: 1,
Node: comment,
Failure: `The build tag "// +build" is redundant since Go 1.17 and can be removed`,
})
return failures
}}
}
}
}

return failures
return []lint.Failure{}
}

// Name returns the rule name.
Expand Down

0 comments on commit 8692e83

Please sign in to comment.