Repository navigation
Add blank-assigned cleanup error linter - #75922
Conversation
Co-authored-by: gh-aw-bot <[email protected]>
|
✅ 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.
|
|
✅ PR Code Quality Reviewer completed the code quality review.
|
|
✅ 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.
|
|
❌ Design Decision Gate 🏗️ failed to deliver outputs during design decision gate check.
|
|
🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅
|
|
✅ Ponytail Reviewer completed successfully!
|
|
Warning The 🏗️ Design Decision Gate — ADR RequiredThis PR makes significant changes to core business logic (211 new lines under 📄 Draft ADR committed: Decision captured in the draft: add a standalone
📋 What to do next
Once an ADR is linked in the PR body, this gate will re-run and verify the implementation matches the decision. ❓ Why ADRs Matter
ADRs create a searchable, permanent record of why the codebase looks the way it does. Future contributors (and your future self) will thank you. 📋 Michael Nygard ADR Format ReferenceAn ADR must contain these four sections to be considered complete:
All ADRs are stored in
|
Comment MemoryPeek at saved memory (pr-code-quality-reviewer)Note This comment is managed by comment memory.Expand the saved memory block to view or edit the persistent context for this thread.
|
There was a problem hiding this comment.
I found two merge-blocking compatibility/correctness concerns in the changed analyzer: deferred _ = os.Remove* assignments are no longer covered, and existing nolint:osremoveuncheckedcleanup suppressions stop applying after the diagnostic moves. Please address these regressions or provide an explicit, tested migration rationale.
🔎 Code quality review by PR Code Quality Reviewer · copilot · gpt50 · ~3 AIC · ⌖ ~1 AIC · ⊞ 1.6K
Comment /review to run again
|
|
||
| position := pass.Fset.PositionFor(call.Pos(), false) | ||
| if filecheck.ShouldSkipFilename(position.Filename, generatedFiles) || | ||
| nolint.HasDirectiveForLinter(position, nolintIndex, "blankassignedcleanuperror") { |
There was a problem hiding this comment.
This changes the suppression key for existing _ = os.Remove* findings from osremoveuncheckedcleanup to blankassignedcleanuperror. Existing source directives using the old key will no longer suppress the diagnostic once this analyzer is enforced, creating a silent migration break. Please preserve the old key for this form or add an explicit migration path and test.
There was a problem hiding this comment.
Added compatibility handling so existing //nolint:osremoveuncheckedcleanup directives still suppress _ = os.Remove/RemoveAll findings. Covered by the legacy-directive fixture in 5e414205.
There was a problem hiding this comment.
Preserved the legacy osremoveuncheckedcleanup suppression key and added fixture coverage for both os.Remove and os.RemoveAll. Fixed in d5893a05b6.
| return | ||
| } | ||
| for _, deferred := range deferredClosures { | ||
| if assign.Pos() >= deferred.start && assign.End() <= deferred.end { |
There was a problem hiding this comment.
This exemption creates a coverage regression: the old osremoveuncheckedcleanup analyzer reported _ = os.Remove/RemoveAll even inside deferred closures, but that assignment logic was removed from it. These common cleanup errors are now silently lint-free. Please either retain coverage for deferred assignments or document and test the intentional behavior with a stronger rationale.
There was a problem hiding this comment.
Removed the deferred-closure exemption and added fixtures asserting that discarded Remove and RemoveAll errors in deferred closures are reported. This is included in 5e414205.
There was a problem hiding this comment.
The analyzer now reports blank-assigned os.Remove/os.RemoveAll errors inside deferred cleanup closures; fixtures cover this behavior. Fixed in d5893a05b6.
There was a problem hiding this comment.
What this change does: Adds a dedicated analyzer for blank-assigned errors from selected os cleanup functions. It moves assignment handling out of osremoveuncheckedcleanup and updates the linter registry, documentation, and fixtures.
Should fix:
-
Copying guaranteed single elements (
pkg/linters/blankassignedcleanuperror/blankassignedcleanuperror.go:L39-44)- What this is: The guards require exactly one left- and right-hand expression.
- Problem: Two loops copy those single elements into variables, adding four lines and hiding the invariant.
- Fix: Use direct indexing with the existing
uncheckedsliceindexsuppression used by nearby linters. - If we skip it: This small matcher remains harder to read than two direct assignments.
Verdict: fix 1 first.
Lean: -4 lines possible.
Generated by ✂️ Ponytail Reviewer for #75922 · codex · routed: gpt56 max · ~3 AIC · ⌖ ~1 AIC · ⊞ 118
Comment /ponytail to run again
| return | ||
| } | ||
| var lhs, rhs ast.Expr | ||
| for _, expr := range assign.Lhs { |
There was a problem hiding this comment.
What this is: The checks on lines 35-36 guarantee exactly one left- and right-hand expression. Problem: The two for loops on lines 39-44 only copy those single elements, adding four lines and obscuring that invariant. Fix: Use lhs := assign.Lhs[0] and rhs := assign.Rhs[0] directly, with the uncheckedsliceindex suppression used by nearby linters. If we skip it: This small matcher stays harder to read than the equivalent two direct assignments.
There was a problem hiding this comment.
Replaced the loops with direct Lhs[0] and Rhs[0] access, retaining the existing one-element guards and adding the uncheckedsliceindex suppressions. Included in 5e414205.
There was a problem hiding this comment.
The analyzer now iterates corresponding LHS/RHS pairs rather than copying single elements; indexed access is guarded by the matching-length check. Fixed in d5893a05b6.
There was a problem hiding this comment.
🟡 Changes recommended
The single-assignment guard leaves discarded filesystem errors unreported in valid parallel assignments with mixed blank and non-blank destinations.
1 open issue
1 file not reviewed
pkg/linters/blankassignedcleanuperror/testdata/src/blankassignedcleanuperror/generated.go: Generated file
What changed in this PR
Adds blankassignedcleanuperror to gh-aw’s custom Go analyzers to detect filesystem errors discarded through _ assignments, addressing #75458.
Changes:
- Detects discarded errors from four
osfunctions, excluding generated files and deferred closures. - Moves assignment checks out of
osremoveuncheckedcleanupto avoid duplicate diagnostics. - Adds fixtures and synchronizes the analyzer registry, documentation, and enforcement metadata.
| File | Description |
|---|---|
pkg/linters/spec_test.go |
Adds the analyzer to documented API checks. |
pkg/linters/registry.go |
Registers the new analyzer. |
pkg/linters/README.md |
Documents the new analyzer and revised cleanup-check scope. |
pkg/linters/osremoveuncheckedcleanup/testdata/src/osremoveuncheckedcleanup/osremoveuncheckedcleanup.go |
Removes assignment cases transferred to the new analyzer. |
pkg/linters/osremoveuncheckedcleanup/osremoveuncheckedcleanup.go |
Limits checks to expression and go statements. |
pkg/linters/doc.go |
Updates the analyzer catalog and count. |
pkg/linters/doc_sync_test.go |
Records deferred CI enforcement. |
pkg/linters/blankassignedcleanuperror/testdata/src/blankassignedcleanuperror/other/cleanup.go |
Supplies unrelated methods for exclusion tests. |
pkg/linters/blankassignedcleanuperror/testdata/src/blankassignedcleanuperror/generated.go |
Tests generated-file exclusion. |
pkg/linters/blankassignedcleanuperror/testdata/src/blankassignedcleanuperror/blankassignedcleanuperror.go |
Covers detection, exclusions, and suppression. |
pkg/linters/blankassignedcleanuperror/blankassignedcleanuperror.go |
Implements blank-assigned filesystem-error detection. |
pkg/linters/blankassignedcleanuperror/blankassignedcleanuperror_test.go |
Runs the analyzer’s fixture tests. |
Review effort: Balanced (auto)
| if !ok || len(assign.Lhs) != 1 || len(assign.Rhs) != 1 { | ||
| return |
There was a problem hiding this comment.
Fixed in d5893a05b6: the analyzer now checks corresponding LHS/RHS pairs when their counts match, with fixtures for _ in both destination positions.
There was a problem hiding this comment.
Skills-Based Review 🧠
Applied /tdd and /grill-with-docs (change type: new feature). Requesting changes because the deferred-closure exemption silently removes coverage for _ = os.Remove(...) that the base analyzer reported.
📋 Key Themes & Highlights
Key Themes
- Undisclosed coverage drop: The removed
AssignStmtbranch inosremoveuncheckedcleanuphad no deferred-closure check. Any_ = os.X(...)inside adefer func(){...}()is now reported by neither analyzer. The PR body describes the move as dedup-only. - Docs do not describe the exemption: The README and
doc.godescriptions omit the deferred-closure scope.
Verification
go test -count=1 ./pkg/linters/...passes, includingblankassignedcleanuperrorandosremoveuncheckedcleanup.- A temporary probe on this branch confirmed that the new analyzer is silent on
_ = os.WriteFileand_ = os.Removeinside deferred closures, and the updatedosremoveuncheckedcleanupis silent on the same form. The probe was removed afterward. - Testdata pins the deferred exemption only for direct
func(){...}literals, not nested func literals.
Positive Highlights
- ✅ Table-driven testdata covers generated files,
nolint, theClose()boundary, and the parenthesised-call form. - ✅ README,
doc.go,spec_test.go, anddoc_sync_test.goare updated together, and the new analyzer is kept out of enforcement until remediation.
@copilot please address the review comments above.
🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · copilot · routed: haiku55 xhigh · ~7 AIC · ⌖ ~2 AIC · ⊞ 5.4K
Comment /matt to run again
| return | ||
| } | ||
| for _, deferred := range deferredClosures { | ||
| if assign.Pos() >= deferred.start && assign.End() <= deferred.end { |
There was a problem hiding this comment.
[/tdd] The deferred-closure exemption is broader than the rule it sits under: any _ = os.X(...) inside any deferred func literal body (including nested func literals) is skipped silently.
The removed AssignStmt branch in osremoveuncheckedcleanup had no deferred check, so base reported _ = os.Remove(tmp) inside a deferred closure. This PR removes that branch, and the new analyzer exempts the same form, so it is now reported by neither analyzer. I confirmed this with a probe on this branch (removed afterward). The PR body presents the move as dedup-only, so this coverage drop is not disclosed.
💡 Suggested fix
Choose one and make it explicit: keep the exemption and document it (a one-line comment here, plus README and doc.go), or drop it so the _ = rule is consistent between top-level and deferred code. If you keep it, add a nested func-literal case to the testdata so the scope is pinned.
@copilot please address this.
There was a problem hiding this comment.
Removed the deferred-closure exemption entirely, so nested or other function literals are no longer silently skipped. Covered by the deferred cleanup fixtures in 5e414205.
There was a problem hiding this comment.
There is no deferred-closure exemption now: blank-assigned cleanup calls are analyzed inside deferred and nested function-literal bodies. The deferred fixture covers reporting. Fixed in d5893a05b6.
| - `appendbytestring` — reports `append(b, []byte(s)...)` calls where `b` is `[]byte` and `s` is a string, which can be simplified to `append(b, s...)`. | ||
| - `appendoneelement` — reports `append(s, []T{x}...)` calls where a single-element slice literal is spread and can be simplified to `append(s, x)`. | ||
| - `blankassigncomma` — reports assignment statements where every result is discarded via 2 or more blank identifiers (e.g. `_, _ = f()`), which may indicate unintended result ignoring. | ||
| - `blankassignedcleanuperror` — reports discarded errors from `os.Remove`, `os.RemoveAll`, `os.WriteFile`, and `os.MkdirAll` when assigned to `_`. |
There was a problem hiding this comment.
[/grill-with-docs] This description does not mention the deferred-closure exemption, so readers cannot tell why _ = os.Remove(...) inside a defer func(){...}() is silent while the same statement elsewhere is reported. Consider adding a clause such as "outside deferred cleanup closures" here and in the matching doc.go and table rows.
@copilot please address this.
There was a problem hiding this comment.
Updated the analyzer description, README entries, and doc.go to say discarded cleanup errors are reported in deferred closures. Included in 5e414205.
There was a problem hiding this comment.
The documentation already states that findings include deferred closures, matching the analyzer behavior; no exemption is applied. Kept in sync in d5893a05b6.
|
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: f1ab6fb
|
Starting the requested work: merge the latest Sous-chef requested-head: f1ab6fb |
…lank-assigned-cleanup-error-6453f9349 Co-authored-by: gh-aw-bot <[email protected]>
Co-authored-by: gh-aw-bot <[email protected]>
|
@copilot resolve the merge conflicts on this branch. |
…lank-assigned-cleanup-error-6453f9349 # Conflicts: # pkg/linters/doc_sync_test.go Co-authored-by: pelikhan <[email protected]>
Co-authored-by: pelikhan <[email protected]>
Completed the analyzer fixes in
Resolved the |
|
🎉 This pull request is included in a new release. Release: |

Adds a linter for cleanup errors discarded by assigning them to
_. It coversos.Remove,os.RemoveAll,os.WriteFile, andos.MkdirAll.Close()checks to the existing analyzer.linters.All()and synchronizes documentation and linter metadata. Existing Remove/RemoveAll assignment checks are moved to the new analyzer to prevent duplicate diagnostics.