Skip to content

Commit c88df8f

Browse files
author
☃ Elliot Shepherd
authored
Fix nil pointer in codeclimate.go (#1077)
Some issues don't have any source lines
1 parent 206d79f commit c88df8f

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

pkg/printers/codeclimate.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,14 @@ func (p CodeClimate) Print(ctx context.Context, issues []result.Issue) error {
3939
issue.Location.Path = i.Pos.Filename
4040
issue.Location.Lines.Begin = i.Pos.Line
4141

42-
// Need a checksum of the issue, so we use MD5 of the filename, text, and first line of source
42+
// Need a checksum of the issue, so we use MD5 of the filename, text, and first line of source if there is any
43+
var firstLine string
44+
if len(i.SourceLines) > 0 {
45+
firstLine = i.SourceLines[0]
46+
}
47+
4348
hash := md5.New() //nolint:gosec
44-
_, _ = hash.Write([]byte(i.Pos.Filename + i.Text + i.SourceLines[0]))
49+
_, _ = hash.Write([]byte(i.Pos.Filename + i.Text + firstLine))
4550
issue.Fingerprint = fmt.Sprintf("%X", hash.Sum(nil))
4651

4752
allIssues = append(allIssues, issue)

0 commit comments

Comments
 (0)