Closed WillAbides closed 11 months ago
Describe the bug Five of the revive's formatters always return an empty string for output. Instead of returning the output, they are writing directly to os.Stdout. The five formatters are default, friendly, ndjson, plain and unix.
os.Stdout
To Reproduce Steps to reproduce the behavior:
Run this test: https://go.dev/play/p/b2yCM6m3PyM
Expected behavior
I expect the test to pass because the output has been returned from the formatter and nothing was written to stdout.
Logs
--- FAIL: TestFormatter (0.01s) --- FAIL: TestFormatter/default (0.00s) testme_test.go:166: formatter wrote to stdout: "test.go:2:5: test failure\n" testme_test.go:171: got "", want "test.go:2:5: test failure" --- FAIL: TestFormatter/friendly (0.00s) testme_test.go:166: formatter wrote to stdout: " ⚠ https://revive.run/r#rule test failure \n test.go:2:5\n\n⚠ 1 problem (0 errors, 1 warning)\n\nWarnings:\n 1 rule \n\n" testme_test.go:171: got "", want "⚠ https://revive.run/r#rule test failure \n test.go:2:5\n\n⚠ 1 problem (0 errors, 1 warning)\n\nWarnings:\n 1 rule" --- FAIL: TestFormatter/ndjson (0.00s) testme_test.go:166: formatter wrote to stdout: "{\"Severity\":\"warning\",\"Failure\":\"test failure\",\"RuleName\":\"rule\",\"Category\":\"cat\",\"Position\":{\"Start\":{\"Filename\":\"test.go\",\"Offset\":0,\"Line\":2,\"Column\":5},\"End\":{\"Filename\":\"test.go\",\"Offset\":0,\"Line\":2,\"Column\":10}},\"Confidence\":0,\"ReplacementLine\":\"\"}\n" testme_test.go:171: got "", want "{\"Severity\":\"warning\",\"Failure\":\"test failure\",\"RuleName\":\"rule\",\"Category\":\"cat\",\"Position\":{\"Start\":{\"Filename\":\"test.go\",\"Offset\":0,\"Line\":2,\"Column\":5},\"End\":{\"Filename\":\"test.go\",\"Offset\":0,\"Line\":2,\"Column\":10}},\"Confidence\":0,\"ReplacementLine\":\"\"}" --- FAIL: TestFormatter/plain (0.00s) testme_test.go:166: formatter wrote to stdout: "test.go:2:5: test failure https://revive.run/r#rule\n" testme_test.go:171: got "", want "test.go:2:5: test failure https://revive.run/r#rule" --- FAIL: TestFormatter/unix (0.00s) testme_test.go:166: formatter wrote to stdout: "test.go:2:5: [rule] test failure\n" testme_test.go:171: got "", want "test.go:2:5: [rule] test failure" FAIL FAIL github.com/mgechev/revive/testme 0.183s FAIL
Desktop (please complete the following information):
Additional context Add any other context about the problem here.
Describe the bug Five of the revive's formatters always return an empty string for output. Instead of returning the output, they are writing directly to
os.Stdout
. The five formatters are default, friendly, ndjson, plain and unix.To Reproduce Steps to reproduce the behavior:
Run this test: https://go.dev/play/p/b2yCM6m3PyM
expand
```go package main import ( "go/token" "os" "strings" "testing" "github.com/mgechev/revive/formatter" "github.com/mgechev/revive/lint" ) func TestFormatter(t *testing.T) { lintFailure := lint.Failure{ Failure: "test failure", RuleName: "rule", Category: "cat", Position: lint.FailurePosition{ Start: token.Position{ Filename: "test.go", Line: 2, Column: 5, }, End: token.Position{ Filename: "test.go", Line: 2, Column: 10, }, }, } for _, td := range []struct { name string formatter lint.Formatter want string }{ { name: "checkstyle", formatter: &formatter.Checkstyle{}, want: `Expected behavior
I expect the test to pass because the output has been returned from the formatter and nothing was written to stdout.
Logs
Desktop (please complete the following information):
Additional context Add any other context about the problem here.