Antonboom / testifylint

The Golang linter that checks usage of github.com/stretchr/testify.
https://github.com/stretchr/testify
MIT License
101 stars 8 forks source link

error-nil: add Empty and Zero #138

Closed ccoVeille closed 1 month ago

ccoVeille commented 5 months ago

we do not detect error used with empty/zero, right now

var err error
assert.Empty(t, err)
assert.Zero(t, err)

We should recommend using NoError

var err error
assert.NoError(t, err)

this pattern is widely used https://github.com/search?q=language%3Ago+%22assert.Empty%28t%2C+err%22&type=code https://github.com/search?q=language%3Ago+%22assert.Zero%28t%2C+err%29%22&type=code

These two are candidates for error-nil

Originally posted by @ccoVeille in https://github.com/Antonboom/testifylint/issues/119#issuecomment-2181588845

ccoVeille commented 5 months ago

Please confirm if the logic is valid for you, then I can code it

Antonboom commented 5 months ago

Yes, this is valid for me.

Need to add to ignored cases in tests:

assert.Empty(t, errs)
assert.Empty(t, err.String())