Antonboom / testifylint

The Golang linter that checks usage of github.com/stretchr/testify.
https://github.com/stretchr/testify
MIT License
97 stars 9 forks source link

feature: tools/testifier #28

Closed Antonboom closed 2 months ago

Antonboom commented 10 months ago

The tool that rewrites std testing.T assertions with stretchr/testify.

Example

Before:

func TestEncryptAndDecryptData(t *testing.T) {
    key1, err := CreateRandBytes(kubeadmconstants.CertificateKeySize)
    if err != nil {
        t.Fatal(err)
    }

    key2, err := CreateRandBytes(kubeadmconstants.CertificateKeySize)
    if err != nil {
        t.Fatal(err)
    }
    // ...
}

After:

func TestEncryptAndDecryptData(t *testing.T) {
    key1, err := CreateRandBytes(kubeadmconstants.CertificateKeySize)
    require.NoError(t, err)

    key2, err := CreateRandBytes(kubeadmconstants.CertificateKeySize)
    require.NoError(t, err)
    // ...
}

P.S. Press 👍 if you think this idea make sense.

ccoVeille commented 5 months ago

Extracted from this comment from maintainer in a PR about adding something to CONTRIBUTING

https://github.com/Antonboom/testifylint/pull/77#discussion_r1554848583

Hi!

1. I meant a more common solution than just fatal replacer.

2. `testifier` proposed to be a separate tool and maybe in separate repo

So the idea in this issue is more than adding new rules.

It might be a separate linter that will detect if code is tests could be replaced by using testify (either if code is partially using testify or simply not using it)