mapdeletecheck: suppress autofix when comments overlap the replaced span#46159
Conversation
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
…ix against comment loss Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Prevents mapdeletecheck autofixes from discarding comments by sharing comment-overlap detection with mapclearloop.
Changes:
- Extracts
HasOverlappingCommentinto shared AST utilities. - Suppresses unsafe fixes while retaining diagnostics.
- Adds comment-related fixtures and refreshes workflow lock metadata.
Show a summary per file
| File | Description |
|---|---|
pkg/linters/internal/astutil/astutil.go |
Adds shared overlap detection. |
pkg/linters/mapclearloop/mapclearloop.go |
Uses shared helper. |
pkg/linters/mapdeletecheck/mapdeletecheck.go |
Guards suggested fixes. |
pkg/linters/mapdeletecheck/testdata/src/mapdeletecheck/mapdeletecheck.go |
Adds commented test cases. |
pkg/linters/mapdeletecheck/testdata/src/mapdeletecheck/mapdeletecheck.go.golden |
Adds expected unchanged cases. |
.github/workflows/skillet.lock.yml |
Normalizes action version metadata. |
.github/workflows/release.lock.yml |
Normalizes action version metadata. |
.github/workflows/hourly-ci-cleaner.lock.yml |
Normalizes action version metadata. |
.github/workflows/avenger.lock.yml |
Normalizes action version metadata. |
Review details
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 9/9 changed files
- Comments generated: 1
- Review effort level: Medium
| Message: "redundant existence check before delete: delete(" + mText + ", " + kText + ") is already a no-op when the key is absent; remove the if statement", | ||
| SuggestedFixes: []analysis.SuggestedFix{{ | ||
| } | ||
| if !astutil.HasOverlappingComment(pass.Files, ifStmt.Pos(), ifStmt.End()) { |
|
✅ Design Decision Gate 🏗️ completed the design decision gate check. No ADR enforcement needed: PR #46159 does not have the 'implementation' label and has only 58 new lines of code in business logic directories (threshold: 100). |
|
✅ PR Code Quality Reviewer completed the code quality review. |
|
✅ Test Quality Sentinel completed test quality analysis. No test files were added or modified in this PR. The PR (#46159) only modifies production code in pkg/linters/ (astutil, mapclearloop, mapdeletecheck) and test data files (.golden and testdata), but no *_test.go or *.test.js files. Test Quality Sentinel analysis skipped. |
|
🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅ |
There was a problem hiding this comment.
Clean refactor: extracts hasOverlappingComment into shared astutil.HasOverlappingComment, applies it consistently in both mapclearloop and mapdeletecheck, and adds test cases that confirm the diagnostic still fires while autofix is correctly suppressed. No issues found.
🧵 Reviewed using Impeccable skills by Impeccable Skills Reviewer · 18.8 AIC · ⌖ 5.35 AIC · ⊞ 5K
There was a problem hiding this comment.
One existing unresolved bug blocks merge
The open review comment at line 124 of mapdeletecheck.go identifies a real correctness break: the // want directives on the bad() if-statements are trailing comments on the if line, falling inside [ifStmt.Pos(), ifStmt.End()). HasOverlappingComment therefore returns true for those cases too, suppressing their SuggestedFix — but the golden file expects the rewritten delete(...) form. The analysistest run will fail.
Lines 7 and 12 of the test fixture both carry // want ... as trailing comments inside the if-statement span. No fix is emitted. Golden expects the fix applied. Must be resolved before merge.
One low-severity nil-guard observation left inline on astutil.go.
🔎 Code quality review by PR Code Quality Reviewer · 49.2 AIC · ⌖ 4.41 AIC · ⊞ 5.6K
Comment /review to run again
| if end <= file.Pos() || start >= file.End() { | ||
| continue | ||
| } | ||
| for _, group := range file.Comments { |
There was a problem hiding this comment.
Nil file entry will panic: if files contains a nil *ast.File (e.g. a buggy or test-injected pass), file.Pos(), file.End(), and file.Comments will all panic.
💡 Suggested fix
for _, file := range files {
if file == nil {
continue
}
if end <= file.Pos() || start >= file.End() {This won't happen in normal go/analysis usage since pass.Files is always populated by the framework, but the function is exported and could be called by future linters that build a synthetic file slice. The nil check is one line and removes the footgun.
There was a problem hiding this comment.
Skills-Based Review 🧠
Applied /diagnosing-bugs and /tdd — requesting changes on two actionable issues.
📋 Key Themes & Highlights
Issues Found
- Test fixture interference (critical):
analysistest// wantdirectives fall withinifStmt.Pos()..ifStmt.End(), meaningHasOverlappingCommentmay suppress the suggested fix even for the plainbad()cases during testing. The golden file needs verification that it reflects real auto-fix behaviour (see inline comment). - Missing unit test for extracted utility:
HasOverlappingCommentis a new shared function inastutilwith no direct unit tests, leaving boundary conditions (adjacent comments, zero-width ranges) unexercised.
Positive Highlights
- ✅ Clean extraction of the private helper into the shared
astutilpackage. - ✅ Diagnostic always fires; only the autofix is suppressed — correct user experience.
- ✅
badWithComments()test cases are cleanly separated and well-commented.
Warning
Firewall blocked 1 domain
The following domain was blocked by the firewall during workflow execution:
proxy.golang.org
To allow these domains, add them to the
network.allowedlist in your workflow frontmatter:
network:
allowed:
- defaults
- "proxy.golang.org"See Network Configuration for more information.
🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · 45 AIC · ⌖ 4.49 AIC · ⊞ 6.7K
Comment /matt to run again
Comments that could not be inline-anchored
pkg/linters/internal/astutil/astutil.go:136
[/tdd] HasOverlappingComment has no unit test in astutil_test.go — correctness is only exercised indirectly through linter integration tests, leaving boundary conditions (e.g. comment.End == start, zero-width range) untested.
<details>
<summary>💡 Suggested unit test sketch</summary>
func TestHasOverlappingComment(t *testing.T) {
src := "package p\n// comment\nvar x = 1\n"
fset := token.NewFileSet()
f, _ := parser.ParseFile(fset, "x.go", src, parser.ParseComments)
…
</details>|
@copilot run pr-finisher skill |
|
@copilot please run the Failed checks:
|
…rectives from suppressing autofixes Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
… autofixes The // want directives on the if line fell within [ifStmt.Pos(), ifStmt.End()), causing HasOverlappingComment to suppress ALL fixes including bad() cases that should have a fix. RunWithSuggestedFixes never populated allFilenames, so the golden file comparison never ran. Move // want to // want +1 on the line before each if statement so they are outside the replaced span. Update the golden file to include the // want +1 comment lines that remain after fixes are applied. Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Addressed in the latest commit. Moved all |
The function is exported and could be called with a synthetic file slice; skip nil entries to avoid a panic on file.Pos()/file.End()/file.Comments. Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
Investigated the CI failure. The Smoke CI job failed due to a runner infrastructure error — |
|
🎉 This pull request is included in a new release. Release: |
mapdeletecheckemittedSuggestedFixunconditionally, so any comment inside theifbody was silently dropped when the autofix was applied.mapclearloopalready guards against this;mapdeletecheckwas inconsistent.Changes
pkg/linters/internal/astutil— AddedHasOverlappingComment(files, start, end), lifting the previously private helper frommapclearloopinto the shared utility package.pkg/linters/mapclearloop— Replaced localhasOverlappingCommentwithastutil.HasOverlappingComment.pkg/linters/mapdeletecheck— GuardsSuggestedFixeswithastutil.HasOverlappingComment; diagnostic always fires, fix is suppressed when comments overlap theifStmtspan.badWithComments()cases (leading and trailing comment) to assert diagnostic fires but no autofix is emitted.Behavior