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(),
|
Filename: i.From.Filename(),
|
||||||
Line: i.From.LineStart(),
|
Line: i.From.LineStart(),
|
||||||
},
|
},
|
||||||
LineRange: result.Range{
|
LineRange: &result.Range{
|
||||||
From: i.From.LineStart(),
|
From: i.From.LineStart(),
|
||||||
To: i.From.LineEnd(),
|
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))
|
res := make([]result.Issue, 0, len(issues))
|
||||||
for _, i := range issues {
|
for _, i := range issues {
|
||||||
text := fmt.Sprintf("%s: %s", i.RuleID, i.What) // TODO: use severity and confidence
|
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)
|
line, err := strconv.Atoi(i.Line)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
r = &result.Range{}
|
||||||
if n, rerr := fmt.Sscanf(i.Line, "%d-%d", &r.From, &r.To); rerr != nil || n != 2 {
|
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)
|
logutils.HiddenWarnf("Can't convert gas line number %q of %v to int: %s", i.Line, i, err)
|
||||||
continue
|
continue
|
||||||
|
@ -14,15 +14,25 @@ func NewJSON() *JSON {
|
|||||||
return &JSON{}
|
return &JSON{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type JSONResult struct {
|
||||||
|
Issues []result.Issue
|
||||||
|
}
|
||||||
|
|
||||||
func (JSON) Print(ctx context.Context, issues <-chan result.Issue) (bool, error) {
|
func (JSON) Print(ctx context.Context, issues <-chan result.Issue) (bool, error) {
|
||||||
var allIssues []result.Issue
|
allIssues := []result.Issue{}
|
||||||
for i := range issues {
|
for i := range issues {
|
||||||
allIssues = append(allIssues, i)
|
allIssues = append(allIssues, i)
|
||||||
}
|
}
|
||||||
outputJSON, err := json.Marshal(allIssues)
|
|
||||||
|
res := JSONResult{
|
||||||
|
Issues: allIssues,
|
||||||
|
}
|
||||||
|
|
||||||
|
outputJSON, err := json.Marshal(res)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Fprint(StdOut, string(outputJSON))
|
fmt.Fprint(StdOut, string(outputJSON))
|
||||||
return len(allIssues) != 0, nil
|
return len(allIssues) != 0, nil
|
||||||
}
|
}
|
||||||
|
@ -11,8 +11,8 @@ type Issue struct {
|
|||||||
Text string
|
Text string
|
||||||
|
|
||||||
Pos token.Position
|
Pos token.Position
|
||||||
LineRange Range
|
LineRange *Range `json:",omitempty"`
|
||||||
HunkPos int
|
HunkPos int `json:",omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i Issue) FilePath() string {
|
func (i Issue) FilePath() string {
|
||||||
@ -24,6 +24,13 @@ func (i Issue) Line() int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (i Issue) GetLineRange() Range {
|
func (i Issue) GetLineRange() Range {
|
||||||
|
if i.LineRange == nil {
|
||||||
|
return Range{
|
||||||
|
From: i.Line(),
|
||||||
|
To: i.Line(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if i.LineRange.From == 0 {
|
if i.LineRange.From == 0 {
|
||||||
return Range{
|
return Range{
|
||||||
From: i.Line(),
|
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