Skip to content

[Code Quality] Extract shared hasOverlappingComment guard into pkg/linters/internal/astutil #46477

Description

@github-actions

Description\n\nThe hasOverlappingComment comment-preservation guard is currently implemented inline inside mapclearloop analyzer but is missing from mapdeletecheck (tracked in #46130). Both are block/statement-replacing autofixers that should protect comments from being silently dropped.\n\nThe Sergo R62 audit (2026-07-18) explicitly recommends extracting this guard to internal/astutil to eliminate duplication and enable consistent comment-safety across all SuggestedFix autofixers.\n\n## Suggested Changes\n\n1. Create pkg/linters/internal/astutil/comments.go with an exported HasOverlappingComment helper\n2. Replace the inline implementation in mapclearloop with a call to the shared helper\n3. Add the guard to mapdeletecheck via the shared helper (resolves #46130)\n4. Add unit tests for the shared helper\n\n## Files Affected\n\n- pkg/linters/mapclearloop.go (extract inline guard)\n- pkg/linters/mapdeletecheck.go (add missing guard)\n- pkg/linters/internal/astutil/comments.go (new file)\n\n## Success Criteria\n\n- hasOverlappingComment logic exists in exactly one place\n- Both mapclearloop and mapdeletecheck use the shared helper\n- All existing linter tests pass\n- make golint-custom remains clean\n\n## Source\n\nExtracted from Sergo Report #46342 (2026-07-18), R62 next-steps section.\n\n## Priority\n\nMedium — prevents comment loss in autofixes and reduces duplication.

🔍 Task mining by Discussion Task Miner - Code Quality Improvement Agent · 75.7 AIC · ⌖ 7.67 AIC · ⊞ 7K ·

  • expires on Jul 19, 2026, 11:16 AM UTC-08:00

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions