diff --git a/.golangci.yml b/.golangci.yml index 8923200..164bd51 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -32,7 +32,6 @@ linters: disable-all: true enable: - bodyclose - - depguard - dogsled - errcheck - errorlint diff --git a/assert/assert_test.go b/assert/assert_test.go index 97ec8dd..6deede8 100644 --- a/assert/assert_test.go +++ b/assert/assert_test.go @@ -105,12 +105,14 @@ func TestAssertWithBoolMultiLineFailure(t *testing.T) { fakeT := &fakeTestingT{} Assert(fakeT, func() bool { - for range []int{1, 2, 3, 4} { + for i := range []int{1, 2, 3, 4} { + _ = i } return false }()) expectFailNowed(t, fakeT, `assertion failed: expression is false: func() bool { - for range []int{1, 2, 3, 4} { + for i := range []int{1, 2, 3, 4} { + _ = i } return false }()`) @@ -244,7 +246,7 @@ func TestCheckEqualFailure(t *testing.T) { func TestCheck_MultipleFunctionsOnTheSameLine(t *testing.T) { fakeT := &fakeTestingT{} - f := func(b bool) {} + f := func(bool) {} f(Check(fakeT, false)) // TODO: update the expected when there is a more correct fix expectFailed(t, fakeT, diff --git a/assert/cmp/compare.go b/assert/cmp/compare.go index 118844f..3ced3de 100644 --- a/assert/cmp/compare.go +++ b/assert/cmp/compare.go @@ -248,7 +248,7 @@ type causer interface { } func formatErrorMessage(err error) string { - //nolint:errorlint // unwrapping is not appropriate here + //nolint:errorlint,nolintlint // unwrapping is not appropriate here if _, ok := err.(causer); ok { return fmt.Sprintf("%q\n%+v", err, err) } diff --git a/assert/opt/opt_test.go b/assert/opt/opt_test.go index c036d18..56019a3 100644 --- a/assert/opt/opt_test.go +++ b/assert/opt/opt_test.go @@ -261,5 +261,5 @@ func TestPathDebug(t *testing.T) { "label1": {}, }, } - gocmp.Equal(fixture, fixture, gocmp.FilterPath(PathDebug, gocmp.Ignore())) + assert.Check(t, gocmp.Equal(fixture, fixture, gocmp.FilterPath(PathDebug, gocmp.Ignore()))) } diff --git a/fs/report.go b/fs/report.go index 952aa26..773df21 100644 --- a/fs/report.go +++ b/fs/report.go @@ -50,8 +50,8 @@ func errProblem(reason string, err error) problem { return problem(fmt.Sprintf("%s: %s", reason, err)) } -func existenceProblem(filename, reason string, args ...interface{}) problem { - return problem(filename + ": " + fmt.Sprintf(reason, args...)) +func existenceProblem(filename string, msgAndArgs ...interface{}) problem { + return problem(filename + ": " + format.Message(msgAndArgs...)) } func eqResource(x, y resource) []problem { diff --git a/fs/report_test.go b/fs/report_test.go index 389d608..7c962c2 100644 --- a/fs/report_test.go +++ b/fs/report_test.go @@ -184,7 +184,7 @@ func TestMatchFileContent(t *testing.T) { defer dir.Remove() t.Run("content matches", func(t *testing.T) { - matcher := func(b []byte) CompareResult { + matcher := func([]byte) CompareResult { return is.ResultSuccess } manifest := Expected(t, @@ -193,7 +193,7 @@ func TestMatchFileContent(t *testing.T) { }) t.Run("content does not match", func(t *testing.T) { - matcher := func(b []byte) CompareResult { + matcher := func([]byte) CompareResult { return is.ResultFailure("data content differs from expected") } manifest := Expected(t, diff --git a/internal/source/source.go b/internal/source/source.go index df61234..9ac4bfa 100644 --- a/internal/source/source.go +++ b/internal/source/source.go @@ -72,7 +72,7 @@ func getNodeAtLine(fileset *token.FileSet, astFile ast.Node, lineNum int) (ast.N return node, err } } - return nil, nil + return nil, errors.New("failed to find expression") } func scanToLine(fileset *token.FileSet, node ast.Node, lineNum int) ast.Node { @@ -92,11 +92,8 @@ func scanToLine(fileset *token.FileSet, node ast.Node, lineNum int) ast.Node { func getCallExprArgs(fileset *token.FileSet, astFile ast.Node, line int) ([]ast.Expr, error) { node, err := getNodeAtLine(fileset, astFile, line) - switch { - case err != nil: + if err != nil { return nil, err - case node == nil: - return nil, fmt.Errorf("failed to find an expression") } debug("found node: %s", debugFormatNode{node}) @@ -104,7 +101,7 @@ func getCallExprArgs(fileset *token.FileSet, astFile ast.Node, line int) ([]ast. visitor := &callExprVisitor{} ast.Walk(visitor, node) if visitor.expr == nil { - return nil, errors.New("failed to find call expression") + return nil, errors.New("failed to find an expression") } debug("callExpr: %s", debugFormatNode{visitor.expr}) return visitor.expr.Args, nil diff --git a/internal/source/source_test.go b/internal/source/source_test.go index 3c21819..aa30304 100644 --- a/internal/source/source_test.go +++ b/internal/source/source_test.go @@ -47,13 +47,13 @@ func shim(_, _, _ string) (string, error) { func TestFormattedCallExprArg_InDefer(t *testing.T) { skip.If(t, isGoVersion18) - cap := &capture{} + c := &capture{} func() { - defer cap.shim("first", "second") + defer c.shim("first", "second") }() - assert.NilError(t, cap.err) - assert.Equal(t, cap.value, `"second"`) + assert.NilError(t, c.err) + assert.Equal(t, c.value, `"second"`) } func isGoVersion18() bool { @@ -70,25 +70,25 @@ func (c *capture) shim(_, _ string) { } func TestFormattedCallExprArg_InAnonymousDefer(t *testing.T) { - cap := &capture{} + c := &capture{} func() { fmt.Println() defer fmt.Println() - defer func() { cap.shim("first", "second") }() + defer func() { c.shim("first", "second") }() }() - assert.NilError(t, cap.err) - assert.Equal(t, cap.value, `"second"`) + assert.NilError(t, c.err) + assert.Equal(t, c.value, `"second"`) } func TestFormattedCallExprArg_InDeferMultipleDefers(t *testing.T) { skip.If(t, isGoVersion18) - cap := &capture{} + c := &capture{} func() { fmt.Println() defer fmt.Println() - defer cap.shim("first", "second") + defer c.shim("first", "second") }() - assert.ErrorContains(t, cap.err, "ambiguous call expression") + assert.ErrorContains(t, c.err, "ambiguous call expression") } diff --git a/poll/example_test.go b/poll/example_test.go index 2e3c32d..21690d0 100644 --- a/poll/example_test.go +++ b/poll/example_test.go @@ -35,7 +35,7 @@ func isDesiredState() bool { return false } func getState() string { return "" } func ExampleSettingOp() { - check := func(t poll.LogT) poll.Result { + check := func(poll.LogT) poll.Result { if isDesiredState() { return poll.Success() } diff --git a/poll/poll.go b/poll/poll.go index a64f770..bd0b4b9 100644 --- a/poll/poll.go +++ b/poll/poll.go @@ -152,7 +152,7 @@ func Compare(compare cmp.Comparison) Result { if assert.RunComparison(buf, assert.ArgsAtZeroIndex, compare) { return Success() } - return Continue(buf.String()) + return Continue("%v", buf.String()) } type logBuffer struct { diff --git a/poll/poll_test.go b/poll/poll_test.go index 8f763c3..ba9ad2e 100644 --- a/poll/poll_test.go +++ b/poll/poll_test.go @@ -18,9 +18,9 @@ func (t *fakeT) Fatalf(format string, args ...interface{}) { panic("exit wait on") } -func (t *fakeT) Log(args ...interface{}) {} +func (t *fakeT) Log(...interface{}) {} -func (t *fakeT) Logf(format string, args ...interface{}) {} +func (t *fakeT) Logf(string, ...interface{}) {} func TestContinueMessage(t *testing.T) { tests := []struct { @@ -52,7 +52,7 @@ func TestContinueMessage(t *testing.T) { func TestWaitOn(t *testing.T) { counter := 0 end := 4 - check := func(t LogT) Result { + check := func(LogT) Result { if counter == end { return Success() } @@ -67,7 +67,7 @@ func TestWaitOn(t *testing.T) { func TestWaitOnWithTimeout(t *testing.T) { fakeT := &fakeT{} - check := func(t LogT) Result { + check := func(LogT) Result { return Continue("not done") } @@ -80,7 +80,7 @@ func TestWaitOnWithTimeout(t *testing.T) { func TestWaitOnWithCheckTimeout(t *testing.T) { fakeT := &fakeT{} - check := func(t LogT) Result { + check := func(LogT) Result { time.Sleep(1 * time.Second) return Continue("not done") } @@ -92,7 +92,7 @@ func TestWaitOnWithCheckTimeout(t *testing.T) { func TestWaitOnWithCheckError(t *testing.T) { fakeT := &fakeT{} - check := func(t LogT) Result { + check := func(LogT) Result { return Error(fmt.Errorf("broke")) } @@ -103,7 +103,7 @@ func TestWaitOnWithCheckError(t *testing.T) { func TestWaitOn_WithCompare(t *testing.T) { fakeT := &fakeT{} - check := func(t LogT) Result { + check := func(LogT) Result { return Compare(cmp.Equal(3, 4)) } diff --git a/x/subtest/example_test.go b/x/subtest/example_test.go index b4365e0..1e0cf0a 100644 --- a/x/subtest/example_test.go +++ b/x/subtest/example_test.go @@ -44,7 +44,7 @@ func ExampleRun_tableTest() { } } -func startFakeService(t subtest.TestContext) string { +func startFakeService(_ subtest.TestContext) string { return "url" }