File tree Expand file tree Collapse file tree 2 files changed +13
-3
lines changed Expand file tree Collapse file tree 2 files changed +13
-3
lines changed Original file line number Diff line number Diff line change @@ -92,10 +92,18 @@ func checkPeriod(c comment) *Issue {
92
92
strings .Split (c .text , "\n " )[pos .line - 1 ],
93
93
)
94
94
95
+ // Get the offset of the first symbol in the last line of the comment.
96
+ // This value is used only in golangci-lint to point to the problem, and
97
+ // to replace the problem when running in auto-fix mode.
98
+ offset := c .start .Offset
99
+ for i := 0 ; i < pos .line - 1 ; i ++ {
100
+ offset += len (c .lines [i ]) + 1
101
+ }
102
+
95
103
iss := Issue {
96
104
Pos : token.Position {
97
105
Filename : c .start .Filename ,
98
- Offset : c . start . Offset ,
106
+ Offset : offset ,
99
107
Line : pos .line + c .start .Line - 1 ,
100
108
Column : pos .column ,
101
109
},
Original file line number Diff line number Diff line change @@ -63,6 +63,7 @@ func TestCheckPeriod(t *testing.T) {
63
63
issue : & Issue {
64
64
Pos : token.Position {
65
65
Filename : start .Filename ,
66
+ Offset : 0 ,
66
67
Line : 1 ,
67
68
Column : 16 ,
68
69
},
@@ -80,6 +81,7 @@ func TestCheckPeriod(t *testing.T) {
80
81
issue : & Issue {
81
82
Pos : token.Position {
82
83
Filename : start .Filename ,
84
+ Offset : 10 ,
83
85
Line : 3 ,
84
86
Column : 6 ,
85
87
},
@@ -244,8 +246,8 @@ func TestCheckPeriod(t *testing.T) {
244
246
case tt .issue != nil && issue == nil :
245
247
t .Fatalf ("Expected issue, got nil" )
246
248
case issue .Pos != tt .issue .Pos :
247
- t .Fatalf ("Wrong position\n expected: %+v\n got: %+v" ,
248
- tt .issue .Pos , issue .Pos )
249
+ t .Fatalf ("Wrong position\n expected: %+v [%d] \n got: %+v [%d] " ,
250
+ tt .issue .Pos , tt . issue .Pos . Offset , issue . Pos , issue . Pos . Offset )
249
251
case issue .Message != tt .issue .Message :
250
252
t .Fatalf ("Wrong message\n expected: %s\n got: %s" ,
251
253
tt .issue .Message , issue .Message )
You can’t perform that action at this time.
0 commit comments