-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is only slightly different than `simple`. The only difference is it supports errorformating and can be used by reviewdog to signify errors vs warnings. * https://vim-jp.org/vimdoc-en/quickfix.html#error-file-format * https://github.com/reviewdog/reviewdog#input-format
- Loading branch information
1 parent
9947a55
commit 00685a0
Showing
5 changed files
with
70 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package printer | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/get-woke/woke/pkg/result" | ||
) | ||
|
||
// ErrorFormat is a ErrorFormat printer meant to be read by errorformat | ||
// https://vim-jp.org/vimdoc-en/quickfix.html#error-file-format | ||
type ErrorFormat struct { | ||
format string | ||
} | ||
|
||
// NewErrorFormat returns a new ErrorFormat printer | ||
func NewErrorFormat() *ErrorFormat { | ||
return &ErrorFormat{ | ||
format: "%s:%d:%d [%c] %s", | ||
} | ||
} | ||
|
||
// Print prints in the format 'filename:line:column: [s] message' | ||
// where `s` is the first character of Severity | ||
// The formatting is meant to line up with errorformat | ||
// "%f:%l:%c [%t] %m" | ||
// https://vim-jp.org/vimdoc-en/quickfix.html#error-file-format | ||
func (e *ErrorFormat) Print(fs *result.FileResults) error { | ||
for _, r := range fs.Results { | ||
fmt.Printf(e.format+"\n", | ||
r.StartPosition.Filename, | ||
r.StartPosition.Line, | ||
r.StartPosition.Column, | ||
r.Rule.Severity.String()[0], | ||
r.Reason()) | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package printer | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestErrorformat_Print(t *testing.T) { | ||
p := NewErrorFormat() | ||
res := generateFileResult() | ||
got := captureOutput(func() { | ||
assert.NoError(t, p.Print(res)) | ||
}) | ||
expected := fmt.Sprintf("foo.txt:1:6 [w] %s\n", res.Results[0].Reason()) | ||
assert.Equal(t, expected, got) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters