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

empty: add integers conversion #115

Closed ccoVeille closed 5 months ago

ccoVeille commented 5 months ago

This pattern should be detected

assert.Equal(t, 0, int(ret.ExitCode))
assert.Equal(t, 0, int(ret.GasUsed))

Example: https://github.com/ipfs-force-community/go-fvm-sdk/blob/d49236897af1fdb5e0f7d29573fcbe1d29e2214d/sdk/cases/send.go#L40-L41

The following code should be suggested

assert.Empty(t, ret.ExitCode)
assert.Empty(t, ret.GasUsed)

This pattern is currently not detected, while it's pretty commonly used https://github.com/search?q=language%3Ago+%22assert.Equal%28t%2C+0%2C+int%22&type=code

Antonboom commented 5 months ago

Please, do not use Empty for objects for which len is not applicable. For me these are Zero cases and use Empty is not best and doubtful option here.

ccoVeille commented 5 months ago

That's right. As you declined the idea of a zero checker, I assumed you didn't want to suggest using zero.

BTW, I just found out these cannot be part of empty checker, as nothing detects this now

a := 17
assert.Equal(t, 0, a)

So I'm unsure where to add it

ccoVeille commented 5 months ago

here are some other use cases

https://github.com/search?q=%22assert.Equal%28t%2C+int%280%29%2C%22+NOT+is%3Aarchived+NOT+is%3Afork+language%3Ago&type=code

https://github.com/karim7262/datadog-agent/blob/a48b9b58fb9f13e53782a936783da2cc4b7b0c7c/pkg/autodiscovery/providers/zookeeper_test.go#L206

assert.Equal(t, int(0), zkr.cache.NumAdTemplates)
Antonboom commented 5 months ago

As you declined the idea of a zero checker, I assumed you didn't want to suggest using zero.

Yes, we are in a stalemate – I have nothing against zero that concentrated on zero objects only, how I mentioned before – https://github.com/Antonboom/testifylint/issues/75#issuecomment-2067582114. But I do not want introduce any complex matrix solutions spread across checkecks

So, let's just ignore assert.Equal(t, 0, a) and similar