
* add ability to set issue severity for out formats that support it based on severity rules * fix lint issues * change log child name * code climate omit severity if empty * add tests for severity rules, add support for case sensitive rules, fix lint issues, better doc comments, share processor test * deduplicated rule logic into a base rule that can be used by multiple rule types, moved severity config to it's own parent key named severity, reduced size of NewRunner function to make it easier to read * put validate function under base rule struct * better validation error wording * add Fingerprint and Description methods to Issue struct, made codeclimate reporter easier to read, checkstyle output is now pretty printed
58 lines
1.5 KiB
Go
58 lines
1.5 KiB
Go
package printers
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
|
|
"github.com/golangci/golangci-lint/pkg/logutils"
|
|
"github.com/golangci/golangci-lint/pkg/result"
|
|
)
|
|
|
|
// CodeClimateIssue is a subset of the Code Climate spec - https://github.com/codeclimate/spec/blob/master/SPEC.md#data-types
|
|
// It is just enough to support GitLab CI Code Quality - https://docs.gitlab.com/ee/user/project/merge_requests/code_quality.html
|
|
type CodeClimateIssue struct {
|
|
Description string `json:"description"`
|
|
Severity string `json:"severity,omitempty"`
|
|
Fingerprint string `json:"fingerprint"`
|
|
Location struct {
|
|
Path string `json:"path"`
|
|
Lines struct {
|
|
Begin int `json:"begin"`
|
|
} `json:"lines"`
|
|
} `json:"location"`
|
|
}
|
|
|
|
type CodeClimate struct {
|
|
}
|
|
|
|
func NewCodeClimate() *CodeClimate {
|
|
return &CodeClimate{}
|
|
}
|
|
|
|
func (p CodeClimate) Print(ctx context.Context, issues []result.Issue) error {
|
|
codeClimateIssues := []CodeClimateIssue{}
|
|
for i := range issues {
|
|
issue := &issues[i]
|
|
codeClimateIssue := CodeClimateIssue{}
|
|
codeClimateIssue.Description = issue.Description()
|
|
codeClimateIssue.Location.Path = issue.Pos.Filename
|
|
codeClimateIssue.Location.Lines.Begin = issue.Pos.Line
|
|
codeClimateIssue.Fingerprint = issue.Fingerprint()
|
|
|
|
if issue.Severity != "" {
|
|
codeClimateIssue.Severity = issue.Severity
|
|
}
|
|
|
|
codeClimateIssues = append(codeClimateIssues, codeClimateIssue)
|
|
}
|
|
|
|
outputJSON, err := json.Marshal(codeClimateIssues)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
fmt.Fprint(logutils.StdOut, string(outputJSON))
|
|
return nil
|
|
}
|