Skip to content
This repository has been archived by the owner on May 9, 2021. It is now read-only.

Check for context.TODO() in functions that have a context.Context argument. #227

Closed
wants to merge 2 commits into from

Conversation

d4l3k
Copy link
Contributor

@d4l3k d4l3k commented Aug 1, 2016

This adds a check for context.TODO() in functions that have a context.Context parameter and suggests using that instead.

I think that this would be a nice check to have especially now that the context package is going to be part of stdlib.

Relates to cockroachdb/cockroach#1779.

@d4l3k
Copy link
Contributor Author

d4l3k commented Aug 1, 2016

/cc @tamird

@tamird
Copy link

tamird commented Aug 1, 2016

👍 on the idea. This is fragile in the face of other packages locally imported as "context" or "context" being imported under a different name.

@d4l3k
Copy link
Contributor Author

d4l3k commented Aug 2, 2016

@tamird Updated to correctly infer the package name alias for "context" and "golang.org/x/net/context" to avoid those issues.

@tamird
Copy link

tamird commented Aug 2, 2016

Cool. @bradfitz

@bradfitz
Copy link
Contributor

bradfitz commented Aug 2, 2016

Yes? I've never touched golint.

@tamird
Copy link

tamird commented Aug 2, 2016

Ah, apologies. @dsymonds seems to be the most active maintainer

On Aug 1, 2016 20:29, "Brad Fitzpatrick" notifications@github.com wrote:

Yes? I've never touched golint.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#227 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/ABdsPDHekVImp15gRfm2sjPbv67s1clbks5qbo-FgaJpZM4JZ7S6
.

@dsymonds
Copy link
Contributor

dsymonds commented Aug 2, 2016

I don't own this any more, but it's not the right place. This new check isn't a matter of style, but one of correctness, so it'd belong in govet, not golint.

@zimmski
Copy link
Contributor

zimmski commented Aug 2, 2016

@dsymonds: Who is the maintainer of golint now?

@dsnet
Copy link
Member

dsnet commented Aug 4, 2016

I agree with @dsymonds that this seems like a govet issue. Usage of context.TODO in a function that accepts a context.Context seems like issue of correctness, not style.

That being said, I think it is a good idea, and the documentation for context.TODO seems to indicate that this the intended situation:

TODO is recognized by static analysis tools that determine
whether Contexts are propagated correctly in a program.

Can you file a issue on https://github.com/golang/go/issues for cmd/vet?

@dsnet
Copy link
Member

dsnet commented Aug 16, 2016

I'm going to close this PR since it's captured in golang/go#16742.

@d4l3k, I encourage you to submit a similar change to golang/go to vet or something.

@dsnet dsnet closed this Aug 16, 2016
quasilyte pushed a commit to quasilyte/go-ruleguard that referenced this pull request Nov 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants