Skip to content

Conversation

@codemageddon
Copy link
Contributor

This pull request adds support for multi-word named types (for example, jobStatus). Although these types remain private, the previous version treated them as errors.

@codemageddon codemageddon requested a review from umputun as a code owner March 28, 2025 20:10
@codemageddon codemageddon changed the title Add support for complext type names Add support for complex type names Mar 28, 2025
@umputun umputun requested a review from Copilot March 29, 2025 17:40
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 pull request adds support for multi-word named types, allowing enum generators to process types such as "jobStatus" rather than treating them as errors.

  • Added support for complex (camel case) type names in the generator
  • Introduced helper functions (splitCamelCase, getFileNameForType) to handle name conversions
  • Updated tests and examples to cover the new behavior

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
internal/generator/testdata/job_status.go Added test data for multi-word type "jobStatus"
internal/generator/generator_test.go Extended tests to cover generation with complex names
internal/generator/generator.go Modified title casing and output naming functions; added helper functions for name conversion
_examples/status/status.go Updated go:generate comments and added multi-word type definition
_examples/status/job_status_test.go Added tests for the new multi-word enum type
_examples/status/job_status_enum.go Generated enum code for "jobStatus" with new parsing logic
README.md Updated generator option description for type naming
Comments suppressed due to low confidence (1)

internal/generator/generator.go:243

  • [nitpick] The comment for getFileNameForType uses an example 'JobStatus', but the generator expects a private (lowercase) type name. Consider updating the comment to clarify the expected input case.
// getFileNameForType returns the file name for the generated enum code based on the type name.

@codemageddon codemageddon force-pushed the support-for-complex-type-names branch from 4381757 to 1bca6b0 Compare March 29, 2025 18:48
@codemageddon codemageddon force-pushed the support-for-complex-type-names branch from 1bca6b0 to 0b753d7 Compare March 29, 2025 18:49
@umputun umputun requested a review from Copilot March 29, 2025 19:32
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 pull request adds support for multi-word named types, enabling the generator to correctly process types like "jobStatus" that were previously treated as errors. Key changes include:

  • Adding a new testdata file and examples for the multi-word type "jobStatus".
  • Updating the generator logic to derive snake_case file names from camel-cased type names.
  • Extending tests and documentation to support and ensure proper functionality for complex type names.

Reviewed Changes

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

Show a summary per file
File Description
internal/generator/testdata/job_status.go Added a sample multi-word named type for testing.
internal/generator/generator_test.go Updated tests to verify generation with complex type names.
internal/generator/generator.go Modified type name validation and file name generation using splitCamelCase.
_examples/status/status.go Added a new go:generate directive and jobStatus type example.
_examples/status/job_status_test.go Introduced tests covering enum behavior for the jobStatus type.
_examples/status/job_status_enum.go Generated enum code for the jobStatus type.
README.md Updated generator options description regarding type privacy.
Comments suppressed due to low confidence (3)

internal/generator/generator.go:48

  • The check for lowercase only inspects the first character of the type name. If multi-word type names are expected to include uppercase letters internally, consider clarifying in the error message or inline documentation that only the initial character is validated.
if !unicode.IsLower(rune(typeName[0])) {

internal/generator/generator.go:24

  • [nitpick] Consider adding a comment to explain the use of 'cases.NoLower', so future maintainers understand how it affects the title casing of complex type names.
var titleCaser = cases.Title(language.English, cases.NoLower)

README.md:89

  • [nitpick] The README mentions that the type must be private but does not specify that only the first character's case is enforced. Consider clarifying that the enforcement only requires the first letter to be lowercase for supporting multi-word type names.
- `-type` (required): the name of the type to generate enum for (must be private)

Copy link
Member

@umputun umputun left a comment

Choose a reason for hiding this comment

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

LGTM, thx!

@umputun umputun merged commit d6a3d14 into go-pkgz:master Mar 29, 2025
2 checks passed
@codemageddon codemageddon deleted the support-for-complex-type-names branch April 1, 2025 09:32
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.

2 participants