From c88df8f47380711e63a012aa8f5b9536d27169bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=98=83=20Elliot=20Shepherd?= Date: Tue, 12 May 2020 05:10:39 +1000 Subject: [PATCH] Fix nil pointer in codeclimate.go (#1077) Some issues don't have any source lines --- pkg/printers/codeclimate.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pkg/printers/codeclimate.go b/pkg/printers/codeclimate.go index 26878056884f..5d45c4eb3019 100644 --- a/pkg/printers/codeclimate.go +++ b/pkg/printers/codeclimate.go @@ -39,9 +39,14 @@ func (p CodeClimate) Print(ctx context.Context, issues []result.Issue) error { issue.Location.Path = i.Pos.Filename issue.Location.Lines.Begin = i.Pos.Line - // Need a checksum of the issue, so we use MD5 of the filename, text, and first line of source + // Need a checksum of the issue, so we use MD5 of the filename, text, and first line of source if there is any + var firstLine string + if len(i.SourceLines) > 0 { + firstLine = i.SourceLines[0] + } + hash := md5.New() //nolint:gosec - _, _ = hash.Write([]byte(i.Pos.Filename + i.Text + i.SourceLines[0])) + _, _ = hash.Write([]byte(i.Pos.Filename + i.Text + firstLine)) issue.Fingerprint = fmt.Sprintf("%X", hash.Sum(nil)) allIssues = append(allIssues, issue)