{"id":28950181,"url":"https://github.com/tkdn/deferargs","last_synced_at":"2026-04-01T20:23:55.110Z","repository":{"id":300515680,"uuid":"1006362181","full_name":"tkdn/deferargs","owner":"tkdn","description":"deferargs is a static analysis tool to detect defer statements that call a function with variable arguments.","archived":false,"fork":false,"pushed_at":"2026-03-20T21:50:37.000Z","size":55,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-03-21T12:57:51.322Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tkdn.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-06-22T05:04:47.000Z","updated_at":"2026-03-20T21:50:33.000Z","dependencies_parsed_at":"2025-08-08T05:28:27.260Z","dependency_job_id":null,"html_url":"https://github.com/tkdn/deferargs","commit_stats":null,"previous_names":["tkdn/deferargs"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/tkdn/deferargs","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tkdn%2Fdeferargs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tkdn%2Fdeferargs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tkdn%2Fdeferargs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tkdn%2Fdeferargs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tkdn","download_url":"https://codeload.github.com/tkdn/deferargs/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tkdn%2Fdeferargs/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31291549,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-01T13:12:26.723Z","status":"ssl_error","status_checked_at":"2026-04-01T13:12:25.102Z","response_time":53,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-06-23T13:31:03.079Z","updated_at":"2026-04-01T20:23:55.103Z","avatar_url":"https://github.com/tkdn.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# deferargs\n\n\u003c!-- [![Go Report Card](https://goreportcard.com/badge/github.com/yourname/deferargs)](https://goreportcard.com/report/github.com/yourname/deferargs) --\u003e\n\n`deferargs` is a static analysis tool to detect `defer` statements that call a function with variable arguments.  \nSince arguments in `defer` calls are evaluated immediately, passing variables may lead to unexpected behavior if their values change afterward.\n\n## Problem\n\nIn Go, the arguments to a `defer` call are evaluated **at the point of the `defer` statement**, not when the deferred function is executed.  \nThis can cause subtle bugs when passing a variable whose value is expected to change later.\n\nFor example:\n\n```go\nfunc fn() (err error) {\n    defer dump(err) // ❗️ evaluated now (likely nil), not at the end\n    err = errors.New(\"something failed\")\n    return\n}\n```\n\nThe call to `dump(err)` will receive `nil`, because `err` is evaluated at the point of the `defer`, before `err` is set.\n\n## Recommendation\n\nTo avoid this issue, wrap the call in a closure:\n\n```go\nfunc f() (err error) {\n    defer func() {\n        dump(err) // ✅ evaluated at the time of execution\n    }()\n    err = errors.New(\"something failed\")\n    return\n}\n```\n\n## Detected Code\n\nThis tool reports `defer` statements where:\n\n- The deferred function is **not** an anonymous function (`func() { ... }`)\n- At least one argument is a **variable reference** (`x`, `obj.Field`, etc.)\n\n### Reported:\n\n```go\ndefer fn(err)\ndefer close(ch)\ndefer logf(\"fail: %v\", err)\n```\n\n### Not Reported:\n\n```go\ndefer fn()                           // no arguments\ndefer fn(errors.New(\"boom\"))        // function call\ndefer fn(nil)                       // literal\ndefer func() { fn(err) }()          // wrapped in closure\n```\n\n## Installation\n\n```bash\ngo install github.com/tkdn/deferargs/cmd/deferargs@latest\n```\n\n## Usage\n\n### As `go vet` plugin (with [staticcheck.io](https://staticcheck.io/)):\n\n```bash\ngo vet -vettool=$(which deferargs) ./...\n```\n\n### Standalone\n\n```bash\ndeferargs ./...\n```\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftkdn%2Fdeferargs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftkdn%2Fdeferargs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftkdn%2Fdeferargs/lists"}