-
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
require-error: detect if !assert.NoError
#125
Comments
This use case is interesting, yes. |
assert
assert
if !assert.NoError
This is interesting:
I have:
I have:
It seems that only the last |
The issue you report here is a bit different than the issue described in this issue I think. Please note, I'm not saying you didn't find an issue. I'm saying it's different. While they are both related to require-error, the error reported by @mmorel-35 is about a detection improvement that should consider the fact an assert test followed by a return could be suggested to be replaced by a require. So it's a suggestion of improvement about something that is not coded now. What you found is an "oddities" with the current require-error checker. I'm surprised by two things:
|
@ccoVeille Yes, you're right, I should have opened a new PR. However, regarding the mentioned improvement ("an assert test followed by a return could be suggested to be replaced by a require"), it's also worth considering that such an
which is run in a goroutine, in my opinion, shouldn't be flagged as a problem. I understand that the examples presented by @mmorel-35 only involve a simple |
Exactly, thanks for providing a good example of what should not be reported. Matthieu and I were only talking about reporting code exactly like this one if assert.Whatever(t, … {
return
} To report using require.Whatever(t, … I use pseudocode here, the whatever could be an asserter about errors (assert.Error, assert.ErrorIs, …) or something as simple as assert.Equal Because the pattern about using if + return is about using require, no matter the asserter. I agree go-require seems the right candidate. (So not require-error) |
Your example showed that we shouldn't report an if + assert.Error with require.Error in require-error checker |
@ccoVeille Quick debugging and it seems the last is not reported because of this: And none of these if statements with negation are being treated as if statements (i.e. is missing here: |
Thank you, it will help us. I don't have a computer with me for the next few days. Maybe Matthieu or Anton will look at it Of course, you can open a PR after reading the contribution guide |
While applying require-error on https://github.com/argoproj/argo-cd I have seen this pattern many times
I fixed require-error rule by replacing it with
There was also some variations like
That could be replaced with
Also, the
return
was replaced by acontinue
in a loop.I’m wondering it would be pertinent to identify this with testifylint ?
The text was updated successfully, but these errors were encountered: