Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/golinters/dupl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
},
Expand Down
3 changes: 2 additions & 1 deletion pkg/golinters/gas.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 12 additions & 2 deletions pkg/printers/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
13 changes: 10 additions & 3 deletions pkg/result/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -24,12 +24,19 @@ 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(),
To: i.Line(),
}
}

return i.LineRange
return *i.LineRange
}