Skip to content

Commit

Permalink
Merge pull request #685 from reviewdog/progo-gen-go
Browse files Browse the repository at this point in the history
Use protojson to unmarshal rdjsonl
  • Loading branch information
haya14busa committed Jul 22, 2020
2 parents ff11c86 + 5f33dc6 commit fa9fd4c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
2 changes: 2 additions & 0 deletions _testdata/custom_rdjsonl.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
{"message":"multiline test 2 (same line)","location":{"path":"_testdata/custom.txt","range":{"start":{"line":5}, "end":{"line":5}}}}
{"message":"multiline test 3 (with line-break)","location":{"path":"_testdata/custom.txt","range":{"start":{"line":6,"column":2}, "end":{"line":7,"column":1}}}}
{"message":"multiline test 4 (with line-break)","location":{"path":"_testdata/custom.txt","range":{"start":{"line":6,"column":2}, "end":{"line":9,"column":1}}}}
{"message":"severity test 1","location":{"path":"_testdata/custom.txt","range":{"start":{"line":5, "column": 5}}}, "severity": "INFO"}
{"message":"severity test 2","location":{"path":"_testdata/custom.txt","range":{"start":{"line":5, "column": 4}}}, "severity": 2}
4 changes: 2 additions & 2 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package reviewdog

import (
"bufio"
"encoding/json"
"encoding/xml"
"errors"
"fmt"
Expand All @@ -11,6 +10,7 @@ import (
"github.com/reviewdog/errorformat"
"github.com/reviewdog/errorformat/fmts"
"github.com/reviewdog/reviewdog/proto/rdf"
"google.golang.org/protobuf/encoding/protojson"
)

// ParserOpt represents option to create Parser. Either FormatName or
Expand Down Expand Up @@ -177,7 +177,7 @@ func (p *RDJSONLParser) Parse(r io.Reader) ([]*CheckResult, error) {
s := bufio.NewScanner(r)
for s.Scan() {
d := new(rdf.Diagnostic)
if err := json.Unmarshal(s.Bytes(), d); err != nil {
if err := protojson.Unmarshal(s.Bytes(), d); err != nil {
return nil, err
}
results = append(results, &CheckResult{Diagnostic: d, Lines: []string{s.Text()}})
Expand Down
4 changes: 3 additions & 1 deletion parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ func TestRDJSONLParser(t *testing.T) {
{"source":{"name":"deadcode"},"message":"'unused2' is unused","location":{"path":"testdata/main.go","range":{"start":{"line":24,"column":6}}}}
{"source":{"name":"errcheck"},"message":"Error return value of 'os.Open' is not checked","location":{"path":"testdata/main.go","range":{"start":{"line":15,"column":9}}}}
{"source":{"name":"ineffassign"},"message":"ineffectual assignment to 'x'","location":{"path":"testdata/main.go","range":{"start":{"line":12,"column":2}}}}
{"source":{"name":"govet"},"message":"printf: Sprintf format %d reads arg #1, but call has 0 args","location":{"path":"testdata/main.go","range":{"start":{"line":13,"column":2}}}}`
{"source":{"name":"govet"},"message":"printf: Sprintf format %d reads arg #1, but call has 0 args","location":{"path":"testdata/main.go","range":{"start":{"line":13,"column":2}}}}
{"source":{"name":"severity-test"},"message":"severity test (string)","location":{"path":"testdata/main.go","range":{"start":{"line":24,"column":6}}}, "severity": "WARNING"}
{"source":{"name":"severity-test"},"message":"severity test (number)","location":{"path":"testdata/main.go","range":{"start":{"line":24,"column":6}}}, "severity": "WARNING"}`
sampleLines := strings.Split(sample, "\n")
p := NewRDJSONLParser()
crs, err := p.Parse(strings.NewReader(sample))
Expand Down

0 comments on commit fa9fd4c

Please sign in to comment.