Skip to content

Commit

Permalink
goheader: skip issues with invalid positions (#5286)
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez authored Jan 2, 2025
1 parent bb896aa commit 8e4b0c3
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pkg/golinters/goheader/goheader.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,18 @@ func runGoHeader(pass *analysis.Pass, conf *goheader.Configuration) error {
// Inspired by https://github.com/denis-tingaikin/go-header/blob/4c75a6a2332f025705325d6c71fff4616aedf48f/analyzer.go#L85-L92
if len(file.Comments) > 0 && file.Comments[0].Pos() < file.Package {
if !strings.HasPrefix(file.Comments[0].List[0].Text, "/*") {
// When the comment are "//" there is a one character offset.
// When the comment is "//" there is a one character offset.
offset = 1
}
commentLine = goanalysis.GetFilePositionFor(pass.Fset, file.Comments[0].Pos()).Line
}

// Skip issues related to build directives.
// https://github.com/denis-tingaikin/go-header/issues/18
if issue.Location().Position-offset < 0 {
continue
}

diag := analysis.Diagnostic{
Pos: f.LineStart(issue.Location().Line+1) + token.Pos(issue.Location().Position-offset), // The position of the first divergence.
Message: issue.Message(),
Expand Down

0 comments on commit 8e4b0c3

Please sign in to comment.