-
Notifications
You must be signed in to change notification settings - Fork 8
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
Incorrect formatter fix with single non-string msgAndArgs
argument
#169
Comments
msgAndArgs
argumentmsgAndArgs
argument
Thanks for reporting this. It's indeed a real bug that has consequences We will take a look. |
I took a look. I found the piece of code involved. I started adding the unit test. I will have to find a way to detect such "uncommon" usage. I'm very polite here, because the example you gave looks improper usage of testify. But then, I'm unsure how to ignore/report it Reporting it as invalid could be counter productive on large code base. So for now, I think the better would be to simply ignore it |
Hey @pgimalac do you have any real life example available on GitHub that you could share about this ? Thanks |
I ran the linter on the https://github.com/DataDog/datadog-agent repository (over 1.1M LoC in Go, including 400k lines of test) and found dozens of occurrences (at least 30). Most of them look like invalid uses of testify (eg. missing
Maybe a disabled-by-default rule to warn when the first |
Thanks for your valuable examples. I think for now, what's is important is to avoid suggesting something invalid. then I have doubts about what else we could/should do :
|
Linking the testify PR which allowed using non-string if there's a single msg argument stretchr/testify#699, for reference. It mentions it's to help with debugging so arguably that doesn't make it a correct usage, but now that it works it's not great if the suggested fix doesn't compile... On the other hand even without considering non-string argument, the fix is invalid when passing
|
Thanks for pointing out the PR and context. Please expect delays as most maintainers are in holidays (including me) |
No worries I'm really not in a hurry, I can just disable the rule anyway ! |
@pgimalac Hi! Thank you for issue
Thanks 🫡 |
Testify assertions can be called with a non-string value for
msgAndArgs
argument if there is a single such argument, as can be seen in the code it will be rendered usingfmt.Sprintf("%+v")
.This means that using
assert.Fail(t, "failed", true)
is functionally correct (this example is odd, but some cases can make sense, like using an error or some struct).But when using
-formatter.require-f-funcs
, the formatter rule oftestifylint
will replace this withassert.Failf(t, "failed", true)
, which doesn't compile as the first message argument of f-variant assertions must have type string.Minimal reproducible example:
The text was updated successfully, but these errors were encountered: