Repository navigation
Add unchecked os cleanup analyzer - #75765
Conversation
Co-authored-by: gh-aw-bot <[email protected]>
|
✅ Ponytail Reviewer completed successfully!
|
|
❌ Design Decision Gate 🏗️ failed to deliver outputs during design decision gate check.
|
|
✅ Test Quality Sentinel completed test quality analysis. Test Quality SentinelOutcome: The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible. Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.
|
|
🔎 PR Code Quality Reviewer is reviewing code quality for this pull request... |
|
✅ PR Specification Reviewer completed successfully! PR Specification ReviewerOutcome: The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible. Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.
|
|
🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅
|
There was a problem hiding this comment.
What this change does: Adds a type-aware analyzer for discarded errors from os.Remove and os.RemoveAll. It registers and documents the analyzer and adds analysis fixtures for handled calls, aliases, deferred calls, and suppressions.
Should fix:
-
One-element slices are traversed with loops (
pkg/linters/osremoveuncheckedcleanup/osremoveuncheckedcleanup.go:45-59)- What this is: The length checks guarantee exactly one left- and right-hand expression.
- Problem: The two loops, temporary expressions, and break statements add control flow that cannot do more than one iteration.
- Fix: Index
stmt.Lhs[0]andstmt.Rhs[0]directly, using the existing(nolint/redacted):uncheckedsliceindexconvention for checked indexes. - If we skip it: This matcher is harder to read and maintain than the equivalent direct extraction.
-
A known package name is normalized through
path.Base(pkg/linters/osremoveuncheckedcleanup/osremoveuncheckedcleanup.go:80)- What this is: The preceding condition has already narrowed
pkgPathto the literalos. - Problem: Calling
path.Baseand importingpathadd machinery without changing the result. - Fix: Report
os.%sdirectly and remove the import. - If we skip it: A fixed string continues to take an indirect path through a general-purpose helper.
- What this is: The preceding condition has already narrowed
Not checked: Correctness, security, performance, and generated or lock-file changes were outside this complexity-only review.
Verdict: fix 1 and 2 first.
Lean: -9 lines possible.
Generated by ✂️ Ponytail Reviewer for #75765 · codex · routed: gpt56 max · ~4 AIC · ⌖ ~1 AIC · ⊞ 118
Comment /ponytail to run again
| return | ||
| } | ||
| var lhs ast.Expr | ||
| for _, expr := range stmt.Lhs { |
There was a problem hiding this comment.
Ponytail: stmt.Lhs and stmt.Rhs are proven to have one element at lines 42-43, so these one-iteration loops and temporary variables add needless control flow; use [0] with the repository standard (nolint/redacted):uncheckedsliceindex guard to remove it.
There was a problem hiding this comment.
Replaced the single-element loops with bounds-guarded direct indexing in 517ef28.
| return | ||
| } | ||
|
|
||
| pass.ReportRangef(call, "error return from %s.%s is discarded; cleanup failures may be silently ignored", path.Base(pkgPath), funcName) |
There was a problem hiding this comment.
Ponytail: pkgPath was just narrowed to the literal "os" on line 68, so path.Base(pkgPath) and the path import add no behavior; report "os.%s" directly and delete the import.
There was a problem hiding this comment.
Removed the redundant path import and report os.%s directly in 517ef28.
|
Warning The 🏗️ Design Decision Gate — ADR RequiredThis PR makes significant changes to core business logic (>100 new lines) but does not have a linked Architecture Decision Record (ADR). Evidence: the gate summary records 📄 Draft ADR committed:
📋 What to do next
Once an ADR is linked in this PR body, this gate will re-run and verify that the implementation matches the decision. ❓ Why ADRs MatterADRs create a searchable, permanent record of why the codebase looks the way it does. They make significant design trade-offs reviewable for future contributors. 📋 Michael Nygard ADR Format ReferenceAn ADR must contain these four sections to be considered complete:
All ADRs are stored in
|
There was a problem hiding this comment.
🟡 Changes recommended
The linter misses discarded cleanup errors in multi-value assignments and assignments to parenthesized blank targets.
2 open issues
What changed in this PR
Adds a type-aware cleanup-error analyzer to gh-aw’s custom Go linters, while leaving CI enforcement disabled pending remediation of existing findings.
Changes:
- Detects bare and blank-assigned
os.Removeandos.RemoveAllcalls using resolved package information. - Adds fixtures for discarded, handled, returned, deferred, and suppressed errors, plus unrelated same-named methods.
- Registers the analyzer and updates documentation and consistency tests.
| File | Description |
|---|---|
pkg/linters/spec_test.go |
Adds the analyzer to documentation specification checks. |
pkg/linters/registry.go |
Registers the analyzer. |
pkg/linters/README.md |
Documents the rule and package. |
pkg/linters/osremoveuncheckedcleanup/testdata/src/osremoveuncheckedcleanup/other/cleanup.go |
Supplies unrelated methods for false-positive checks. |
pkg/linters/osremoveuncheckedcleanup/testdata/src/osremoveuncheckedcleanup/osremoveuncheckedcleanup.go |
Adds diagnostic and exemption fixtures. |
pkg/linters/osremoveuncheckedcleanup/osremoveuncheckedcleanup.go |
Implements cleanup-error detection and suppression handling. |
pkg/linters/osremoveuncheckedcleanup/osremoveuncheckedcleanup_test.go |
Runs the analyzer’s fixture tests. |
pkg/linters/doc.go |
Updates the analyzer catalog and count. |
pkg/linters/doc_sync_test.go |
Records the deferred CI enforcement status. |
Review effort: Balanced (auto)
| if len(stmt.Lhs) != 1 || len(stmt.Rhs) != 1 { | ||
| return |
| lhs = expr | ||
| break | ||
| } | ||
| blank, ok := lhs.(*ast.Ident) |
There was a problem hiding this comment.
Skills-Based Review 🧠
Applied /tdd, /grill-with-docs, and /codebase-design. No blocking issues. Two small follow-ups are left as inline comments.
📋 Verification and key themes
Verification
go test ./pkg/linters/osremoveuncheckedcleanup/passes.go test ./pkg/linters/passes, including the doc-sync and spec tests.go vetis clean.- Running the new analyzer over
./pkg/...and./cmd/...reports 24 real findings. This supports thenotYetEnforcedrationale indoc_sync_test.go, which says remediation is needed before CI enforcement. cgo.ymlpasses explicitLINTER_FLAGSlists that exclude the new analyzer, so it is not enforced in CI, as intended.
Key themes
- Documentation count drift: the
spec_test.goprose comment still says 88. The table anddocumentedAnalyzers()list 89. The sync test passes because it compares lists, not prose. - Readability: the single-element
for ... breakloops inanalyzeDiscardedCleanupcan bestmt.Lhs[0]andstmt.Rhs[0].
Positive highlights
- ✅ Test data covers aliased imports, parenthesised calls,
_ =, handled, returned, deferred, same-named methods on other types, andnolintsuppression. - ✅ Method-name collisions are correctly rejected through
*types.Funcpackage matching. - ✅ Registration in
registry.go,doc.go, and the README is consistent with the siblingosexitinlibrarypattern.
Not covered
go os.Remove(path)(aGoStmt) has no testdata case. The currentExprStmtfilter ignores it, which matches thedeferexemption, so a case would document the intent.
@copilot please address the review comments above.
🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · copilot · routed: haiku55 xhigh · ~9 AIC · ⌖ ~2 AIC · ⊞ 5.4K
Comment /matt to run again
| return | ||
| } | ||
| var lhs ast.Expr | ||
| for _, expr := range stmt.Lhs { |
There was a problem hiding this comment.
[/codebase-design] The for _, expr := range stmt.Lhs { lhs = expr; break } loop is an indirect way to take the only element of a slice. The len(...) != 1 guard above already ensures there is exactly one element, so stmt.Lhs[0] says the same thing more directly. The same applies to the stmt.Rhs loop at lines 55–58.
@copilot please address this.
There was a problem hiding this comment.
Replaced the single-element loops with bounds-guarded direct indexing in 517ef28.
|
|
||
| // documentedAnalyzers returns the analyzer subpackages documented in the README | ||
| // "Public API > Subpackages" table. The README documents 87 analyzer | ||
| // "Public API > Subpackages" table. The README documents 88 analyzer |
There was a problem hiding this comment.
[/grill-with-docs] Stale count: this comment says the README documents 88 analyzer subpackages, but the README Subpackages table and documentedAnalyzers() both list 89 analyzers (the internal helper row is the only exclusion). This PR moves the figure from 87 to 88 while the list grows to 89, so update it to 89 to match what the sync test enforces.
@copilot please address this.
There was a problem hiding this comment.
Updated the documented analyzer count to 89 in 517ef28.
|
Copilot assignment requested for the following outstanding work:
Once you start work, post this work summary as a PR comment without the leading Copilot mention, including the Sous-chef head, work, and state lines below, to record that the assignment is running. Apply the necessary fixes on this PR's existing branch, reply to each listed review thread and resolve it when addressed. Ignore feedback already answered or resolved; stop when only human review or CI remains. Do not merge or trigger CI. Sous-chef requested-head: 0a7f491
|
Sous-chef requested-head: 0a7f491 |
…s-remove-unchecked-cleanup-analyzer Co-authored-by: gh-aw-bot <[email protected]>
Co-authored-by: gh-aw-bot <[email protected]>
|
🎉 This pull request is included in a new release. Release: |

Bare
os.Removeandos.RemoveAllcalls can silently discard cleanup errors. This adds a type-aware analyzer that reports those calls while allowing handled or returned errors, deferred calls, and matchingnolintdirectives._ =assignments. Register and document the analyzer without enabling CI enforcement.