Repository navigation
Conversation
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
|
✅ PR Code Quality Reviewer completed the code quality review. PR Code Quality ReviewerOutcome: The agent completed and reported one or more actions. The no-op output is a completion signal, not a claim that no action was taken. Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.
|
This comment has been minimized.
This comment has been minimized.
|
✅ 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 Specification Reviewer completed successfully! PR Specification ReviewerOutcome: The agent completed and reported one or more actions. The no-op output is a completion signal, not a claim that no action was taken. Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.
|
|
✅ Ponytail Reviewer completed successfully!
|
|
🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅
|
There was a problem hiding this comment.
What this change does: Adds an analyzer that finds map-copy loops and suggests maps.Copy when it is available. It registers the analyzer as advisory.
One simplification is noted inline. Verdict: Ship.
Lean: -11 lines possible.
Generated by ✂️ Ponytail Reviewer for #78958 · codex · routed: gpt61 medium · ~6 AIC · ⌖ ~1 AIC · ⊞ 185
Comment /ponytail to run again
| if len(rangeStmt.Body.List) != 1 { | ||
| return nil, false | ||
| } | ||
| var bodyStmt ast.Stmt |
There was a problem hiding this comment.
Should fix: The body, left side, and right side are each checked to have exactly one item, so use [0] directly in all three places; the three loops add 11 lines without handling any additional case.
There was a problem hiding this comment.
Replaced the slice traversals with guarded [0] accesses; the exact-length checks are documented for the custom linter. Included in 0dd7ca8.
Comment MemoryPeek at saved memory (spec-review-history)History |
🏗️ 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). 📄 Draft ADR committed:
📋 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. 🔎 Evidence used
📋 Michael Nygard ADR format referenceAn ADR must contain Context, Decision, Alternatives Considered, and Consequences to be considered complete. ADRs live in References: §44257509648
|
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.
Review verdict
Please address the unsafe suggested-fix transformations before merging. The current analyzer can remove observable assignments to outer range variables and can generate behavior-changing or uncompilable replacements for non-stable destination expressions.
See the inline comments for targeted fixes and regression coverage.
🔎 Code quality review by PR Code Quality Reviewer · copilot · gpt50 · ~3 AIC · ⌖ ~1 AIC · ⊞ 1.5K
Comment /review to run again
| bodyStmt = stmt | ||
| } | ||
| assignStmt, ok := bodyStmt.(*ast.AssignStmt) | ||
| if !ok || assignStmt.Tok != token.ASSIGN || len(assignStmt.Lhs) != 1 || len(assignStmt.Rhs) != 1 { |
There was a problem hiding this comment.
The suggested rewrite is also offered for for k, v = range src, but this form assigns the final key and value into outer variables; replacing the loop with maps.Copy removes those assignments and changes observable behavior after the loop.
💡 Preserve outer-variable semantics
Restrict this transformation to rangeStmt.Tok == token.DEFINE, or otherwise prove the range variables are not used after the loop, and add a regression test for the assignment form.
There was a problem hiding this comment.
Assignment-form ranges are now excluded, and the fixture/golden preserve the = loop unchanged. Included in 0dd7ca8.
| TextEdits: []analysis.TextEdit{{ | ||
| Pos: rangeStmt.Pos(), | ||
| End: rangeStmt.End(), | ||
| NewText: []byte("maps.Copy(" + dstText + ", " + srcText + ")"), |
There was a problem hiding this comment.
This fix is unsafe for destination expressions that are not stable map references, such as pick()[k] = v or groups[k][k] = v: it moves the destination evaluation outside the loop, changing call counts or producing code that references the loop variable after its scope (and can fail to compile).
💡 Limit suggested fixes to stable destinations
Only offer the rewrite when the indexed map expression is an identifier or a side-effect-free selector chain that does not reference the range variables; otherwise keep the diagnostic but omit the suggested fix. Add regression cases for a function-call destination and a destination indexed by k.
There was a problem hiding this comment.
Suggested fixes now require stable operands and reject destination references to range variables; nested-index and call cases cover the exclusions. Included in 0dd7ca8.
Comment MemoryPeek at saved memory (review-history)History |
There was a problem hiding this comment.
Skills-Based Review 🧠
Applied /diagnosing-bugs and /tdd. Requesting changes: the suggested fix for the for k, v = range form produces code that does not compile, and the golden test enshrines that output.
📋 Key Themes & Highlights
Key Themes
- Broken autofix for
=loops:go vetrejects the golden file withdeclared and not used: k. The test passes only because the golden was generated from the bad rewrite. - Destination evaluated once: a call in the destination (for example
getMap()[k] = v) would run once per entry in the loop but only once aftermaps.Copy. The fix should be limited to plain identifiers and selectors.
Positive Highlights
- ✅ Clear, bounded matching rules: self-copies, blank variables, compound assignment, extra statements, and
nolintare all skipped. - ✅ Shadowed
mapspackage and comment-bearing loops are handled conservatively. - ✅ Advisory rollout via
notYetEnforcedis consistent with the existing linters.
Verification
go test ./pkg/linters/mapcopyloop/...passes, but only because the golden encodes the broken output.go test ./pkg/linters/passes.
@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 · ⊞ 6.6K
Comment /matt to run again
| End: rangeStmt.End(), | ||
| Message: "range-copy loop can be replaced with maps.Copy(" + dstText + ", " + srcText + ")", | ||
| } | ||
| if mapsPackageVisible(pass.Pkg, rangeStmt.Pos()) && |
There was a problem hiding this comment.
[/diagnosing-bugs] The suggested fix ignores the range form. For for k, v = range src (rangeStmt.Tok == token.ASSIGN) the rewrite leaves the outer k and v unused, so the fixed file does not compile. It also drops their final values after the loop, which changes behavior.
Offer the fix only for := loops and report the = form without a fix.
💡 Suggested guard
if rangeStmt.Tok == token.DEFINE &&
mapsPackageVisible(pass.Pkg, rangeStmt.Pos()) &&
!astutil.HasOverlappingComment(pass.Files, rangeStmt.Pos(), rangeStmt.End()) {@copilot please address this.
There was a problem hiding this comment.
The analyzer now skips = range loops; their fixture remains unchanged. Included in 0dd7ca8.
| return | ||
| } | ||
| srcText := astutil.NodeText(pass.Fset, rangeStmt.X) | ||
| dstText := astutil.NodeText(pass.Fset, indexExpr.X) |
There was a problem hiding this comment.
[/diagnosing-bugs] dstText is evaluated once per iteration in the original loop but only once in maps.Copy. If the destination contains a call, such as getMap()[k] = v, the fix changes how often getMap runs. Restrict the fix to destinations made of identifiers and selectors, and add a call-destination case that expects a diagnostic with no suggested fix.
@copilot please address this.
There was a problem hiding this comment.
Function-call destinations and sources now retain diagnostics without suggested fixes; regression fixtures cover both. Included in 0dd7ca8.
|
|
||
| var k string | ||
| var v int | ||
| for k, v = range src { // want `range-copy loop can be replaced with maps.Copy\(dst, src\)` |
There was a problem hiding this comment.
[/tdd] This = case should keep its diagnostic but expect no suggested fix. The golden output for this loop must remain the original loop, not maps.Copy.
@copilot please address this.
There was a problem hiding this comment.
The assignment-form fixture now expects no suggested fix and remains unchanged in the golden output. Included in 0dd7ca8.
|
|
||
| maps.Copy(dst, src) | ||
|
|
||
| var k string |
There was a problem hiding this comment.
[/tdd] This golden output is not valid Go: go vet reports declared and not used: k. The test passes only because the golden captured the broken rewrite. Regenerate the golden after the guard fix so the = loop stays unchanged.
@copilot please address this.
There was a problem hiding this comment.
The golden preserves the assignment-form loop, and the test type-checks the rewritten source. Included in 0dd7ca8.
There was a problem hiding this comment.
🟡 Changes recommended
The suggested maps.Copy rewrites can change program behavior or produce invalid code, while current fixtures never exercise the fix path.
3 open issues
What changed in this PR
Adds mapcopyloop, a readability analyzer for gh-aw’s custom Go linter suite that recommends maps.Copy for map-copy loops.
Changes:
- Implements loop matching, suppression handling, and conditional suggested fixes.
- Adds diagnostic fixtures and golden replacement expectations.
- Registers and documents the analyzer while deferring CI enforcement until existing findings are addressed.
| File | Description |
|---|---|
pkg/linters/spec_test.go |
Adds the analyzer to documentation checks. |
pkg/linters/registry.go |
Registers the analyzer. |
pkg/linters/README.md |
Documents the rule and subpackage. |
pkg/linters/mapcopyloop/testdata/src/mapcopyloopnoimport/mapcopyloopnoimport.go |
Adds a diagnostic case without importing maps. |
pkg/linters/mapcopyloop/testdata/src/mapcopyloop/mapcopyloop.go.golden |
Records expected replacement output. |
pkg/linters/mapcopyloop/testdata/src/mapcopyloop/mapcopyloop.go |
Covers matching, exclusions, and suppression. |
pkg/linters/mapcopyloop/mapcopyloop.go |
Implements detection and suggested fixes. |
pkg/linters/mapcopyloop/mapcopyloop_test.go |
Runs diagnostic and suggested-fix checks. |
pkg/linters/doc.go |
Adds the analyzer to package documentation. |
pkg/linters/doc_sync_test.go |
Records deferred CI enforcement. |
Review effort: Balanced (adaptive)
| dstType := pass.TypesInfo.TypeOf(indexExpr.X) | ||
| if !isMap(dstType) || !types.Identical(dstType, srcType) { | ||
| return | ||
| } |
There was a problem hiding this comment.
Fixes now require side-effect-free identifier/selector operands and a destination independent of range variables; nested indexing and calls are covered. Included in 0dd7ca8.
| func rangeObjects(pass *analysis.Pass, rangeStmt *ast.RangeStmt) (types.Object, types.Object, bool) { | ||
| keyIdent, keyOK := rangeStmt.Key.(*ast.Ident) | ||
| valueIdent, valueOK := rangeStmt.Value.(*ast.Ident) | ||
| if !keyOK || !valueOK || keyIdent.Name == "_" || valueIdent.Name == "_" { |
There was a problem hiding this comment.
The analyzer now skips assignment-form ranges, keeping their outer-variable behavior and source intact. Included in 0dd7ca8.
| func TestAnalyzer(t *testing.T) { | ||
| t.Parallel() | ||
| testdata := analysistest.TestData() | ||
| analysistest.RunWithSuggestedFixes(t, testdata, mapcopyloop.Analyzer, "mapcopyloop") |
There was a problem hiding this comment.
Added a comment-free positive fixture that emits a fix, and a test type-checks the rewritten golden file. Included in 0dd7ca8.
|
🍳 A little prep to help this PR along! Copilot assignment requested for the following outstanding work:
Keeping the changes focused; human review and CI get the final taste test. No merging or CI triggering. Structured data{
"completed_task": 0,
"head": "25924b6d2bdb1ef2fbc9f55e67d9a73da445e0c2",
"kind": "requested",
"schema_version": "1",
"state": "e307b3121bd2e5e866b5e6ea8e61c191e9f3ea9332af4a7c7112f07ca272c745",
"work": [
"025d8c73a512c851a34fb3206ffeb52616720dcc6b820472e7c789cea24483bf",
"074f874c085acada191a64c87bbe11dda281b6dd6574a5649dc0b94430c37779",
"1b6acb702e4908f394d8597f78eac49a338f88a129069623dcb04aac535297d6",
"219aa7fb6e77d6475b28342ea6d5413b7fe5d84c742471efb5ec981a9836cc26",
"31d3efc53f09b7a7eae3a47e52d681dbca2375f81afebbae53d32987f5727791",
"95e3ad84de73d5d8326e40af51426c5e7bb77c8a05971f21553b3e7db23388bb",
"9cef6c9d15bda6048fba74e41b251d1c2afb8dc70a4a29334a6155c1be4f2409",
"a2714d789b51f2265e8a4c5b704f31a921ac3cc64382b822ec4edf2c01153a1b",
"af9bb3f18d91437b8ce3a32cfec08557feb0b12255a0a4e8a514bee9154633c4",
"d7daeb44e0d54603607d7ad9c5292548b14452676bd5277b5ddd56729fb7340b"
],
"workflow": "pr-sous-chef"
}
|
…ap-copy-loop-e5c786f5623b6782 Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
|
Category: feature | Risk: medium | Score 62/100 (impact 28 + urgency 17 + quality 17) | Action: auto_merge | Reason: new linter analyzer is scoped and CI validated; keep it moving after a standard review.
|


Add a readability linter for range-over-map loops that copy each entry into another map. It reports only single-statement
dst[k] = vloops and can suggest replacing them withmaps.Copy.nolint:mapcopyloop.mapsis visible and both maps have the same type.