lenstringzero: report the actual expression in diagnostic messages - #54721
Conversation
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
|
Hey Per CONTRIBUTING.md:
Next steps:
This ensures coordination and maintains the project's agentic development workflow. The code quality is excellent — once you follow the process, this fix should move through quickly. 🚀
|
|
✅ Ponytail Reviewer completed successfully! Lean already. Ship.
|
|
🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅
|
|
✅ Test Quality Sentinel completed test quality analysis. Test Quality Sentinel skipped because pre-fetch PR data was unavailable: unable to fetch PR file list
|
|
✅ Design Decision Gate 🏗️ completed the design decision gate check. No ADR enforcement needed: PR #54721 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. Reviewed PR #54721 and found no actionable changed-line issues to comment on; submitting no-op safe output to satisfy workflow requirement.
|
There was a problem hiding this comment.
Pull request overview
Updates lenstringzero diagnostics to report the actual source expressions.
Changes:
- Propagates matched
lenor alias nodes into diagnostic construction. - Renders accurate argument and comparison text with fallbacks.
- Adds exact-message regression fixtures for named variables and aliases.
Show a summary per file
| File | Description |
|---|---|
pkg/linters/lenstringzero/lenstringzero.go |
Builds diagnostics from matched AST expressions. |
pkg/linters/lenstringzero/testdata/src/lenstringzero/lenstringzero.go |
Adds and updates diagnostic expectations. |
pkg/linters/lenstringzero/testdata/src/lenstringzero/lenstringzero.go.golden |
Updates expected suggested-fix output. |
Review details
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
- Files reviewed: 3/3 changed files
- Comments generated: 0
- Review effort level: Balanced
There was a problem hiding this comment.
Skills-Based Review 🧠
Applied /diagnosing-bugs — the fix correctly addresses root cause, not just symptoms. Approving.
📋 Key Themes & Highlights
Key Themes
- Root cause fixed: hardcoded
s/len(s)placeholders replaced with actual source text at the diagnostic site - Fallback is safe:
exprTextOrgracefully degrades to the old placeholders whenNodeTextcan't render - Regression tests added:
namedVariableEmptyandnamedVariableAliasEmptypin exact message text for non-trivial variable names
Positive Highlights
- ✅ All 8 return paths in
matchLenLiteralExprcorrectly thread the newlenNodevalue - ✅ Golden file correctly leaves alias cases unchanged (consistent with existing behavior)
- ✅
exprTextOris a clean, reusable helper with a clear contract - ✅ PR scope is tight: only the diagnostic message is touched;
SuggestedFixesconstruction is correctly left alone
🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · sonnet46 · 19.8 AIC · ⌖ 9.76 AIC · ⊞ 7.6K
Comment /matt to run again
There was a problem hiding this comment.
The changes are correct and well-implemented. The linter now reports actual source expressions in diagnostic messages (e.g. use n == "" instead of the hardcoded use s == ""), which makes messages significantly more actionable for developers.
The implementation is clean:
lenNodeis threaded through the return signature with clear documentationexprTextOrhas a proper nil guard and meaningful fallback- All test expectations and golden files are updated consistently
🧵 Reviewed using Impeccable skills by Impeccable Skills Reviewer · sonnet46 · 18.5 AIC · ⌖ 8.98 AIC · ⊞ 6.2K
Comment MemoryNote This comment is managed by comment memory.It stores persistent context for this thread in the code block at the top of this comment.
|
PR Triage
|
PR TriageCategory: Non-draft, CI green (29 success), 2x APPROVED. Automated triage — run 32572524009
|
|
@copilot this PR still needs forward progress before maintainer review.
Run: https://github.com/github/gh-aw/actions/runs/32573431024
|
…-diagnostic-message Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
Branch refreshed by merging
Verified locally after the merge:
Diff vs |
lenstringzerohardcoded the placeholder textsandlen(s)in its diagnostic format string, so every violation named a variable that doesn't exist in the source. The alias path (n := len(s); if n == 0) was doubly wrong: it reportedlen(s)where the source readsn, and nosappears at the flagged line at all.Before / after for
if len(username) == 0:Changes
matchLenLiteralExprnow also returnslenNode, the expression actually being compared — thelen(...)call for the direct case, the alias identifier for the alias case. Yoda-order branches return the corresponding operand.astutil.NodeTextfor both the string argument and the compared node, via a smallexprTextOrhelper that falls back to the previous placeholders if a node can't be printed.analysistestsource and golden files updated ton; addednamedVariableEmpty/namedVariableAliasEmptycases asserting exact message text for a non-trivial variable name (username/usernameLen).SuggestedFixesconstruction is untouched — the autofix was already correct.Out of scope
The issue notes
lenstringzerois missing fromLINTER_FLAGSin.github/workflows/cgo.yml, which is why this went unnoticed. Enabling it repo-wide is a separate change with broader blast radius and isn't part of the issue's validation checklist.