refactor(strcase,BREAKING!): adopt STYLE2024 case conversion rules#405
Open
Kybxd wants to merge 2 commits into
Open
refactor(strcase,BREAKING!): adopt STYLE2024 case conversion rules#405Kybxd wants to merge 2 commits into
Kybxd wants to merge 2 commits into
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #405 +/- ##
==========================================
+ Coverage 74.83% 75.09% +0.25%
==========================================
Files 88 90 +2
Lines 9372 9536 +164
==========================================
+ Hits 7014 7161 +147
- Misses 1785 1795 +10
- Partials 573 580 +7 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Member
|
Due to Edition 2024: features.enforce_naming_style
So if tableau support the new naming style, it shoud be enabled by config options. |
|
The latest Buf updates on your PR. Results from workflow Buf CI / buf (pull_request).
|
Rewrite the strcase package so that all case conversions follow the Protobuf STYLE2024 guide (https://protobuf.dev/programming-guides/style/): - Underscores are only allowed in front of a letter, so digit boundaries no longer get an underscore (e.g. "Tier1" -> "tier1", not "tier_1"). - Acronyms are treated as ordinary words (e.g. "JSONData" -> "json_data", "userID" -> "user_id"). Public API changes: - ToPascal / ToCamel / ToSnake / ToScreamingSnake are reimplemented on a new chunk-based algorithm in camel.go / snake.go. ToCamel now produces "anyKindOfString" (was the previous ToLowerCamel semantics); the unused ToLowerCamel / ToKebab / ToDelimited variants are dropped. - Add EnumValue(enumName, value) helper (internal/strcase/enum_value.go) that builds STYLE2024-compliant enum value names: prefixes the value with UPPER_SNAKE_CASE(enumName) and inserts a leading "V" when the value would otherwise start with a digit (e.g. EnumValue("DeviceTier", "1") -> "DEVICE_TIER_V1"). - Update doc.go / README.md and rewrite snake/camel tests against the new rules; add enum_value_test.go. Call sites: - internal/confgen: switch ToCamel -> ToPascal for default field name and union type-column / type-node lookup. - internal/protogen/exporter: build union enum value names via EnumValue("Type", field.Name); use ToPascal to derive the union message type when no explicit type is given. - internal/protogen/sheet_mode: enum value naming goes through EnumValue(ws.Name, value.Name); the ad-hoc prefix logic is removed. - internal/tools/cmd/ecode: use ToCamel directly for goName. Options: - Deprecate ProtoOutputOption.EnumValueWithPrefix. STYLE2024 mandates the prefix unconditionally, so the option is now a no-op and only kept for config-schema backward compatibility. Remove its usage from the functional test setup. Test fixtures regenerated to reflect the new naming: - Rename csv__bom__utf_8_bom.proto -> csv__bom__utf8_bom.proto and excel__metasheet__merger_1/scatter_1.proto -> *_merger1/scatter1.proto (digits no longer separated by underscore). - Update generated .proto files under test/functest/proto/default/* for fields/enum values whose case form changed under STYLE2024.
Introduce a legacy mode in the strcase package to allow existing projects to opt back into the pre-STYLE2024 naming algorithm. This mode is gated by the `useLegacyNamingStyle` option and is force-disabled when the requested proto edition is >= 2024. Key changes: - Change proto edition type from string to int for proper numeric comparison against the STYLE2024 edition threshold. - Add legacy implementations for camel, snake, and enum value conversions, porting the old byte-walking algorithms. - Make `EnumValueWithPrefix` conditional under legacy mode, matching the historical behavior where prefixing was opt-in. - Update all strcase tests to run cases against both STYLE2024 and legacy engines side-by-side.
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.
Motivation
The
internal/strcasepackage was forked long ago fromiancoleman/strcaseand produced names that diverge from the Protobuf STYLE2024 and Edition 2024: features.enforce_naming_style guide:Tier1→tier_1), which STYLE2024 explicitly forbids.JSONData→ various forms depending on the acronym table) instead of as ordinary words.ToLowerCamel,ToKebab,ToDelimited, …) inherited from upstream.Meanwhile downstream code (
protogen,confgen) kept patching around these rough edges with ad-hoc prefix logic andToCamel/ToPascalswaps. This MR reworks the package to STYLE2024 in one place, removes the workarounds at call sites, and regenerates the affected test fixtures.What changes
internal/strcase— core rewriteNew chunk-based PascalCase / snake_case algorithm in
camel.go/snake.go. STYLE2024 invariants:Tier1→tier1, nevertier_1).GetDnsRequest/dns_request,userID→user_id).Public API trimmed to the four conversions actually needed:
ToPascal(s)AnyKindOfStringToCamel(s)anyKindOfStringToSnake(s)any_kind_of_stringToScreamingSnake(s)ANY_KIND_OF_STRINGToCamelnow producesanyKindOfString(i.e. previousToLowerCamelsemantics).ToLowerCamel,ToKebab,ToScreamingKebab,ToDelimited,ToScreamingDelimited,ToSnakeWithIgnoreare removed.New helper
EnumValue(enumName, value)(enum_value.go) producing STYLE2024-compliant enum value names: prefixes withUPPER_SNAKE_CASE(enumName), normalizes the value, and inserts a leadingVwhen the value would otherwise start with a digit. Examples:doc.go/README.mdrewritten to describe the STYLE2024 contract and the (now smaller) public surface.Tests rewritten against the new rules; new
enum_value_test.gocoversEnumValueplus an acronym-context regression case.Call sites updated to use the new API
internal/confgen(util.go,table_parser.go,document_parser.go): default field/column/node name derivation switches fromToCameltoToPascalso the proto fieldhero_idcontinues to map to the sheet/document nameHeroIdunder the new rules.internal/protogen/exporter.go: union enum value names go throughEnumValue("Type", field.Name); when an explicit message type is not provided, the type name is derived viaToPascal(field.Name).internal/protogen/sheet_mode.go: enum value naming for sheet-mode enums goes throughEnumValue(ws.Name, value.Name); the ad-hoc prefix-prepend logic is removed.internal/tools/cmd/ecode/main.go: directly usesToCamelfor the Go field name (replaces the previous PascalCase + manual lower-first hack).Options — deprecation
options.ProtoOutputOption.EnumValueWithPrefixis deprecated and now a no-op. STYLE2024 mandates the enum-name prefix unconditionally, so the option no longer makes sense. The field is kept for config-schema backward compatibility; updated godoc reflects this. The functional test setup (test/functest/util.go) drops its usage.Breaking changes
This MR will change generated
.protocontent for any sheet whose names contain digit-letter junctions, all-caps acronyms, or rely on the ad-hoc enum prefix toggle. Concretely:csv__bom__utf_8_bom.proto→csv__bom__utf8_bom.protoexcel__metasheet__merger_1.proto→excel__metasheet__merger1.protoexcel__metasheet__scatter_1.proto→excel__metasheet__scatter1.prototest/functest/proto/default/*).EnumValueWithPrefix = falseno longer suppresses the prefix; downstream users relying on the unprefixed form must regenerate.strcasesymbols (ToLowerCamel,ToKebab,ToDelimited, …): no internal user remains, but external embedders ofinternal/strcase(if any) need to migrate to the four supported conversions.