Repository navigation
[linter-miner] Add splitlines-on-newline custom analyzer - #75820
Conversation
Co-authored-by: gh-aw-bot <[email protected]>
|
|
🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅
|
|
❌ Design Decision Gate 🏗️ failed to deliver outputs during design decision gate check.
|
|
✅ 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.
|
|
✅ Ponytail Reviewer completed successfully!
|
|
✅ 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.
|
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.
🔎 Code quality review by PR Code Quality Reviewer · copilot · gpt50 · ~2 AIC · ⌖ ~1 AIC · ⊞ 1.6K
Comment /review to run again
| pass.Report(analysis.Diagnostic{ | ||
| Pos: call.Pos(), | ||
| End: call.End(), | ||
| Message: "strings.Split with a newline separator can retain carriage returns on CRLF input and produce a trailing empty element; normalize line endings or use a line scanner instead", |
There was a problem hiding this comment.
The blanket advice to 'use a line scanner instead' is unsafe: bufio.Scanner has a default 64 KiB token limit and different trailing-line semantics, so callers may introduce failures or behavior changes simply by following this diagnostic. Please keep the recommendation to normalize CRLF / trim \r, or qualify scanner guidance with its buffer and semantic caveats.
There was a problem hiding this comment.
Updated the diagnostic to recommend normalizing line endings or trimming carriage returns from each line; it no longer suggests Scanner. Commit 13d801c.
|
Warning The 🏗️ Design Decision Gate — ADR RequiredThis PR makes significant changes to core business logic (155 new lines under 📄 Draft ADR committed:
Key decisions in the draft: a type-aware 📋 What to do next
Once an ADR is linked in the PR body, this gate will re-run and verify 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 ReferenceAn ADR must contain these four sections to be considered complete:
All ADRs are stored in
|
There was a problem hiding this comment.
What this change does: Adds a registered analyzer that reports strings.Split calls with a compile-time newline separator. It also wires the analyzer into documentation, suppression handling, generated-file filtering, and analysis tests.
Should fix:
-
Reuse the existing strings-call matcher (
pkg/linters/splitlines-on-newline/splitlines_on_newline.go:L54)- What this is:
isStringsSplitrecognizes astrings.Splitcall. - Problem: Its selector unwrapping and package check duplicate
astutil.AsStringsMethodCall, already used bystringssplitfirstand covered by shared tests. The argument-count guard is also repeated inhasNewlineSeparator. - Fix: Call
astutil.AsStringsMethodCall(pass, call, "Split")and keep one argument-count check, deleting the local selector logic and redundant guard. - If we skip it: This analyzer owns another copy of matching logic that must be maintained whenever the shared helper changes.
- What this is:
Verdict: fix 1 first.
Lean: -9 lines possible.
Generated by ✂️ Ponytail Reviewer for #75820 · codex · routed: gpt56 max · ~3 AIC · ⌖ ~1 AIC · ⊞ 118
Comment /ponytail to run again
| }) | ||
| } | ||
|
|
||
| func isStringsSplit(pass *analysis.Pass, call *ast.CallExpr) bool { |
There was a problem hiding this comment.
Reuse astutil.AsStringsMethodCall here; it already performs the exact parenthesis, method-name, and strings-package checks. Keeping this local matcher duplicates that helper and its tests; replacing it and retaining one argument-count check removes several lines without changing the analyzer behavior.
There was a problem hiding this comment.
Replaced the local matcher with astutil.AsStringsMethodCall and retained one argument-count check. Commit 13d801c.
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues block approval of the newline-splitting analyzer change.
No open issues 🎉
1 file not reviewed
pkg/linters/splitlines-on-newline/testdata/src/splitlinesonnewline/generated.go: Generated file
What changed in this PR
Adds a custom Go analyzer to gh-aw’s linter suite that flags strings.Split calls using a newline separator, highlighting possible CRLF handling and trailing-empty-element issues.
Changes:
- Adds type-checked detection for literal and named newline constants, including aliased imports.
- Adds fixtures covering detection, exclusions, generated files, and suppression directives.
- Registers the analyzer and synchronizes documentation while marking CI enforcement as deferred.
| File | Description |
|---|---|
pkg/linters/splitlines-on-newline/testdata/src/splitlinesonnewline/suppressed.go |
Tests explicit suppression. |
pkg/linters/splitlines-on-newline/testdata/src/splitlinesonnewline/splitlines.go |
Covers matching calls and excluded patterns. |
pkg/linters/splitlines-on-newline/testdata/src/splitlinesonnewline/generated.go |
Tests generated-file exclusion. |
pkg/linters/splitlines-on-newline/splitlines_on_newline.go |
Implements detection and diagnostics. |
pkg/linters/splitlines-on-newline/splitlines_on_newline_test.go |
Runs analyzer fixture tests. |
pkg/linters/spec_test.go |
Adds the analyzer to documentation/API checks. |
pkg/linters/registry.go |
Registers the analyzer in the canonical list. |
pkg/linters/README.md |
Documents the analyzer and its public API. |
pkg/linters/doc.go |
Updates the package’s analyzer inventory. |
pkg/linters/doc_sync_test.go |
Records deferred enforcement and maps the documentation slug. |
Review effort: Balanced (auto)
There was a problem hiding this comment.
Skills-Based Review 🧠
Applied /tdd and /codebase-design. Verdict: COMMENT, no blocking issues.
The analyzer logic holds up. The separator is matched by type-checked constant value, and the strings package is resolved by import path, so aliases work and shadowed names do not match. nolint and generated-file handling are wired like sibling analyzers. go test ./pkg/linters/... passes and gofmt is clean. I also confirmed with a temporary test that a local variable named strings produces no diagnostic, then removed it.
Correction to my inline README comment: the import belongs immediately before sprintfbool, not between sprintfint and ssljson. splitlines sorts before sprintf because l comes before r. registry.go is already correct.
📋 Key Themes
- Test gap: no negative case for a shadowed
stringsidentifier (inline comment onsplitlines.go) - Doc ordering: the import and
_ =lines in the README snippet are out of order (inline comment onREADME.md)
@copilot please address the review comments above.
🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · copilot · routed: haiku55 xhigh · ~4 AIC · ⌖ ~2 AIC · ⊞ 5.4K
Comment /matt to run again
| "github.com/github/gh-aw/pkg/linters/sprintfbool" | ||
| "github.com/github/gh-aw/pkg/linters/sprintfint" | ||
| "github.com/github/gh-aw/pkg/linters/ssljson" | ||
| "github.com/github/gh-aw/pkg/linters/splitlines-on-newline" |
There was a problem hiding this comment.
[/codebase-design] Import order is off: splitlines-on-newline sorts before ssljson (sp < ss), so it belongs between sprintfint and ssljson. The matching _ = splitlinesonnewline.Analyzer line in this snippet has the same problem. registry.go already has the correct order, so this snippet should mirror it.
@copilot please address this.
There was a problem hiding this comment.
Moved the import and analyzer reference ahead of ssljson as requested. Commit 13d801c.
| return nil | ||
| } | ||
|
|
||
| func goodUserDefinedSplit(input string) { |
There was a problem hiding this comment.
[/tdd] Missing negative case: no test covers a local variable that shadows the strings package. splitindexzero has one (shadowedPackageName). The current IsPkgSelector check already handles this correctly, so this is a regression guard rather than a bug.
💡 Suggested test case
func goodShadowedPackageName(input string) {
strings := customSplitter{}
strings.Split(input, "\n")
}@copilot please address this.
There was a problem hiding this comment.
Added a negative fixture for a local strings variable that shadows the package. Commit 13d801c.
|
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: f16edb5
|
Co-authored-by: gh-aw-bot <[email protected]>
|
🎉 This pull request is included in a new release. Release: |
strings.Split(s, "\n")can retain carriage returns on CRLF input and add a trailing empty element for newline-terminated input. This adds a type-checked analyzer for those calls, including aliasedstringsimports and named newline constants.Splitmethods, generated files, andnolint:splitlinesonnewlinesuppressions.