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

contains: use `Contains` instead of `strings.Contains` #54

Closed nickajacks1 closed 4 months ago

nickajacks1 commented 9 months ago

Using assert.True on strings.Contains does not print out useful information about the arguments in the case of a failure. assert.Contains, on the other hand, will report both values on failure.

❌
     assert.True(t, strings.Contains(s, "abc123"))
     assert.True(t, strings.Contains(string(b), "abc123"))

✅
     assert.Contains(t, s, "abc123")
     assert.Contains(t, string(b), "abc123")

assert.Contains doesn't seem to work well with byte slices, so users would need to convert the bytes to strings. Consequently, I'm not too sure about including bytes.Contains in the same lint rule.

Antonboom commented 9 months ago

Hi, @nickajacks1!

Thank you for proposal.

assert.Contains doesn't seem to work well with byte slices

offtop: maybe to open issue/PR in testify?

nickajacks1 commented 9 months ago

Good idea, I'll look into that and report back here.

Antonboom commented 9 months ago

Full-featured implementation is blocked by https://github.com/stretchr/testify/pull/1526