testifylint icon indicating copy to clipboard operation
testifylint copied to clipboard

len: Len instead of Equal when actual is a variable

Open Limero opened this issue 1 year ago • 1 comments

testifylint v1.4.3 correctly suggests using assert.Len for the following cases:

expected := []string{"a", "b"}
assert.Equal(t, len(expected), 2)

actual := []string{"a", "b"}
assert.Equal(t, 2, len(actual))

expected := 2
actual := []string{"a", "b"}
assert.Equal(t, expected, len(actual))

However, this case is not detected:

expected := []string{"a", "b"}
actual := 2
assert.Equal(t, len(expected), actual)

Limero avatar Jul 30 '24 09:07 Limero

Thanks for reporting the issue. We will be OK at it.

So it's more suggestion of improvement than a bug, so it's good.

The team is currently not working actively as it's summer. So be patient.

Do you have an example of existing code available on GitHub that is like what you reported ? It could be code you fixed that no longer exists, so then please point us the PR

I'm asking because sometimes it helps to find other pattern in existing code surrounding the one you want us to consider

Thanks by advance

ccoVeille avatar Jul 30 '24 10:07 ccoVeille

hi, @Limero

However, this case is not detected:

It is expected behaviour, which was introduced after

  • https://github.com/Antonboom/testifylint/issues/9
  • https://github.com/Antonboom/testifylint/issues/40

assert.Equal(t, len(expected), actual) is not equivalent of assert.Len(t, expected, actual), because the first assertion means

check that actual value == length of expected val

(emphasis on the actual value) not the

check that len of expected value is actual value

(emphasis on the len assertion of expected value)

Antonboom avatar Nov 16 '24 11:11 Antonboom

Documentation improved in https://github.com/Antonboom/testifylint/commit/1d666af3dc3c74c17999df6bbdee40a38fba2064

Antonboom avatar Nov 17 '24 11:11 Antonboom