Skip to content

Conversation

@umputun
Copy link
Member

@umputun umputun commented Nov 29, 2025

Summary

  • Adds support for comment annotations on enum constants to define parsing aliases
  • Enables parsing multiple string representations for the same enum value
  • Fixes bug where lowercase mode didn't properly normalize input for case-insensitive parsing
  • Parsing is now always case-insensitive regardless of -lower flag

Changes

  • parseAliasComment() function extracts aliases from inline comments
  • validateAliases() method checks for conflicts with canonical names and duplicate aliases
  • Template updated to include aliases in parse map with duplicate key prevention
  • Parsing always uses strings.ToLower(v) for case-insensitive lookup
  • Comprehensive tests added (99.3% coverage)
  • README updated with alias documentation

allows enum constants to have comment annotations like
// enum:alias=rw,read-write that enable parsing multiple
string representations for the same enum value.

- add parseAliasComment() to extract aliases from inline comments
- add validateAliases() to check for conflicts and duplicates
- update template to include aliases in parse map
- make parsing always case-insensitive (fixes lowercase mode bug)
- add comprehensive tests for alias feature
- update README with alias documentation
@umputun umputun requested a review from Copilot November 29, 2025 21:50
@umputun umputun self-assigned this Nov 29, 2025
@umputun umputun added the enhancement New feature or request label Nov 29, 2025
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds support for parsing aliases on enum constants, enabling multiple string representations to map to the same enum value. The implementation also fixes a bug where case-insensitive parsing wasn't working correctly in lowercase mode.

Key Changes:

  • Added parseAliasComment() function to extract aliases from inline comments using enum:alias= directive
  • Added validateAliases() to prevent duplicate aliases and conflicts with canonical names
  • Modified parsing to always be case-insensitive using strings.ToLower(v) regardless of -lower flag
  • Updated template to include aliases in parse map with duplicate key prevention logic
  • Added comprehensive test coverage for alias functionality

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.

Show a summary per file
File Description
internal/generator/generator.go Core implementation of alias parsing, validation, and storage in constValue/Value structs
internal/generator/enum.go.tmpl Updated template to generate parse map with aliases and always use case-insensitive lookup
internal/generator/generator_test.go Added comprehensive unit tests for alias parsing, validation, and generation
internal/generator/integration_test.go Added integration test for alias functionality
internal/generator/testdata/integration/status_enum.go Updated generated code to reflect new case-insensitive parsing behavior
internal/generator/testdata/integration/priority_enum.go Fixed import ordering (standard library before third-party)
internal/generator/testdata/integration/permission.go Added test enum with aliases for integration testing
README.md Added comprehensive documentation for alias feature with examples and usage rules

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

@umputun umputun merged commit 9cda39d into master Nov 29, 2025
8 checks passed
@umputun umputun deleted the feature/alias-support branch November 29, 2025 21:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants