Unexport internal constants to match upstream Java visibility#262
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Final API/cruft pass ahead of the v2.0.0 tag.
What
private/package-private. These are now unexported so the package's public surface mirrors the Java API. The only exported constant is nowREGION_CODE_FOR_NON_GEO_ENTITY(the solepublic static finalupstream, referenced cross-package bygeocodingexactly as the Java geocoder references it). The Go-idiomaticErr*values (standing in for Java's checked exceptions) and the public enum types remain exported.alphaMappings(vestigial — the combinedalphaPhoneMappingsmap is defined inline rather than amalgamated like the Java) anddigitsPattern(an unused sibling ofnonDigitsPattern).Leniencydoc comments (replacing a staleTODO), dropped the other leftoverTODO(ttacon)markers, switched one matcher regex to a raw-string literal, and rewrote two doc-comment examples from leaked Java syntax into idiomatic Go.sync-upstreamskill so a future sync won't re-export a new private constant.Why
The module is already on the
/v2import 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 withgofmt -r(strings/comments untouched), using lower-camelCase to match house style.Reviewer notes
BREAKING CHANGE:trailer on the commit, and worth a line in the v2.0.0 release notes).CHANGELOG.mdis intentionally left untouched.gofmt/go build/go vetclean;go test -p=1 -count=1 ./...andgo test -race .green.staticcheckstill reports threeU1000"unused" forgetExtractedNationalPrefix,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.