Skip to content

refactor(stringutil): extract isASCIIAlphanumeric helper in sanitize.go#47455

Merged
pelikhan merged 2 commits into
mainfrom
copilot/refactor-stringutil-duplicate-checks
Jul 23, 2026
Merged

refactor(stringutil): extract isASCIIAlphanumeric helper in sanitize.go#47455
pelikhan merged 2 commits into
mainfrom
copilot/refactor-stringutil-duplicate-checks

Conversation

Copilot AI commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

sanitize.go had two functions open-coding the identical ASCII alphanumeric rune test, creating divergence risk for the character-class definition.

Changes

  • pkg/stringutil/sanitize.go — adds unexported helper isASCIIAlphanumeric(r rune) bool and replaces the duplicated inline expressions in SanitizeIdentifierName and SanitizeForFilename:
func isASCIIAlphanumeric(r rune) bool {
    return (r >= 'a' && r <= 'z') || (r >= 'A' && r <= 'Z') || (r >= '0' && r <= '9')
}

// SanitizeIdentifierName
if isASCIIAlphanumeric(r) || r == '_' { ... }

// SanitizeForFilename
if isASCIIAlphanumeric(r) || r == '-' || r == '_' || r == '.' { ... }

Purely mechanical, behavior-preserving; existing tests cover both call sites.

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor stringutil to consolidate duplicated ASCII-alphanumeric checks refactor(stringutil): extract isASCIIAlphanumeric helper in sanitize.go Jul 23, 2026
Copilot AI requested a review from pelikhan July 23, 2026 04:58
@pelikhan
pelikhan marked this pull request as ready for review July 23, 2026 05:10
Copilot AI review requested due to automatic review settings July 23, 2026 05:10

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.

Pull request overview

Extracts a shared ASCII alphanumeric check to reduce duplicated sanitization logic without changing behavior.

Changes:

  • Adds isASCIIAlphanumeric.
  • Reuses it in both identifier and filename sanitizers.
Show a summary per file
File Description
pkg/stringutil/sanitize.go Consolidates duplicate character validation logic.

Review details

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 1/1 changed files
  • Comments generated: 0
  • Review effort level: Medium

@github-actions

github-actions Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Design Decision Gate 🏗️ completed the design decision gate check.

No ADR enforcement needed: PR #47455 does not have the 'implementation' label and has only 7 new lines of code in business logic directories (threshold: 100).

@github-actions

github-actions Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

PR Code Quality Reviewer completed the code quality review.

@github-actions

github-actions Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Test Quality Sentinel completed test quality analysis.

No test files were added or modified in this PR. Test Quality Sentinel skipped.

@github-actions

github-actions Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

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

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

Clean refactor — the extracted isASCIIAlphanumeric helper correctly mirrors the original inline conditions and is applied consistently at both call sites. No logic changes, no issues found.

🧵 Reviewed using Impeccable skills by Impeccable Skills Reviewer · sonnet46 8.87 AIC · ⌖ 5.1 AIC · ⊞ 5K

@github-actions github-actions Bot mentioned this pull request Jul 23, 2026

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

Clean refactor — approved

Extracting isASCIIAlphanumeric is a correct, behavior-preserving deduplication. Both call sites updated properly, helper is appropriately unexported, and existing tests cover both paths. No issues found.

🔎 Code quality review by PR Code Quality Reviewer · sonnet46 17.9 AIC · ⌖ 4.47 AIC · ⊞ 5.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.

Skills-Based Review 🧠

Applied /codebase-design — the extraction is clean and behavior-preserving. ✅

📋 Key Themes & Highlights

Positive Highlights

  • ✅ Single, clear definition of the ASCII alphanumeric character class — eliminates divergence risk
  • ✅ Unexported helper keeps the interface surface minimal
  • ✅ Both call sites are mechanically correct after the substitution
  • ✅ Comment on the helper accurately describes its contract

Minor Observation

The helper isASCIIAlphanumeric is not directly unit-tested; it is exercised indirectly through SanitizeIdentifierName and SanitizeForFilename. That is acceptable for a small private helper, but a direct test would lock in the boundary conditions ('0', '9', 'a', 'z', 'A', 'Z', and one character outside each range) and make the contract self-documenting.

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · sonnet46 17.4 AIC · ⌖ 4.54 AIC · ⊞ 6.7K
Comment /matt to run again

@pelikhan
pelikhan merged commit 5183022 into main Jul 23, 2026
71 of 82 checks passed
@pelikhan
pelikhan deleted the copilot/refactor-stringutil-duplicate-checks branch July 23, 2026 05:22
@github-actions

Copy link
Copy Markdown
Contributor

🎉 This pull request is included in a new release.

Release: v0.83.1

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.

[refactor] stringutil: consolidate duplicated inline ASCII-alphanumeric rune checks

3 participants