-
Notifications
You must be signed in to change notification settings - Fork 9.8k
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 rule from testifylint #18741
Conversation
Hi @ghouscht. Thanks for your PR. I'm waiting for a etcd-io member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files
... and 27 files with indirect coverage changes @@ Coverage Diff @@
## main #18741 +/- ##
==========================================
- Coverage 68.77% 68.71% -0.06%
==========================================
Files 420 420
Lines 35501 35501
==========================================
- Hits 24416 24395 -21
- Misses 9657 9675 +18
- Partials 1428 1431 +3 Continue to review full report in Codecov by Sentry.
|
@@ -40,12 +40,12 @@ func AssertNotNil(t *testing.T, v any) { | |||
// Deprecated: use github.com/stretchr/testify/assert.True instead. | |||
func AssertTrue(t *testing.T, v bool, msg ...string) { | |||
t.Helper() | |||
assert.True(t, v, msg) | |||
assert.True(t, v, msg) //nolint:testifylint |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both the AssertTrue
and AssertFalse
functions are part of the public API of the testutils
pkg. It looks like they are no longer used within the etcd codebase but they could be used outside of the etcd codebase. I thought it is best to keep them as they are, thus the nolint
directive. Let me know if you think that is ok.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Until this code is removed, it's better to keep it as is . I agree to disable the linter here
FYI: @mmorel-35 here is the second PR for the |
There are many places where the expected or unexpected error is is printed with I'm wondering if it's not redondant with the behavior of testify which will print it |
Yes, that is true. I can clean them up if you and the maintainers agree on that. |
I feel like it's the best opportunity to do that as most of them are probably modified in this PR. Let's see what the maintainers think. |
|
||
leaderIndex := epc.WaitLeader(t) | ||
_, err = epc.Procs[leaderIndex].Logs().ExpectWithContext(ctx, expect.ExpectedResponse{Value: "finished compaction hash check"}) | ||
require.NoError(t, err, "can't get log indicating finished compaction hash check") | ||
require.NoErrorf(t, err, "can't get log indicating finished compaction hash check") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: there is no variable-length variable in this case, shouldn't require.NoError
be better than require.NoErrorf
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note this is a generic question.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had the same question and the author of linter directed me to the rule's documentation:
https://github.com/Antonboom/testifylint?tab=readme-ov-file#formatter
And the historical note associated:
https://github.com/Antonboom/testifylint?tab=readme-ov-file#historical-reference
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should always use *f
functions when require-f-funcs: true
no matter there is variable-length variables or not?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That seems to be the recommended way to do indeed
- go-require | ||
- require-error | ||
enable-all: true | ||
formatter: | ||
require-f-funcs: true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does this option mean? Could you add a comment to clarify?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://golangci-lint.run/usage/linters/#testifylint states:
To require f-assertions if format string is used.
I'll add a comment 👍🏻
Yes, testify already prints the error, so we don't need to print it again. But not a big deal. |
4babfc2
to
2d144f0
Compare
76e0c60
to
be02cdb
Compare
👍🏻 I cleaned up the messages and removed redundant information. |
@ghouscht , |
/ok-to-test |
/test pull-etcd-integration-2-cpu-arm64 |
tools/.golangci.yaml
Outdated
- go-require | ||
- require-error | ||
enable-all: true | ||
formatter: | ||
# Require f-assertions (e.g. assert.Equalf) if a format string is used. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It could be just a nitpick on the comment, but after reading
- this conversation fix: enable formatter rule from testifylint #18741 (comment)
- and the references https://github.com/Antonboom/testifylint?tab=readme-ov-file#formatter, https://github.com/Antonboom/testifylint?tab=readme-ov-file#historical-reference.
I think this comment's "format string" part is inaccurate. The suggestion is to use the *f
functions regardless of whether the message string has formatting or not (if I understood correctly).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In https://golangci-lint.run/usage/linters/#testifylint
The comment is:
To require f-assertions if format string is used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, even in the documentation from golangci-lint it is not very accurate. I think it something like
Require f-assertions (e.g. assert.Equalf) if a message is passed to the assertion.
might be better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about
Require f-assertions (e.g.
assert.Equalf
) if a message is passed to the assertion, even there is no variable-length variables, i.e. requirerequire.NoErrorf
for both cases below,
require.NoErrorf(t, err, "whatever message")
require.NoErrorf(t, err, "whatever message: %v", v)
be02cdb
to
4af1959
Compare
Signed-off-by: Thomas Gosteli <[email protected]>
4af1959
to
ff4a8df
Compare
/test pull-etcd-integration-1-cpu-amd64 |
/test pull-etcd-integration-1-cpu-amd64 One last try, seems there is always some kind of timeout in this test. |
From golang programming perspective, I think we still prefer non-f-functions (i.e. For example, we prefer to use in
in
But in stretchr/testify, each f-function is actually a syntax sugar of corresponding non-f-function. For example, So there is no reason to keep both. But they can't simplify remove anyone otherwise it will break lots of application's tests.
So it's accepted to always require |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: ahrtr, ghouscht, ivanvc, mmorel-35 The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Raised a followup #18766 |
Hi, guys @ghouscht appeciated for using of @ahrtr, @ivanvc I improved the linter description based on your threads:
Also, I reviewed the
It leads to the following points:
Thanks! 😭 |
This PR enables the
formatter
testifylint rule as part of #18719Please read https://github.com/etcd-io/etcd/blob/main/CONTRIBUTING.md#contribution-flow.