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

compares: problem with types juggling #135

Open ccoVeille opened 5 months ago

ccoVeille commented 5 months ago

Here is a valid piece of code I have in my code base

There is a function that returns an int32, the tests checks if the value is under the max of int16

Here is the minimum to reproduce the issue

    val := int32(42)
    require.True(t, val <= math.MaxInt16)

The code is autofixed to this

    val := int32(42)
    require.LessOrEqual(t, val, math.MaxInt16)

Which is valid, BUT then require.LessOrEqual will report that val(int32) is not from the same type as math.MaxInt16) (an untyped int)

                Error:          Elements should be the same type

Yes, the code could have been written in a another way, but testifylint provided something that cannot work.