@@ -80,6 +80,10 @@ func checkCommentForPeriod(c comment) *Issue {
80
80
// attached lines. Use `iss.Pos.Column` because it's a position in
81
81
// the original line.
82
82
original := c .lines [pos .line - 1 ]
83
+ if len (original ) < iss .Pos .Column - 1 {
84
+ // This should never happen. Avoid panics, skip this check.
85
+ return nil
86
+ }
83
87
iss .Replacement = original [:iss .Pos .Column - 1 ] + "." +
84
88
original [iss .Pos .Column - 1 :]
85
89
@@ -117,14 +121,18 @@ func checkCommentForCapital(c comment) []Issue {
117
121
Message : noCapitalMessage ,
118
122
}
119
123
120
- // Make a replacement. Use `pos.line ` to get an original line from
124
+ // Make a replacement. Use `pos.original ` to get an original original from
121
125
// attached lines. Use `iss.Pos.Column` because it's a position in
122
- // the original line.
123
- line := c .lines [pos .line - 1 ]
124
- col := byteToRuneColumn (line , iss .Pos .Column ) - 1
125
- rep := string (unicode .ToTitle ([]rune (line )[col ])) // capital letter
126
- iss .Replacement = line [:iss .Pos .Column - 1 ] + rep +
127
- line [iss .Pos .Column - 1 + len (rep ):]
126
+ // the original original.
127
+ original := c .lines [pos .line - 1 ]
128
+ col := byteToRuneColumn (original , iss .Pos .Column ) - 1
129
+ rep := string (unicode .ToTitle ([]rune (original )[col ])) // capital letter
130
+ if len (original ) < iss .Pos .Column - 1 + len (rep ) {
131
+ // This should never happen. Avoid panics, skip this check.
132
+ continue
133
+ }
134
+ iss .Replacement = original [:iss .Pos .Column - 1 ] + rep +
135
+ original [iss .Pos .Column - 1 + len (rep ):]
128
136
129
137
// Save replacement to raw lines to be able to combine it with
130
138
// further replacements
0 commit comments