Skip to content

Add linting rule for preferring defer over t.Cleanup in tests (except helpers) #3181

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

Closed
mafredri opened this issue Jul 25, 2022 · 1 comment
Labels
stale This issue is like stale bread.

Comments

@mafredri
Copy link
Member

The premise is that we want tests to use defer so that they read like idiomatic Go code and that there is no mixed usage of defer and t.Cleanup (since the order of execution is hard to reason about, and rarely the intent). The exception is test helper functions.

This was requested in #3113 but not required for merging the PR.

A few examples for ruleguard rules was floated in #3113 but both have unnecessary repercussions:

  1. Simple rule is too aggressive
  2. More specific rule does not catch non-toplevel uses (e.g. if the t.Cleanup is inside if {} it won't be caught
@github-actions
Copy link

This issue is becoming stale. In order to keep the tracker readable and actionable, I'm going close to this issue in 7 days if there isn't more activity.

@github-actions github-actions bot added the stale This issue is like stale bread. label Sep 24, 2022
@github-actions github-actions bot closed this as completed Oct 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale This issue is like stale bread.
Projects
None yet
Development

No branches or pull requests

1 participant