Skip to content

Commit

Permalink
feat: multiline code snippet
Browse files Browse the repository at this point in the history
  • Loading branch information
0xtekgrinder committed Oct 30, 2024
1 parent 535f5b5 commit 24bd678
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions formatter/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions formatter/cyclomatic_complexity.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
4 changes: 2 additions & 2 deletions formatter/general.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
2 changes: 1 addition & 1 deletion formatter/missing_mod_package.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
`
}
Expand Down
6 changes: 3 additions & 3 deletions formatter/slice_bound.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 -}}
`
}

Expand Down

0 comments on commit 24bd678

Please sign in to comment.