Write JSON output more compactly and output object, not array
This commit is contained in:
parent
2a8eec1f70
commit
541656cc20
@ -41,7 +41,7 @@ func (d Dupl) Run(ctx context.Context, lintCtx *linter.Context) ([]result.Issue,
|
||||
Filename: i.From.Filename(),
|
||||
Line: i.From.LineStart(),
|
||||
},
|
||||
LineRange: result.Range{
|
||||
LineRange: &result.Range{
|
||||
From: i.From.LineStart(),
|
||||
To: i.From.LineEnd(),
|
||||
},
|
||||
|
@ -41,9 +41,10 @@ func (lint Gas) Run(ctx context.Context, lintCtx *linter.Context) ([]result.Issu
|
||||
res := make([]result.Issue, 0, len(issues))
|
||||
for _, i := range issues {
|
||||
text := fmt.Sprintf("%s: %s", i.RuleID, i.What) // TODO: use severity and confidence
|
||||
var r result.Range
|
||||
var r *result.Range
|
||||
line, err := strconv.Atoi(i.Line)
|
||||
if err != nil {
|
||||
r = &result.Range{}
|
||||
if n, rerr := fmt.Sscanf(i.Line, "%d-%d", &r.From, &r.To); rerr != nil || n != 2 {
|
||||
logutils.HiddenWarnf("Can't convert gas line number %q of %v to int: %s", i.Line, i, err)
|
||||
continue
|
||||
|
@ -14,15 +14,25 @@ func NewJSON() *JSON {
|
||||
return &JSON{}
|
||||
}
|
||||
|
||||
type JSONResult struct {
|
||||
Issues []result.Issue
|
||||
}
|
||||
|
||||
func (JSON) Print(ctx context.Context, issues <-chan result.Issue) (bool, error) {
|
||||
var allIssues []result.Issue
|
||||
allIssues := []result.Issue{}
|
||||
for i := range issues {
|
||||
allIssues = append(allIssues, i)
|
||||
}
|
||||
outputJSON, err := json.Marshal(allIssues)
|
||||
|
||||
res := JSONResult{
|
||||
Issues: allIssues,
|
||||
}
|
||||
|
||||
outputJSON, err := json.Marshal(res)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
fmt.Fprint(StdOut, string(outputJSON))
|
||||
return len(allIssues) != 0, nil
|
||||
}
|
||||
|
@ -11,8 +11,8 @@ type Issue struct {
|
||||
Text string
|
||||
|
||||
Pos token.Position
|
||||
LineRange Range
|
||||
HunkPos int
|
||||
LineRange *Range `json:",omitempty"`
|
||||
HunkPos int `json:",omitempty"`
|
||||
}
|
||||
|
||||
func (i Issue) FilePath() string {
|
||||
@ -24,6 +24,13 @@ func (i Issue) Line() int {
|
||||
}
|
||||
|
||||
func (i Issue) GetLineRange() Range {
|
||||
if i.LineRange == nil {
|
||||
return Range{
|
||||
From: i.Line(),
|
||||
To: i.Line(),
|
||||
}
|
||||
}
|
||||
|
||||
if i.LineRange.From == 0 {
|
||||
return Range{
|
||||
From: i.Line(),
|
||||
@ -31,5 +38,5 @@ func (i Issue) GetLineRange() Range {
|
||||
}
|
||||
}
|
||||
|
||||
return i.LineRange
|
||||
return *i.LineRange
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user