Golangci-lint 1.55 bundles in testifylint
, which must be the best new linter in years, aiming to make calls to the testify
package more consistent.
Its best aspect is being able to detect reversed parameters. i.e. require.Equal(t, actual, expected)
when it should be require.Equal(t, expected, actual)
. An example fix from River:
- require.Equal(t, cleaner.Config.RescueAfter, RescueAfterDefault)
+ require.Equal(t, RescueAfterDefault, cleaner.Config.RescueAfter)
But there’s many other good ones. Requiring Len
instead of using an equality assertion:
- require.Len(t, job.Errors, 0)
+ require.Empty(t, job.Errors)
Or use of ErrorAs
:
err1 := &UnknownJobKindError{Kind: "MyJobArgs"}
var err2 *UnknownJobKindError
- require.True(t, errors.As(err1, &err2))
+ require.ErrorAs(t, err1, &err2)