Skip to content

Commit

Permalink
[chore]: enable error-nil rule from testifylint (#5843)
Browse files Browse the repository at this point in the history
Testifylint is a linter that provides best practices with the use of
testify.

This PR enables
[error-nil](https://github.com/Antonboom/testifylint?tab=readme-ov-file#error-nil)
rule from [testifylint](https://github.com/Antonboom/testifylint)

Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
Co-authored-by: Robert Pająk <pellared@hotmail.com>
  • Loading branch information
mmorel-35 and pellared authored Sep 25, 2024
1 parent 316114c commit d284a86
Show file tree
Hide file tree
Showing 13 changed files with 8 additions and 14 deletions.
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,6 @@ linters-settings:
testifylint:
enable-all: true
disable:
- error-nil
- expected-actual
- float-compare
- go-require
Expand Down
2 changes: 1 addition & 1 deletion bridge/opencensus/metric_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func TestMetricProducer(t *testing.T) {
if tc.expectErr {
require.Error(t, err)
} else {
require.Nil(t, err)
require.NoError(t, err)
}
require.Equal(t, len(output), len(tc.expected))
for i := range output {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (

func requireErrorString(t *testing.T, expect string, err error) {
t.Helper()
require.NotNil(t, err)
require.Error(t, err)
require.ErrorIs(t, err, PartialSuccess{})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestMultiErr(t *testing.T) {
me := &multiErr{datatype: name}

t.Run("ErrOrNil", func(t *testing.T) {
require.Nil(t, me.errOrNil())
require.NoError(t, me.errOrNil())
me.errs = []error{e0}
assert.Error(t, me.errOrNil())
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (

func requireErrorString(t *testing.T, expect string, err error) {
t.Helper()
require.NotNil(t, err)
require.Error(t, err)
require.ErrorIs(t, err, PartialSuccess{})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestMultiErr(t *testing.T) {
me := &multiErr{datatype: name}

t.Run("ErrOrNil", func(t *testing.T) {
require.Nil(t, me.errOrNil())
require.NoError(t, me.errOrNil())
me.errs = []error{e0}
assert.Error(t, me.errOrNil())
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (

func requireErrorString(t *testing.T, expect string, err error) {
t.Helper()
require.NotNil(t, err)
require.Error(t, err)
require.ErrorIs(t, err, PartialSuccess{})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (

func requireErrorString(t *testing.T, expect string, err error) {
t.Helper()
require.NotNil(t, err)
require.Error(t, err)
require.ErrorIs(t, err, PartialSuccess{})

Expand Down
2 changes: 1 addition & 1 deletion exporters/stdout/stdouttrace/trace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func TestExporterExportSpan(t *testing.T) {
// write to buffer for testing
var b bytes.Buffer
ex, err := stdouttrace.New(append(tt.opts, stdouttrace.WithWriter(&b))...)
require.Nil(t, err)
require.NoError(t, err)

err = ex.ExportSpans(tt.ctx, tracetest.SpanStubs{ss, ss}.Snapshots())
assert.Equal(t, tt.wantErr, err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestMultiErr(t *testing.T) {
me := &multiErr{datatype: name}

t.Run("ErrOrNil", func(t *testing.T) {
require.Nil(t, me.errOrNil())
require.NoError(t, me.errOrNil())
me.errs = []error{e0}
assert.Error(t, me.errOrNil())
})
Expand Down
1 change: 0 additions & 1 deletion internal/shared/otlp/partialsuccess_test.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (

func requireErrorString(t *testing.T, expect string, err error) {
t.Helper()
require.NotNil(t, err)
require.Error(t, err)
require.ErrorIs(t, err, PartialSuccess{})

Expand Down
4 changes: 2 additions & 2 deletions sdk/metric/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ func TestConfigReaderSignalsEmpty(t *testing.T) {
require.NotNil(t, s)

ctx := context.Background()
assert.Nil(t, f(ctx))
assert.Nil(t, s(ctx))
assert.NoError(t, f(ctx))
assert.NoError(t, s(ctx))
assert.ErrorIs(t, s(ctx), ErrReaderShutdown)
}

Expand Down
2 changes: 1 addition & 1 deletion sdk/trace/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ func testStoredError(t *testing.T, target interface{}) {
err := handler.errs[0]

require.Implements(t, (*error)(nil), target)
require.NotNil(t, target.(error))
require.Error(t, target.(error))

defer handler.Reset()
if errors.Is(err, target.(error)) {
Expand Down

0 comments on commit d284a86

Please sign in to comment.