Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change the type of error type from rune to string #108

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 15 additions & 15 deletions errorformat.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ type qffields struct {
useviscol bool
pattern string
enr int
etype byte
etype string
valid bool

lines []string
Expand All @@ -98,8 +98,8 @@ type Entry struct {
Pattern string `json:"pattern"`
// description of the error
Text string `json:"text"`
// type of the error, 'E', '1', etc.
Type rune `json:"type"`
// type of the error, "E", "1", etc.
Type string `json:"type"`
// true: recognized error message
Valid bool `json:"valid"`

Expand Down Expand Up @@ -138,18 +138,18 @@ func (e *Entry) String() string {
func (e *Entry) Types() string {
s := ""
switch e.Type {
case 'e', 'E':
case "e", "E", "✖":
s = "error"
case 0:
case "":
if e.Nr > 0 {
s = "error"
}
case 'w', 'W':
case "w", "W", "⚠":
s = "warning"
case 'i', 'I':
case "i", "I":
s = "info"
default:
s = string(e.Type)
s = e.Type
}
if e.Nr > 0 {
if s != "" {
Expand Down Expand Up @@ -190,7 +190,7 @@ func (s *Scanner) Scan() bool {
Text: fields.errmsg,
Vcol: fields.useviscol,
Valid: fields.valid,
Type: rune(fields.etype),
Type: fields.etype,
Lines: fields.lines,
}
if qfl.Filename == "" && s.qi.currfile != "" {
Expand Down Expand Up @@ -266,7 +266,7 @@ func (s *Scanner) parseLineInternal(line string, i int) (qfstatus, *qffields) {
}

if strchar("EWI", idx) {
fields.etype = idx
fields.etype = string(idx)
}

if r.F != "" { // %f
Expand All @@ -278,7 +278,7 @@ func (s *Scanner) parseLineInternal(line string, i int) (qfstatus, *qffields) {
fields.enr = r.N // %n
fields.lnum = r.L // %l
fields.col = r.C // %c
if r.T != 0 {
if r.T != "" {
fields.etype = r.T // %t
}
if efm.flagplus && !s.qi.multiscan { // %+
Expand Down Expand Up @@ -352,8 +352,8 @@ func (s *Scanner) parseLineInternal(line string, i int) (qfstatus, *qffields) {
if qfprev.Nr < 1 {
qfprev.Nr = fields.enr
}
if fields.etype != 0 && qfprev.Type == 0 {
qfprev.Type = rune(fields.etype)
if fields.etype != "" && qfprev.Type == "" {
qfprev.Type = fields.etype
}
if qfprev.Filename == "" {
qfprev.Filename = fields.namebuf
Expand Down Expand Up @@ -512,7 +512,7 @@ type Match struct {
N int // (%n) error number
L int // (%l) line number
C int // (%c) column number
T byte // (%t) error type
T string // (%t) error type
M string // (%m) error message
R string // (%r) the "rest" of a single-line file message
P string // (%p) pointer line
Expand Down Expand Up @@ -543,7 +543,7 @@ func (efm *Efm) Match(s string) *Match {
case "c":
match.C = mustAtoI(m)
case "t":
match.T = m[0]
match.T = m
case "m":
match.M = m
case "r":
Expand Down
12 changes: 6 additions & 6 deletions errorformat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,15 +267,15 @@ nexttext:

func TestEntry_Types(t *testing.T) {
tests := []struct {
t rune
t string
nr int
want string
}{
{t: 'e', want: "error"},
{t: 'E', want: "error"},
{t: 'e', nr: 14, want: "error 14"},
{t: 'w', nr: 14, want: "warning 14"},
{t: 'i', want: "info"},
{t: "e", want: "error"},
{t: "E", want: "error"},
{t: "e", nr: 14, want: "error 14"},
{t: "w", nr: 14, want: "warning 14"},
{t: "i", want: "info"},
{nr: 14, want: "error 14"},
}
for _, tt := range tests {
Expand Down
2 changes: 1 addition & 1 deletion fmts/css.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ func init() {
Name: "stylelint",
Errorformat: []string{
`%-P%f`,
`%*[\ ]%l:%c%*[\ ]%*[✖⚠]%*[\ ]%m`,
`%*[\ ]%l:%c%*[\ ]%t%*[\ ]%m`,
`%-Q`,
},
Description: "A mighty modern CSS linter",
Expand Down
22 changes: 11 additions & 11 deletions fmts/testdata/stylelint.ok
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
renderer/style.css|46 col 3| Unexpected longhand value '0px 5px 0 5px' instead of '0px 5px 0' shorthand-property-no-redundant-values
renderer/style.css|46 col 12| Unexpected unit length-zero-no-unit
renderer/style.css|116 col 3| Unexpected longhand value '0 5px 0 5px' instead of '0 5px' shorthand-property-no-redundant-values
renderer/style.css|145 col 16| Unexpected unit length-zero-no-unit
renderer/style.css|146 col 13| Unexpected unit length-zero-no-unit
renderer/style.css|151 col 17| Unexpected unit length-zero-no-unit
renderer/style.css|152 col 3| Unexpected longhand value '0px 16px 100px 16px' instead of '0px 16px 100px' shorthand-property-no-redundant-values
renderer/style.css|152 col 13| Unexpected unit length-zero-no-unit
renderer/style.css|166 col 18| Unexpected unit length-zero-no-unit
renderer/style.css|182 col 1| Expected empty line before non-nested rule rule-non-nested-empty-line-before
renderer/style.css|200 col 1| Expected empty line before non-nested rule rule-non-nested-empty-line-before
renderer/style.css|46 col 3 error| Unexpected longhand value '0px 5px 0 5px' instead of '0px 5px 0' shorthand-property-no-redundant-values
renderer/style.css|46 col 12 warning| Unexpected unit length-zero-no-unit
renderer/style.css|116 col 3 error| Unexpected longhand value '0 5px 0 5px' instead of '0 5px' shorthand-property-no-redundant-values
renderer/style.css|145 col 16 warning| Unexpected unit length-zero-no-unit
renderer/style.css|146 col 13 warning| Unexpected unit length-zero-no-unit
renderer/style.css|151 col 17 warning| Unexpected unit length-zero-no-unit
renderer/style.css|152 col 3 error| Unexpected longhand value '0px 16px 100px 16px' instead of '0px 16px 100px' shorthand-property-no-redundant-values
renderer/style.css|152 col 13 warning| Unexpected unit length-zero-no-unit
renderer/style.css|166 col 18 warning| Unexpected unit length-zero-no-unit
renderer/style.css|182 col 1 error| Expected empty line before non-nested rule rule-non-nested-empty-line-before
renderer/style.css|200 col 1 error| Expected empty line before non-nested rule rule-non-nested-empty-line-before
4 changes: 2 additions & 2 deletions writer/checkstyle.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ func (c *CheckStyle) Write(e *errorformat.Entry) error {
Message: e.Text,
Severity: e.Types(),
}
if e.Nr != 0 && e.Type != 0 {
checkerr.Source = fmt.Sprintf("%s%d", string(e.Type), e.Nr)
if e.Nr != 0 && e.Type != "" {
checkerr.Source = fmt.Sprintf("%s%d", e.Type, e.Nr)
}
c.files[e.Filename].Errors = append(c.files[e.Filename].Errors, checkerr)
return nil
Expand Down
8 changes: 4 additions & 4 deletions writer/jsonl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ func ExampleJSONL() {
w.Write(e)
}
// Output:
// {"filename":"path/to/file1","lnum":1,"col":14,"vcol":false,"nr":0,"pattern":"","text":"hello","type":87,"valid":false,"lines":["path/to/file1:1:14:[W] hello"]}
// {"filename":"path/to/file1","lnum":2,"col":14,"vcol":false,"nr":0,"pattern":"","text":"vim","type":73,"valid":false,"lines":["path/to/file1:2:14:[I] vim"]}
// {"filename":"file2","lnum":2,"col":14,"vcol":false,"nr":1,"pattern":"","text":"emacs","type":69,"valid":false,"lines":["file2:2:14:[E] emacs"]}
// {"filename":"file2","lnum":14,"col":1,"vcol":false,"nr":14,"pattern":"","text":"neovim","type":69,"valid":false,"lines":["file2:14:1:[E] neovim"]}
// {"filename":"path/to/file1","lnum":1,"col":14,"vcol":false,"nr":0,"pattern":"","text":"hello","type":"W","valid":false,"lines":["path/to/file1:1:14:[W] hello"]}
// {"filename":"path/to/file1","lnum":2,"col":14,"vcol":false,"nr":0,"pattern":"","text":"vim","type":"I","valid":false,"lines":["path/to/file1:2:14:[I] vim"]}
// {"filename":"file2","lnum":2,"col":14,"vcol":false,"nr":1,"pattern":"","text":"emacs","type":"E","valid":false,"lines":["file2:2:14:[E] emacs"]}
// {"filename":"file2","lnum":14,"col":1,"vcol":false,"nr":14,"pattern":"","text":"neovim","type":"E","valid":false,"lines":["file2:14:1:[E] neovim"]}
}
6 changes: 3 additions & 3 deletions writer/sarif.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ func (s *Sarif) Write(e *errorformat.Entry) error {

// Set Level
switch e.Type {
case 'e', 'E':
case "e", "E", "✖":
result.Level = sarif.Error.Ptr()
case 'w', 'W':
case "w", "W", "⚠":
result.Level = sarif.Warning.Ptr()
case 'n', 'N', 'i', 'I': // Handle info as note.
case "n", "N", "i", "I": // Handle info as note.
result.Level = sarif.Note.Ptr()
}

Expand Down
10 changes: 5 additions & 5 deletions writer/writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import (
)

var testErrs = []*errorformat.Entry{
{Filename: "path/to/file1", Lnum: 1, Col: 14, Text: "hello", Type: 'W'},
{Filename: "path/to/file1", Lnum: 2, Col: 14, Text: "vim", Type: 'I'},
{Filename: "file2", Lnum: 2, Col: 14, Text: "emacs", Type: 'E', Nr: 1},
{Filename: "file2", Lnum: 14, Col: 1, Text: "neovim", Type: 'E', Nr: 14},
{Filename: "path/to/file1", Lnum: 1, Col: 14, Text: "hello", Type: "W"},
{Filename: "path/to/file1", Lnum: 2, Col: 14, Text: "vim", Type: "I"},
{Filename: "file2", Lnum: 2, Col: 14, Text: "emacs", Type: "E", Nr: 1},
{Filename: "file2", Lnum: 14, Col: 1, Text: "neovim", Type: "E", Nr: 14},
}

func init() {
for _, e := range testErrs {
e.Lines = append(e.Lines, fmt.Sprintf("%s:%d:%d:[%s] %s",
e.Filename, e.Lnum, e.Col, string(e.Type), e.Text))
e.Filename, e.Lnum, e.Col, e.Type, e.Text))
}
}