Skip to content

Commit 8e4b0c3

Browse files
authored
goheader: skip issues with invalid positions (#5286)
1 parent bb896aa commit 8e4b0c3

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

pkg/golinters/goheader/goheader.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,18 @@ func runGoHeader(pass *analysis.Pass, conf *goheader.Configuration) error {
8181
// Inspired by https://github.com/denis-tingaikin/go-header/blob/4c75a6a2332f025705325d6c71fff4616aedf48f/analyzer.go#L85-L92
8282
if len(file.Comments) > 0 && file.Comments[0].Pos() < file.Package {
8383
if !strings.HasPrefix(file.Comments[0].List[0].Text, "/*") {
84-
// When the comment are "//" there is a one character offset.
84+
// When the comment is "//" there is a one character offset.
8585
offset = 1
8686
}
8787
commentLine = goanalysis.GetFilePositionFor(pass.Fset, file.Comments[0].Pos()).Line
8888
}
8989

90+
// Skip issues related to build directives.
91+
// https://github.com/denis-tingaikin/go-header/issues/18
92+
if issue.Location().Position-offset < 0 {
93+
continue
94+
}
95+
9096
diag := analysis.Diagnostic{
9197
Pos: f.LineStart(issue.Location().Line+1) + token.Pos(issue.Location().Position-offset), // The position of the first divergence.
9298
Message: issue.Message(),

0 commit comments

Comments
 (0)