Repository navigation
uncheckedflushreturn: flag discarded errors in defer ...Flush() - #49908
Conversation
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
defer ...Flush()
Triage ResultCategory: refactor | Risk: low | Score: 38/100 (impact 12, urgency 10, quality 16) Recommended action: defer Draft PR, CI pending, small lint-focused change (2 files, 31+/1-) flagging discarded defer Flush() errors. Low urgency, safe to batch with similar lint PRs later.
|
|
✅ Design Decision Gate 🏗️ completed the design decision gate check. No ADR enforcement needed: PR #49908 does not have the implementation label and has only 31 new lines of code in business logic directories (threshold: 100). |
|
🧠 Matt Pocock Skills Reviewer failed during the skills-based review. |
|
|
|
✅ Test Quality Sentinel completed test quality analysis. |
There was a problem hiding this comment.
Pull request overview
Extends uncheckedflushreturn to detect discarded errors from deferred Flush() calls.
Changes:
- Adds
ast.DeferStmtanalysis using existing flush validation/reporting. - Adds tests for diagnostics and
nolintsuppression.
Show a summary per file
| File | Description |
|---|---|
pkg/linters/uncheckedflushreturn/uncheckedflushreturn.go |
Detects unchecked deferred flush calls. |
pkg/linters/uncheckedflushreturn/testdata/src/uncheckedflushreturn/uncheckedflushreturn.go |
Covers flagged and suppressed deferred calls. |
Review details
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 2/2 changed files
- Comments generated: 0
- Review effort level: Balanced
There was a problem hiding this comment.
The implementation is correct and well-structured. DeferStmt is properly added to the node filter, checkDiscardedFlushDefer follows the established pattern, nolint suppression resolves correctly via call.Pos(), and testdata covers both the flagged and suppressed forms.
🧵 Reviewed using Impeccable skills by Impeccable Skills Reviewer · sonnet46 · 17 AIC · ⌖ 7.36 AIC · ⊞ 5.4K
🧪 Test Quality Sentinel Report✅ Test Quality Score: N/A — No Test Changes
The testdata file is an input corpus for the Go analysis framework ( Verdict
|
|
/matt |
|
🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅ |
There was a problem hiding this comment.
Skills-Based Review 🧠
Applied /tdd and /codebase-design — changes are solid, approving.
📋 Key Themes & Highlights
Key Themes
- Consistent pattern reuse:
DeferStmthandling mirrors the existingExprStmt/AssignStmtpattern faithfully — filename-skip guard in the switch case, logic delegated to a dedicatedcheckDiscardedFlushDeferhelper. - Defensive nil check:
stmt.Call == nilguard incheckDiscardedFlushDeferis technically unreachable for well-formed AST but follows safe-coding convention. - Test coverage: both
deferBad(flagged) anddeferSuppressed(nolint suppression) cases are present, mirroring the coverage shape of the existing tests.
Positive Highlights
- ✅ Minimal, surgical diff — only the missing code path is added
- ✅ New function is self-contained and easy to reason about
- ✅ Testdata covers both the positive (diagnostic fired) and suppression (nolint respected) cases
- ✅ PR description is clear and accurately describes what was changed
Minor Observation (non-blocking)
The defer x.Flush() pattern is genuinely hard to fix at the call site. The idiomatic workaround is a named-return closure:
defer func() { err = bw.Flush() }()Consider adding a suggested fix hint to the diagnostic message so the linter is immediately actionable. Not a blocker.
🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · sonnet46 · 19 AIC · ⌖ 14.4 AIC · ⊞ 7.1K
Comment /matt to run again
|
🎉 This pull request is included in a new release. Release: |
uncheckedflushreturnonly inspectedExprStmtandAssignStmt, sodefer w.Flush()(the most common dropped-flush-error pattern) was never visited or reported. This change extends analyzer coverage to deferred calls and adds focused testdata for deferred flagged and suppressed forms.Analyzer scope expansion
*ast.DeferStmtto the inspector node filter.DeferStmthandling inrun()and wired it to existing flush/error detection and reporting flow.Deferred flush check
checkDiscardedFlushDefer(...)to inspectstmt.Calland report whenFlush()returns an error that is discarded.Testdata coverage
deferBad()case expecting the standard unchecked-flush diagnostic.deferSuppressed()case validating//nolint:uncheckedflushreturnsuppression for deferred form.defer w.Flush()(the most common discard pattern) is never flagged #49902