-
Notifications
You must be signed in to change notification settings - Fork 2
Disable nonsensical usetesting context linting rule #223
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
Conversation
|
I'm still inclined to say that using Yes, there are cases where it must not be used, but that forces one to think about proper use of the |
This is the complete list of occurrences of
|
And yet there are many proponents, the proposal was accepted, and it reduces some boilerplate.
It's relatively new, and would require touching many files, potentially blocking other PRs or at least causing more work. It can happen over time, package by package. Time will tell.
Marking the "92% of cases" as false positive is subjective, imo. The Anyhow, it's fine that the default for the linter will be changed. It'll end up being a matter of code review, and personal preference then. |
|
Given that the default is going to change with the next golangci-lint update, can we get this PR merged please, before this linter introduces more |
|
I disagree with disabling |
|
Yeah, context.TODO is a weird one, and I’m not a fan of the decision to include it in the stdlib. In most cases, I consider it a red flag, both in testing and in production code. |
usetestingenforces the use oft.Contexteverywhere, even int.Cleanup. This is incorrect, as that context is cancelled just beforeCleanupis called.Furthermore, in many cases,
context.Backgroundis used like this:Here it doesn't make any difference if
context.Backgroundort.Contextis used:doSomethingdoesn't block indefinitely, it will return eventually.doSomethingblocks longer than the test timeout,go testwill fail.There are a few situations where
t.Contextis useful:context.WithCancel.Also see https://github.com/smallstep/bouncer/pull/260.