Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: enable formatter.require-f-funcs from testifylint #2836

Conversation

mmorel-35
Copy link
Contributor

What does this PR do?

Setup formatter.require-f-funcs from testifylint linter and apply it’s recommandations .

Why is it important?

To require f-assertions if format string is used.

Signed-off-by: Matthieu MOREL [email protected]

Copy link

netlify bot commented Oct 18, 2024

Deploy Preview for testcontainers-go ready!

Name Link
🔨 Latest commit 0cbdab1
🔍 Latest deploy log https://app.netlify.com/sites/testcontainers-go/deploys/67128a26b373690008ba84f4
😎 Deploy Preview https://deploy-preview-2836--testcontainers-go.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@mmorel-35 mmorel-35 marked this pull request as ready for review October 18, 2024 13:20
@mmorel-35 mmorel-35 requested a review from a team as a code owner October 18, 2024 13:20
@mdelapenya
Copy link
Member

What is your experience with this rule? I think we are doing good progress in throwing more meaningful error messages, which will be part of the test failure in the case require.Error fails. So I'm not very sure about including this one. Wdyt?

Copy link
Collaborator

@stevenh stevenh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand this one, could you clarify why this change is beneficial?

@mmorel-35
Copy link
Contributor Author

I probably missed something because it's not the intention of the rule to reduce the readability of the test results, on the contrary.
Let's check.

The rule reason is explained here
https://github.com/Antonboom/testifylint?tab=readme-ov-file#formatter

There is also more to read
https://github.com/Antonboom/testifylint?tab=readme-ov-file#historical-reference

@stevenh
Copy link
Collaborator

stevenh commented Oct 18, 2024

I probably missed something because it's not the intention of the rule to reduce the readability of the test results, on the contrary. Let's check.

The rule reason is explained here https://github.com/Antonboom/testifylint?tab=readme-ov-file#formatter

There is also more to read https://github.com/Antonboom/testifylint?tab=readme-ov-file#historical-reference

Yer that's there to eliminate an embedded fmt.Sprintf as those messages are just raw strings it's not needed.

So its needed for this:

assert.Errorf(t, err, fmt.Sprintf("test %s", test.testName)) // Bad
assert.Errorf(t, err, "test %s", test.testName) // Good

But not needed for this:

assert.Error(t, err, "thing should error") // Not needed as no replaceable variables

@mmorel-35
Copy link
Contributor Author

Have look over here, Antonboom/testifylint#177 (comment)
I asked the same question to testifylint's author

@mmorel-35 mmorel-35 force-pushed the testifylint/formatter/require-f-funcs branch from 358566d to 9509a90 Compare October 18, 2024 15:49
@mmorel-35 mmorel-35 force-pushed the testifylint/formatter/require-f-funcs branch from 9509a90 to 0cbdab1 Compare October 18, 2024 16:17
@stevenh
Copy link
Collaborator

stevenh commented Oct 18, 2024

Have look over here, Antonboom/testifylint#177 (comment) I asked the same question to testifylint's author

Thanks for that context, really useful.

Having read the history and looked at the code for assert / require, I believe there's a case which was overlooked. If you trace the calls you'll end up in messageFromMsgAndArgs which has a specific case for a single argument as can be found here.

So f versions are actually only required in the case where there is more than one argument.

If that rule doesn't handle that edge case I suggest we leave it disabled as it would cause churn for no real value, I would even suggest that including a reason for things like NoError add little to no value so would be better removed.

@mmorel-35
Copy link
Contributor Author

mmorel-35 commented Oct 18, 2024

OK, I'll close this PR.
@mdelapenya , @stevenh ,
But I would like to suggest having a look at

require.Error(t, results.FirstErr(), kerr.UnknownTopicOrPartition) //nolint:testifylint

In modules/redpanda/redpanda_test.go .

Shall it be turned into

require.ErrorIs(t, results.FirstErr(), kerr.UnknownTopicOrPartition)

or

require.ErrorContains(t, results.FirstErr(), kerr.UnknownTopicOrPartition)

Or am I missing the understanding of the behavior of that test ?

@mmorel-35 mmorel-35 closed this Oct 18, 2024
@mmorel-35 mmorel-35 deleted the testifylint/formatter/require-f-funcs branch October 18, 2024 17:56
@stevenh
Copy link
Collaborator

stevenh commented Oct 21, 2024

Yes @mmorel-35 nice catch, that should be an ErrorIs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants