File tree Expand file tree Collapse file tree 1 file changed +13
-8
lines changed Expand file tree Collapse file tree 1 file changed +13
-8
lines changed Original file line number Diff line number Diff line change @@ -76,8 +76,20 @@ func runGoHeader(pass *analysis.Pass, conf *goheader.Configuration) error {
76
76
77
77
f := pass .Fset .File (file .Pos ())
78
78
79
+ commentLine := 1
80
+ var offset int
81
+
82
+ // Inspired by https://github.com/denis-tingaikin/go-header/blob/4c75a6a2332f025705325d6c71fff4616aedf48f/analyzer.go#L85-L92
83
+ if len (file .Comments ) > 0 && file .Comments [0 ].Pos () < file .Package {
84
+ if ! strings .HasPrefix (file .Comments [0 ].List [0 ].Text , "/*" ) {
85
+ // When the comment are "//" there is a one character offset.
86
+ offset = 1
87
+ }
88
+ commentLine = goanalysis .GetFilePositionFor (pass .Fset , file .Comments [0 ].Pos ()).Line
89
+ }
90
+
79
91
diag := analysis.Diagnostic {
80
- Pos : f .LineStart (issue .Location ().Line + 1 ) + token .Pos (issue .Location ().Position ), // The position of the first divergence.
92
+ Pos : f .LineStart (issue .Location ().Line + 1 ) + token .Pos (issue .Location ().Position - offset ), // The position of the first divergence.
81
93
Message : issue .Message (),
82
94
}
83
95
@@ -87,13 +99,6 @@ func runGoHeader(pass *analysis.Pass, conf *goheader.Configuration) error {
87
99
current += len (s )
88
100
}
89
101
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
102
start := f .LineStart (commentLine )
98
103
99
104
end := start + token .Pos (current )
You can’t perform that action at this time.
0 commit comments