Repository navigation
Add stringssplitfirst analyzer - #75753
Conversation
Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
stringssplitfirst analyzer
|
✅ PR Code Quality Reviewer completed the code quality review.
|
|
❌ Design Decision Gate 🏗️ failed to deliver outputs during design decision gate check.
|
|
🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅
|
|
✅ 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.
|
|
✅ Ponytail Reviewer completed successfully!
|
|
✅ PR Specification Reviewer completed successfully! PR Specification ReviewerOutcome: 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.
|
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.
Request changes: the splitindexzero analyzer was narrowed to SplitN, but its emitted diagnostic still names strings.Split/SplitN, so findings are misleading and overlap conceptually with the new analyzer. Please update the message and related expectations.
Static review only; I did not run tests. The specialist pass was unavailable because its tool invocation was rejected, so this review reflects the independent pass.
🔎 Code quality review by PR Code Quality Reviewer · copilot · gpt50 · ~2 AIC · ⌖ ~1 AIC · ⊞ 1.6K
Comment /review to run again
| } | ||
|
|
||
| if !isSplitCall(pass, index.X) { | ||
| if !isSplitNCall(pass, index.X) { |
There was a problem hiding this comment.
The matcher now only accepts strings.SplitN, but the diagnostic text below still says strings.Split/SplitN. As a result, every finding from this analyzer falsely claims that strings.Split was matched, which is especially confusing now that strings.Split has moved to the new analyzer. Please update the message to mention only strings.SplitN (and keep the docs/test expectations in sync).
There was a problem hiding this comment.
Fixed in f2b931d: the diagnostic now names only strings.SplitN, and the fixture pins the full diagnostic text so the stale wording cannot pass. The README and analyzer documentation already describe the SplitN-only scope. Focused tests pass.
|
Warning The 🏗️ Design Decision Gate — ADR RequiredThis PR adds 197 new lines under 📄 Draft ADR committed: Decision captured in the draft: add a dedicated
📋 What to do next
Once an ADR is linked in the PR body, this gate will re-run and check that the implementation matches the decision. ❓ Why ADRs MatterADRs create a searchable, permanent record of why the codebase looks the way it does. Future contributors (and your future self) will thank you. 📋 Michael Nygard ADR Format ReferenceAn ADR must contain these four sections to be considered complete:
All ADRs are stored in
|
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are blocking approval.
No open issues 🎉
1 file not reviewed
pkg/linters/stringssplitfirst/testdata/src/stringssplitfirst/generated.go: Generated file
What changed in this PR
Adds stringssplitfirst to gh-aw’s custom Go analyzers, recommending strings.Cut instead of strings.Split(s, sep)[0] when the separator is a non-empty constant.
Changes:
- Adds the coverage-aware analyzer and fixtures for matching, excluded, generated, and suppressed cases.
- Restricts
splitindexzerotostrings.SplitN(..., 2)[0]to avoid duplicate reports. - Updates registration and documentation, marking the new analyzer as not yet CI-enforced.
| File | Description |
|---|---|
pkg/linters/stringssplitfirst/testdata/src/stringssplitfirst/stringssplitfirst.go |
Tests matches, exclusions, aliases, and suppression. |
pkg/linters/stringssplitfirst/testdata/src/stringssplitfirst/generated.go |
Verifies generated code is skipped. |
pkg/linters/stringssplitfirst/stringssplitfirst.go |
Implements the coverage-aware analyzer. |
pkg/linters/stringssplitfirst/stringssplitfirst_test.go |
Runs analyzer fixture tests. |
pkg/linters/splitindexzero/testdata/src/splitindexzero/splitindexzero.go |
Updates fixtures for SplitN-only reporting. |
pkg/linters/splitindexzero/splitindexzero.go |
Narrows detection to strings.SplitN. |
pkg/linters/spec_test.go |
Adds the analyzer to documentation checks. |
pkg/linters/registry.go |
Registers the new analyzer. |
pkg/linters/README.md |
Documents the analyzer and revised rule scopes. |
pkg/linters/doc.go |
Updates the analyzer catalog and count. |
pkg/linters/doc_sync_test.go |
Records deferred CI enforcement. |
Review effort: Balanced (auto)
There was a problem hiding this comment.
What this change does: Adds a separate analyzer for constant, non-empty strings.Split(...)[0] cases and narrows splitindexzero to SplitN. It also wires the analyzer into the registry, documentation, coverage gating, and focused tests.
Should fix:
-
Keep standard-library matching in the shared helper (
pkg/linters/stringssplitfirst/stringssplitfirst.go:65-68)- What this is:
isStringsSplitreimplements selector unwrapping and standard-library package matching. - Problem:
astutil.AsStringsMethodCallinpkg/linters/internal/astutil/astutil.goalready owns this exact check, so this creates a second path that can drift when the shared matcher changes. - Fix: Call
astutil.AsStringsMethodCall(pass, call,Split)here, then keep only the argument and separator checks. - If we skip it: Every shared matching change needs another manual update and this rule carries redundant branches.
- What this is:
Verdict: fix 1 first.
Lean: -1 lines possible.
Generated by ✂️ Ponytail Reviewer for #75753 · codex · routed: gpt56 max · ~4 AIC · ⌖ ~1 AIC · ⊞ 118
Comment /ponytail to run again
| } | ||
|
|
||
| func isStringsSplit(pass *analysis.Pass, call *ast.CallExpr) bool { | ||
| sel, ok := astutil.UnwrapParenExpr(call.Fun).(*ast.SelectorExpr) |
There was a problem hiding this comment.
What this is: isStringsSplit reimplements selector unwrapping and standard-library package matching. Problem: astutil.AsStringsMethodCall in pkg/linters/internal/astutil/astutil.go already owns this exact check, so this creates a second path that can drift when the shared matcher changes. Fix: Call astutil.AsStringsMethodCall(pass, call, Split) here, then keep only the argument and separator checks. If we skip it: Every shared matching change needs another manual update and this rule carries redundant branches.
There was a problem hiding this comment.
Fixed in f2b931d: isStringsSplit now delegates standard-library matching to astutil.AsStringsMethodCall(pass, call, "Split"), retaining the argument and separator checks. Added a parenthesized-selector fixture; focused analyzer and shared-helper tests pass.
There was a problem hiding this comment.
Skills-Based Review 🧠
Applied /diagnosing-bugs, /tdd, and /codebase-design. Requesting changes on one misleading diagnostic and one duplicated helper; the rest is minor.
📋 Key Themes & Highlights
Key Themes
- Stale diagnostic:
splitindexzeronow matches onlySplitN, but its message still saysSplit/SplitN(line 59). The testdatawantregexstrings\.Splitmatches that stale text, so the test does not catch it. - Duplicated helpers:
isConstantIntand the constant non-empty string check are duplicated betweenstringssplitfirstandsplitindexzero. ADR 53564 already sets the precedent for hoisting them intopkg/linters/internal/astutil. - Stale ADR:
docs/adr/74904-add-splitindexzero-analyzer.mdstill describes the pre-narrowing scope.
Positive Highlights
- ✅ Both analyzers are registered consistently in
registry.go,spec_test.go,doc.go, and the README, andnotYetEnforcedcovers both. - ✅ Test coverage for
stringssplitfirstis good: alias, parenthesized, shadowed package, dynamic and empty separators, andnolint. - ✅ Narrowing
splitindexzeroremoves no CI enforcement, since neither analyzer is in the CI linter list. - ✅
go test ./pkg/linters/...passes.
Production Findings (informational)
The new analyzer flags 2 existing sites: pkg/workflow/engine_config_parser.go:198 and pkg/cli/edit_command.go:80. splitindexzero flags 6 SplitN sites in pkg/workflow and pkg/cli. These are correctly parked under notYetEnforced, but they are worth a tracking issue.
Note: The first inline comment was anchored to
splitindexzero.goline 20 (the correct description). The real issue is line 59, which has its own comment. Please disregard the line-20 comment.
@copilot please address the review comments above.
Comments that could not be inline-anchored
pkg/linters/doc_sync_test.go:49
Nit: `notYetEnforced` is kept in alphabetical order, and `stringssplitfirst` sits between `splitindexzero` and `sprintferrdot`. Move it below `stringsconcatloop` to keep the map sorted. @copilot please address this.
pkg/linters/splitindexzero/splitindexzero.go:20
**[/tdd]** The analyzer description is correct now, but the diagnostic at line 59 still says `strings.Split/SplitN(...)[0]`. Since `Split` is no longer reported, this message misleads users. Change it to say `strings.SplitN(...)[0]`. The testdata `// want` pattern `strings\.Split` is too loose to catch this, because it also matches `strings.SplitN`. Tighten it to `strings\.SplitN` so the message is pinned. @copilot please address this.
pkg/linters/stringssplitfirst/stringssplitfirst.go:77
**[/codebase-design]** `isConstantInt` duplicates the helper of the same name in `splitindexzero.go`. The constant non-empty string check on line 74 duplicates `hasNonEmptyStringArgument` there. Per the hoisting precedent in ADR 53564, move both into `pkg/linters/internal/astutil` so the two analyzers share one definition and cannot drift apart. @copilot please address this.
pkg/linters/splitindexzero/splitindexzero.go:59
**[/diagnosing-bugs]** This diagnostic still says `strings.Split/SplitN(...)[0]`, but the analyzer now only matches `SplitN`, so the message misleads users. Change it to `strings.SplitN(...)[0] allocates a []string just to read the first segment; use strings.Cut instead`. This supersedes the earlier comment anchored to line 20, which is correct as written. @copilot please address this.
🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · copilot · routed: haiku55 xhigh · ~7 AIC · ⌖ ~2 AIC · ⊞ 5.4K
Comment /matt to run again
|
Copilot assignment requested for the following outstanding work:
Once you start work, post this work summary as a PR comment without the leading Copilot mention, including the Sous-chef head, work, and state lines below, to record that the assignment is running. Apply the necessary fixes on this PR's existing branch, reply to each listed review thread and resolve it when addressed. Ignore feedback already answered or resolved; stop when only human review or CI remains. Do not merge or trigger CI. Sous-chef requested-head: 745ff90
|
Assignment running. Copilot assignment requested for the following outstanding work:
I will apply fixes on this existing branch, reply to and resolve addressed review threads where supported, and stop when only human review or CI remains. I will not merge the PR or trigger CI. Sous-chef requested-head: 745ff90 |
…tringssplitfirst Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
|
🎉 This pull request is included in a new release. Release: |
strings.Split(s, sep)[0]allocates a slice when only the first segment is needed. Add a linter recommendingstrings.Cutfor constant, non-empty separators.stringssplitfirst, with tests for matches, exclusions, generated code, andnolint.splitindexzerotostrings.SplitN(..., 2)[0].