Skip to content

[linter-miner] Add splitlines-on-newline custom analyzer - #75820

Merged
pelikhan merged 3 commits into
mainfrom
copilot/linter-minersplitlines-on-newline-5a4a01e0cbf1e9f5
Nov 8, 2026
Merged

pelikhan merged 3 commits into
mainfrom
copilot/linter-minersplitlines-on-newline-5a4a01e0cbf1e9f5

Conversation

Copilot AI commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

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 aliased strings imports and named newline constants.

  • Analyzer: Skips other or non-constant separators, user-defined Split methods, generated files, and nolint:splitlinesonnewline suppressions.
  • Registration and docs: Adds the analyzer to the canonical registry and synchronizes its API and package documentation.
  • CI rollout: Records the analyzer as not yet enforced while existing production uses are remediated.
const newline = "\n"

lines := strings.Split(input, newline) // flagged

Copilot AI changed the title [WIP] Add splitlines-on-newline custom analyzer [linter-miner] Add splitlines-on-newline custom analyzer Nov 8, 2026
Copilot AI requested a review from gh-aw-bot November 8, 2026 04:43
@pelikhan
pelikhan marked this pull request as ready for review November 8, 2026 06:06
Copilot AI adaptive review requested due to automatic review settings November 8, 2026 06:06
@github-actions

github-actions Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ PR Code Quality Reviewer failed to deliver outputs during code quality review.

🔎 Code quality review by PR Code Quality Reviewer

@github-actions

github-actions Bot commented Nov 8, 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 8, 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 8, 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 #75820

@github-actions

github-actions Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

✅ Ponytail Reviewer completed successfully!

Generated by Ponytail Reviewer for #75820

@github-actions

github-actions Bot commented Nov 8, 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 8, 2026

Copy link
Copy Markdown
Contributor

Comment Memory

Peek at saved memory (pr-code-quality-reviewer)
reviewed_at: 2026-11-08T06:09:05Z
review_event: COMMENT
top_themes: scanner guidance can introduce token-limit and semantic regressions
files_reviewed: pkg/linters/splitlines-on-newline/splitlines_on_newline.go, pkg/linters/README.md, pkg/linters/doc.go, pkg/linters/registry.go, pkg/linters/spec_test.go, pkg/linters/doc_sync_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.

🔎 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",

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

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.

Updated the diagnostic to recommend normalizing line endings or trimming carriage returns from each line; it no longer suggests Scanner. Commit 13d801c.

@github-actions

github-actions Bot commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Warning

The push_to_pull_request_branch operation failed: Cannot verify branch protection rules for "copilot/linter-minersplitlines-on-newline-5a4a01e0cbf1e9f5": 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 makes significant changes to core business logic (155 new lines under pkg/) but does not have a linked Architecture Decision Record (ADR).

📄 Draft ADR committed: docs/adr/75820-add-splitlines-on-newline-analyzer.md. Review and complete it before merging.

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

Key decisions in the draft: a type-aware splitlinesonnewline analyzer that reports diagnostics only (no autofix). It is registered as not yet enforced, and it uses a hyphenated package directory and doc slug that need a special case in docSlugToAnalyzerName.

📋 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: add context the AI could not infer, refine the decision rationale, and confirm the alternatives (autofix, immediate enforcement, regex-based check). In particular, confirm the reason for the hyphenated splitlines-on-newline package name.

  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-75820: Add splitlines-on-newline Analyzer (link unavailable: invalid HTTPS URL)

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

"AI made me procrastinate on key design decisions. Because refactoring was cheap, I could always say 'I'll deal with this later.' Deferring decisions corroded my ability to think clearly."

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 · ~31 AIC · ⌖ ~2 AIC · ⊞ 7.7K · ◷
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.

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:

  1. Reuse the existing strings-call matcher (pkg/linters/splitlines-on-newline/splitlines_on_newline.go:L54)

    • What this is: isStringsSplit recognizes a strings.Split call.
    • Problem: Its selector unwrapping and package check duplicate astutil.AsStringsMethodCall, already used by stringssplitfirst and covered by shared tests. The argument-count guard is also repeated in hasNewlineSeparator.
    • 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.

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 {

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.

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.

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.

Replaced the local matcher with astutil.AsStringsMethodCall and retained one argument-count check. Commit 13d801c.

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

@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 /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 strings identifier (inline comment on splitlines.go)
  • Doc ordering: the import and _ = lines in the README snippet are out of order (inline comment on README.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

Comment thread pkg/linters/README.md
"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"

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.

[/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.

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.

Moved the import and analyzer reference ahead of ssljson as requested. Commit 13d801c.

return nil
}

func goodUserDefinedSplit(input string) {

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.

[/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.

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.

Added a negative fixture for a local strings variable that shadows the package. Commit 13d801c.

@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/splitlines-on-newline/splitlines_on_newline.go:49): 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. - [linter-miner] Add splitlines-on-newline custom analyzer #75820 (comment)
  3. Review (pkg/linters/splitlines-on-newline/splitlines_on_newline.go:54): 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. - [linter-miner] Add splitlines-on-newline custom analyzer #75820 (comment)
  4. Review (pkg/linters/README.md:310): [/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. - [linter-miner] Add splitlines-on-newline custom analyzer #75820 (comment)
  5. Review (pkg/linters/splitlines-on-newline/testdata/src/splitlinesonnewline/splitlines.go:35): [/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. - [linter-miner] Add splitlines-on-newline custom analyzer #75820 (comment)
  6. Fix failing check safe_outputs (FAILURE): https://github.com/github/gh-aw/actions/runs/42453377640/job/128648204625.
  7. Fix failing check safe_outputs (FAILURE): https://github.com/github/gh-aw/actions/runs/42453377632/job/128648198417.

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
Sous-chef requested-work: 43217f512450c3f6013464ece1e60962647b7a42a56b8890683d888ad70633a7 91ee2ae7ade10a612b53142423b1c9b0c7543a048a6559258279d6f8c550262f 9c0ba7cf8aa4740a25e333e13647d71b0db03bdbb083e34e8f7068afd18c58f5 c501119f9435f007a2147b84bbc745388f11468b455f36b9c803d401217392ea c7cf93e497befdd5e698d00101b0703e4101fe4133d86d433f7c170d07402b7e
Sous-chef requested-state: 1a8b9920d48e667b39127f04f2f0f08f6214cc87a2bb9ecca3ea3ec6090629e5

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

@pelikhan
pelikhan merged commit 57111b2 into main Nov 8, 2026
82 checks passed
@pelikhan
pelikhan deleted the copilot/linter-minersplitlines-on-newline-5a4a01e0cbf1e9f5 branch November 8, 2026 08:30
@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 splitlines-on-newline custom analyzer

4 participants