From 24bd67837f685de462cb73067677e0b52ad4c824 Mon Sep 17 00:00:00 2001 From: 0xtekgrinder <0xtekgrinder@protonmail.com> Date: Wed, 30 Oct 2024 12:28:46 +0100 Subject: [PATCH] feat: multiline code snippet --- formatter/builder.go | 4 ++-- formatter/cyclomatic_complexity.go | 4 ++-- formatter/general.go | 4 ++-- formatter/missing_mod_package.go | 2 +- formatter/slice_bound.go | 6 +++--- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/formatter/builder.go b/formatter/builder.go index e69bfe9..62a38ee 100644 --- a/formatter/builder.go +++ b/formatter/builder.go @@ -156,7 +156,7 @@ func header(rule string, severity string, maxLineNumWidth int, filename string, padding := strings.Repeat(" ", maxLineNumWidth) endString += lineStyle.Sprintf("%s--> ", padding) - endString += fileStyle.Sprintf("%s:%d:%d", filename, startLine, startColumn) + endString += fileStyle.Sprintf("%s:%d:%d\n", filename, startLine, startColumn) return endString } @@ -174,7 +174,7 @@ func codeSnippet(snippetLines []string, startLine int, endLine int, maxLineNumWi line = strings.TrimPrefix(line, commonIndent) lineNum := fmt.Sprintf("%*d", maxLineNumWidth, i) - endString += lineStyle.Sprintf("%s | %s", lineNum, line) + endString += lineStyle.Sprintf("%s | %s\n", lineNum, line) } return endString diff --git a/formatter/cyclomatic_complexity.go b/formatter/cyclomatic_complexity.go index 6f58440..6d5bf12 100644 --- a/formatter/cyclomatic_complexity.go +++ b/formatter/cyclomatic_complexity.go @@ -8,8 +8,8 @@ import ( type CyclomaticComplexityFormatter struct{} func (f *CyclomaticComplexityFormatter) IssueTemplate() string { - return `{{header .Rule .Severity .MaxLineNumWidth .Filename .StartLine .StartColumn}} -{{snippet .SnippetLines .StartLine .EndLine .MaxLineNumWidth .CommonIndent .Padding}} + return `{{header .Rule .Severity .MaxLineNumWidth .Filename .StartLine .StartColumn -}} +{{snippet .SnippetLines .StartLine .EndLine .MaxLineNumWidth .CommonIndent .Padding -}} {{underlineAndMessage .Message .Padding .StartLine .EndLine .StartColumn .EndColumn .SnippetLines .CommonIndent}} {{complexityInfo .Padding .Message }} diff --git a/formatter/general.go b/formatter/general.go index 23c5b7c..3d5a549 100644 --- a/formatter/general.go +++ b/formatter/general.go @@ -3,8 +3,8 @@ package formatter type GeneralIssueFormatter struct{} func (f *GeneralIssueFormatter) IssueTemplate() string { - return `{{header .Rule .Severity .MaxLineNumWidth .Filename .StartLine .StartColumn}} -{{snippet .SnippetLines .StartLine .EndLine .MaxLineNumWidth .CommonIndent .Padding}} + return `{{header .Rule .Severity .MaxLineNumWidth .Filename .StartLine .StartColumn -}} +{{snippet .SnippetLines .StartLine .EndLine .MaxLineNumWidth .CommonIndent .Padding -}} {{underlineAndMessage .Message .Padding .StartLine .EndLine .StartColumn .EndColumn .SnippetLines .CommonIndent}} {{- if .Suggestion }} diff --git a/formatter/missing_mod_package.go b/formatter/missing_mod_package.go index 5bf8197..8221f35 100644 --- a/formatter/missing_mod_package.go +++ b/formatter/missing_mod_package.go @@ -3,7 +3,7 @@ package formatter type MissingModPackageFormatter struct{} func (f *MissingModPackageFormatter) IssueTemplate() string { - return `{{header .Rule .Severity .MaxLineNumWidth .Filename .StartLine .StartColumn}} + return `{{header .Rule .Severity .MaxLineNumWidth .Filename .StartLine .StartColumn -}} {{message .Message}} ` } diff --git a/formatter/slice_bound.go b/formatter/slice_bound.go index 76e8419..00d262e 100644 --- a/formatter/slice_bound.go +++ b/formatter/slice_bound.go @@ -3,10 +3,10 @@ package formatter type SliceBoundsCheckFormatter struct{} func (f *SliceBoundsCheckFormatter) IssueTemplate() string { - return `{{header .Rule .Severity .MaxLineNumWidth .Filename .StartLine .StartColumn}} -{{snippet .SnippetLines .StartLine .EndLine .MaxLineNumWidth .CommonIndent .Padding}} + return `{{header .Rule .Severity .MaxLineNumWidth .Filename .StartLine .StartColumn -}} +{{snippet .SnippetLines .StartLine .EndLine .MaxLineNumWidth .CommonIndent .Padding -}} {{underlineAndMessage .Message .Padding .StartLine .EndLine .StartColumn .EndColumn .SnippetLines .CommonIndent}} -{{warning .Category}} +{{warning .Category -}} ` }