Skip to content

Commit 03b6d1a

Browse files
committed
chore: use first divergence as a display position
1 parent ee07579 commit 03b6d1a

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

pkg/golinters/goheader/goheader.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -76,17 +76,8 @@ func runGoHeader(pass *analysis.Pass, conf *goheader.Configuration) error {
7676

7777
f := pass.Fset.File(file.Pos())
7878

79-
commentLine := 1
80-
81-
// Inspired by https://github.com/denis-tingaikin/go-header/blob/4c75a6a2332f025705325d6c71fff4616aedf48f/analyzer.go#L85-L92
82-
if len(file.Comments) > 0 && file.Comments[0].Pos() < file.Package {
83-
commentLine = goanalysis.GetFilePositionFor(pass.Fset, file.Comments[0].Pos()).Line
84-
}
85-
86-
start := f.LineStart(commentLine)
87-
8879
diag := analysis.Diagnostic{
89-
Pos: start,
80+
Pos: f.LineStart(issue.Location().Line+1) + token.Pos(issue.Location().Position), // The position of the first divergence.
9081
Message: issue.Message(),
9182
}
9283

@@ -96,6 +87,15 @@ func runGoHeader(pass *analysis.Pass, conf *goheader.Configuration) error {
9687
current += len(s)
9788
}
9889

90+
commentLine := 1
91+
92+
// Inspired by https://github.com/denis-tingaikin/go-header/blob/4c75a6a2332f025705325d6c71fff4616aedf48f/analyzer.go#L85-L92
93+
if len(file.Comments) > 0 && file.Comments[0].Pos() < file.Package {
94+
commentLine = goanalysis.GetFilePositionFor(pass.Fset, file.Comments[0].Pos()).Line
95+
}
96+
97+
start := f.LineStart(commentLine)
98+
9999
end := start + token.Pos(current)
100100

101101
header := strings.Join(fix.Expected, "\n") + "\n"

0 commit comments

Comments
 (0)