-
-
Notifications
You must be signed in to change notification settings - Fork 63
catalog: add golang func call in defer example #801
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
…ample Co-authored-by: HerringtonDarkholme <[email protected]>
Co-authored-by: HerringtonDarkholme <[email protected]>
Co-authored-by: HerringtonDarkholme <[email protected]>
@copilot please remove npm-lock file since this repo is using pnpm |
Important Review skippedBot user detected. To trigger a single review, invoke the You can disable this status message by setting the 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Join our Discord community for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Pull Request Overview
This PR adds a new Go example to the ast-grep catalog that detects a common anti-pattern in defer statements where function calls are evaluated immediately instead of when the defer executes. The example specifically targets testing code that incorrectly defers assertion calls with failpoint management functions.
- Adds detection for defer statements that call assertion functions with failpoint methods as parameters
- Provides clear explanation of Go's defer evaluation timing and why this pattern is problematic
- Includes a real-world example from TiDB codebase and suggested fix using anonymous functions
Reviewed Changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
website/catalog/go/defer-func-call-antipattern.md |
New catalog entry with ast-grep rule to detect problematic defer statements in Go testing code |
website/catalog/go/index.md |
Added include directive for the new defer antipattern example |
Co-authored-by: HerringtonDarkholme <[email protected]>
Removed package-lock.json and updated .gitignore to prevent it from being added in the future since this repository uses pnpm. (commit c4f8e92) |
This PR adds a Golang example to the catalog to detect a common anti-pattern where
defer
statements contain function calls with parameters that are evaluated immediately instead of when the defer executes.The issue commonly occurs in Go testing code when using assertion libraries with failpoint management:
In the problematic version,
failpoint.Disable("some/path")
is evaluated when the defer statement is encountered, not when the function exits. This makes the failpoint disabled immediately after being enabled, rendering tests ineffective.Changes:
website/catalog/go/defer-func-call-antipattern.md
with:defer $A.$B(t, failpoint.$M($$$))
defer_statement
selectorwebsite/catalog/go/index.md
to include the new exampleThe ast-grep pattern detects defer statements matching:
This addresses a real issue found in the TiDB codebase where thousands of similar problematic defer statements existed.
Fixes #793.
Warning
Firewall rules blocked me from connecting to one or more addresses
I tried to connect to the following addresses, but was blocked by firewall rules:
plugins.dprint.dev
/home/REDACTED/work/ast-grep.github.io/ast-grep.github.io/node_modules/dprint/dprint check
(dns block)/home/REDACTED/work/ast-grep.github.io/ast-grep.github.io/node_modules/dprint/dprint fmt
(dns block)If you need me to access, download, or install something from one of these locations, you can either:
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.