Skip to content

Add stringssplitfirst analyzer - #75753

Merged
pelikhan merged 4 commits into
mainfrom
copilot/linter-minerstringssplitfirst
Nov 7, 2026
Merged

pelikhan merged 4 commits into
mainfrom
copilot/linter-minerstringssplitfirst

Conversation

Copilot AI commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

strings.Split(s, sep)[0] allocates a slice when only the first segment is needed. Add a linter recommending strings.Cut for constant, non-empty separators.

  • Analyzer: Register stringssplitfirst, with tests for matches, exclusions, generated code, and nolint.
  • Avoid duplicate reports: Narrow splitindexzero to strings.SplitN(..., 2)[0].
  • Docs and enforcement: Update linter documentation and track the new analyzer as not yet CI-enforced.
first := strings.Split(value, ",")[0] // prefer strings.Cut

Copilot AI linked an issue Nov 7, 2026 that may be closed by this pull request
Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
Copilot AI changed the title [WIP] Add stringssplitfirst linter Add stringssplitfirst analyzer Nov 7, 2026
Copilot AI requested a review from gh-aw-bot November 7, 2026 21:40
@pelikhan
pelikhan marked this pull request as ready for review November 7, 2026 21:51
Copilot AI dynamic review requested due to automatic review settings November 7, 2026 21:51
@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

✅ PR Code Quality Reviewer completed the code quality review.

🔎 Code quality review by PR Code Quality Reviewer

@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

❌ Design Decision Gate 🏗️ failed to deliver outputs during design decision gate check.

🏗️ ADR gate enforced by Design Decision Gate 🏗️

@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer

@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

✅ Test Quality Sentinel completed test quality analysis.

Test Quality Sentinel

Outcome: reported_no_action

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.

Generated from Test Quality Sentinel · routed: gpt56 max · ~1 AIC · ⌖ ~2 AIC · ⊞ 6.3K · ◷

🧪 Test quality analysis by Test Quality Sentinel

@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

✅ Ponytail Reviewer completed successfully!

Generated by Ponytail Reviewer for #75753

@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

✅ PR Specification Reviewer completed successfully!

PR Specification Reviewer

Outcome: reported_no_action

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.

Generated from PR Specification Reviewer · gpt56 · ~1 AIC · ⌖ ~1 AIC · ⊞ 1.7K · ◷

Generated by PR Specification Reviewer for #75753

@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

Comment Memory

Peek at saved memory (pr-code-quality-reviewer)
reviewed_at: 2026-11-07T21:54:31Z
review_event: REQUEST_CHANGES
top_themes:
  - stale diagnostic text after narrowing splitindexzero to SplitN
files_reviewed:
  - pkg/linters/splitindexzero/splitindexzero.go
  - pkg/linters/stringssplitfirst/stringssplitfirst.go
  - pkg/linters/registry.go
  - pkg/linters/README.md
  - pkg/linters/doc.go
  - pkg/linters/doc_sync_test.go
  - pkg/linters/spec_test.go
comment_count: 1

Note

This comment is managed by comment memory.

Expand the saved memory block to view or edit the persistent context for this thread.
Edit only the text inside the backtick fences; workflow metadata and the footer are regenerated automatically.

Learn more about comment memory

🔎 Code quality review by PR Code Quality Reviewer · copilot · gpt50 · ~2 AIC · ⌖ ~1 AIC · ⊞ 1.6K · ◷
Comment /review to run again

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

Warning

The push_to_pull_request_branch operation failed: Cannot verify branch protection rules for "copilot/linter-minerstringssplitfirst": Resource not accessible by integration - https://docs.github.com/rest/branches/branch-protection\#get-branch-protection. Reading classic branch protection requires a GitHub App installation token or fine-grained PAT with Administration: read repository permission; GITHUB_TOKEN cannot provide this permission. Push blocked to prevent accidental writes to protected branches.. The code changes were not applied.

🏗️ Design Decision Gate — ADR Required

This PR adds 197 new lines under pkg/, which is over the 100-line threshold. It has no linked Architecture Decision Record (ADR).

📄 Draft ADR committed: docs/adr/75753-split-first-segment-detection-into-stringssplitfirst-analyzer.md. Review and complete it before merging.

Decision captured in the draft: add a dedicated stringssplitfirst analyzer for strings.Split(s, sep)[0] with a constant, non-empty separator. Narrow splitindexzero to strings.SplitN(s, sep, 2)[0] so the same call is never reported twice.

🔒 This PR cannot merge until an ADR is linked in the PR body.

📋 What to do next
  1. Review the draft ADR committed to your branch. It was generated from the PR diff.

  2. Complete the missing sections. Resolve the [TODO: verify] note on why a separate analyzer was preferred over keeping coverage in splitindexzero, and refine the alternatives.

  3. Commit the finalized ADR to docs/adr/ on your branch.

  4. Reference the ADR in this PR body by adding a line such as:

    ADR: ADR-75753: Split First-Segment Detection into a Dedicated stringssplitfirst Analyzer (link unavailable: invalid HTTPS URL)

Once an ADR is linked in the PR body, this gate will re-run and check that the implementation matches the decision.

❓ Why ADRs Matter

ADRs 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 Reference

An ADR must contain these four sections to be considered complete:

  • Context: What is the problem? What forces are at play?
  • Decision: What did you decide? Why?
  • Alternatives Considered: What else could have been done?
  • Consequences: What are the trade-offs (positive and negative)?

All ADRs are stored in docs/adr/ as Markdown files numbered by PR number.

🏗️ ADR gate enforced by Design Decision Gate 🏗️ · pi · routed: opus55 medium · ~35 AIC · ⌖ ~2 AIC · ⊞ 7.7K · ◷
Comment /review to run again

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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 splitindexzero to strings.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)

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. Keep standard-library matching in the shared helper (pkg/linters/stringssplitfirst/stringssplitfirst.go:65-68)

    • 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.

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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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: splitindexzero now matches only SplitN, but its message still says Split/SplitN (line 59). The testdata want regex strings\.Split matches that stale text, so the test does not catch it.
  • Duplicated helpers: isConstantInt and the constant non-empty string check are duplicated between stringssplitfirst and splitindexzero. ADR 53564 already sets the precedent for hoisting them into pkg/linters/internal/astutil.
  • Stale ADR: docs/adr/74904-add-splitindexzero-analyzer.md still describes the pre-narrowing scope.

Positive Highlights

  • ✅ Both analyzers are registered consistently in registry.go, spec_test.go, doc.go, and the README, and notYetEnforced covers both.
  • ✅ Test coverage for stringssplitfirst is good: alias, parenthesized, shadowed package, dynamic and empty separators, and nolint.
  • ✅ Narrowing splitindexzero removes 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.go line 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

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot

Copilot assignment requested for the following outstanding work:

  1. Update this branch with the latest main using make merge-main, resolving any conflicts and preserving the intended changes.
  2. Review (pkg/linters/splitindexzero/splitindexzero.go:41): 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). - Add stringssplitfirst analyzer #75753 (comment)
  3. Review (pkg/linters/stringssplitfirst/stringssplitfirst.go:66): 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. - Add stringssplitfirst analyzer #75753 (comment)
  4. Fix failing check safe_outputs (FAILURE): https://github.com/github/gh-aw/actions/runs/42417851349/job/128541017343.

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
Sous-chef requested-work: 311a6cdbd8f978b589ed24b913ecca38976b64766ce32de4372ead8150526e5e 547be554db21843f0a91bfb5978e989bcd40ad6e19fa77bbd87e160c3a0c75f5 c7cf93e497befdd5e698d00101b0703e4101fe4133d86d433f7c170d07402b7e
Sous-chef requested-state: 7dad0c0855da7906206bcbb87d81aa5a7105ac2f81fb772c7b49cbd78d7517b2

Generated by 👨🍳 PR Sous Chef · pi · haiku45 · ~5 AIC · ⌖ ~15 AIC · ⊞ 1.2K · ◷
Comment /souschef to run again

Copilot AI commented Nov 7, 2026

Copy link
Copy Markdown
Contributor Author

@copilot

Copilot assignment requested for the following outstanding work:...

Assignment running.

Copilot assignment requested for the following outstanding work:

  1. Update this branch with the latest main using make merge-main, resolving conflicts while preserving the intended changes.
  2. Update the splitindexzero diagnostic to mention only strings.SplitN, keeping documentation and test expectations in sync (discussion_r4503893303).
  3. Reuse astutil.AsStringsMethodCall(pass, call, "Split") in stringssplitfirst instead of duplicating standard-library matching (discussion_r4503896266).
  4. Investigate and address the failing safe_outputs check: https://github.com/github/gh-aw/actions/runs/42417851349/job/128541017343.

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
Sous-chef requested-work: 311a6cdbd8f978b589ed24b913ecca38976b64766ce32de4372ead8150526e5e 547be554db21843f0a91bfb5978e989bcd40ad6e19fa77bbd87e160c3a0c75f5 c7cf93e497befdd5e698d00101b0703e4101fe4133d86d433f7c170d07402b7e
Sous-chef requested-state: 7dad0c0855da7906206bcbb87d81aa5a7105ac2f81fb772c7b49cbd78d7517b2

…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>
@pelikhan
pelikhan merged commit 7c46d5b into main Nov 7, 2026
63 checks passed
@pelikhan
pelikhan deleted the copilot/linter-minerstringssplitfirst branch November 7, 2026 23:09
@github-actions

Copy link
Copy Markdown
Contributor

🎉 This pull request is included in a new release.

Release: v1.2.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[linter-miner] Add stringssplitfirst linter

4 participants