From 941d4970ea95b4c6d305321011280153e1117693 Mon Sep 17 00:00:00 2001 From: Kensuke Kubo Date: Wed, 6 Oct 2021 23:04:14 +0900 Subject: [PATCH] fix: stylelint --- errorformat.go | 30 +++++++++++++++--------------- errorformat_test.go | 12 ++++++------ fmts/css.go | 2 +- fmts/testdata/stylelint.ok | 22 +++++++++++----------- writer/checkstyle.go | 4 ++-- writer/jsonl_test.go | 8 ++++---- writer/sarif.go | 6 +++--- writer/writer_test.go | 10 +++++----- 8 files changed, 47 insertions(+), 47 deletions(-) diff --git a/errorformat.go b/errorformat.go index bfdda67..984b3be 100644 --- a/errorformat.go +++ b/errorformat.go @@ -74,7 +74,7 @@ type qffields struct { useviscol bool pattern string enr int - etype byte + etype string valid bool lines []string @@ -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"` @@ -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 != "" { @@ -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 != "" { @@ -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 @@ -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 { // %+ @@ -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 @@ -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 @@ -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": diff --git a/errorformat_test.go b/errorformat_test.go index 12603d2..c43eaac 100644 --- a/errorformat_test.go +++ b/errorformat_test.go @@ -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 { diff --git a/fmts/css.go b/fmts/css.go index 6f7f62f..a2e2b30 100644 --- a/fmts/css.go +++ b/fmts/css.go @@ -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", diff --git a/fmts/testdata/stylelint.ok b/fmts/testdata/stylelint.ok index 3a3e339..617250d 100644 --- a/fmts/testdata/stylelint.ok +++ b/fmts/testdata/stylelint.ok @@ -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 diff --git a/writer/checkstyle.go b/writer/checkstyle.go index d5e6012..16a4e17 100644 --- a/writer/checkstyle.go +++ b/writer/checkstyle.go @@ -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 diff --git a/writer/jsonl_test.go b/writer/jsonl_test.go index 7a25ff1..6a4ad5f 100644 --- a/writer/jsonl_test.go +++ b/writer/jsonl_test.go @@ -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"]} } diff --git a/writer/sarif.go b/writer/sarif.go index 8e1904a..8a0a0f7 100644 --- a/writer/sarif.go +++ b/writer/sarif.go @@ -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() } diff --git a/writer/writer_test.go b/writer/writer_test.go index 605be61..a6ba20f 100644 --- a/writer/writer_test.go +++ b/writer/writer_test.go @@ -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)) } }