Skip to content

Unexport internal constants to match upstream Java visibility#262

Merged
rowanseymour merged 1 commit into
mainfrom
chore/trim-public-api-for-v2
Jun 4, 2026
Merged

Unexport internal constants to match upstream Java visibility#262
rowanseymour merged 1 commit into
mainfrom
chore/trim-public-api-for-v2

Conversation

@rowanseymour

Copy link
Copy Markdown
Member

Final API/cruft pass ahead of the v2.0.0 tag.

What

  • Unexport ~63 Java-private internals. The port historically exported a large set of package-level constants, regex patterns, and mapping tables that libphonenumber's Java reference keeps private/package-private. These are now unexported so the package's public surface mirrors the Java API. The only exported constant is now REGION_CODE_FOR_NON_GEO_ENTITY (the sole public static final upstream, referenced cross-package by geocoding exactly as the Java geocoder references it). The Go-idiomatic Err* values (standing in for Java's checked exceptions) and the public enum types remain exported.
  • Remove two dead vars surfaced by the unexport: alphaMappings (vestigial — the combined alphaPhoneMappings map is defined inline rather than amalgamated like the Java) and digitsPattern (an unused sibling of nonDigitsPattern).
  • Minor cleanups: ported the Leniency doc comments (replacing a stale TODO), dropped the other leftover TODO(ttacon) markers, switched one matcher regex to a raw-string literal, and rewrote two doc-comment examples from leaked Java syntax into idiomatic Go.
  • Guardrail: added a "Mirror Java's visibility" rule to the sync-upstream skill so a future sync won't re-export a new private constant.

Why

The module is already on the /v2 import path, so the major bump is the natural moment to trim the public surface to match the strict-port philosophy. The renames were done AST-safely with gofmt -r (strings/comments untouched), using lower-camelCase to match house style.

Reviewer notes

  • ⚠️ Breaking change — previously-exported internal constants are now unexported (carried as a BREAKING CHANGE: trailer on the commit, and worth a line in the v2.0.0 release notes). CHANGELOG.md is intentionally left untouched.
  • Verification: gofmt/go build/go vet clean; go test -p=1 -count=1 ./... and go test -race . green.
  • staticcheck still reports three U1000 "unused" for getExtractedNationalPrefix, getExampleShortNumber, getExampleShortNumberForCost — these are false positives (all used by tests, mirroring Java's @VisibleForTesting); staticcheck's test analysis is degraded by a go1.26 stdlib compile error in the local toolchain.

The port historically exported ~60 package-level constants, regex
patterns, and mapping tables that libphonenumber's Java reference keeps
private or package-private. Ahead of the v2 major release, unexport
everything that is not public upstream so the package's public surface
mirrors the Java API.

The only exported constant is now REGION_CODE_FOR_NON_GEO_ENTITY (the
sole public static final upstream); the Err* values and the public enum
types remain exported.

Also:
- remove two now-dead package vars surfaced by the unexport
  (alphaMappings, vestigial since the combined map is defined inline;
  digitsPattern, an unused sibling of nonDigitsPattern)
- port the Leniency doc comments and drop stale TODO markers
- use a raw-string literal for one matcher regex
- rewrite two doc-comment examples in idiomatic Go
- document the visibility rule in the sync-upstream skill

BREAKING CHANGE: previously-exported internal constants are now
unexported.
@rowanseymour rowanseymour merged commit ad15837 into main Jun 4, 2026
6 checks passed
@rowanseymour rowanseymour deleted the chore/trim-public-api-for-v2 branch June 4, 2026 01:39
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.

1 participant