Conversation
bbengfort
commented
Apr 7, 2026
Comment on lines
+63
to
+68
| // TODO: use the packages.NeedsSyntax mode to get the ast and find the | ||
| // CompositeLit that represents the names variable. You can then use its Elts | ||
| // property to get the number of elements and compare that to the number of | ||
| // constants. Unfortunately, there is no mapping from a types.Object to an | ||
| // ast.Node to do checking if it is an ast.CompositeLit so ast traversal is | ||
| // required, which is a bit too far for me to implement right now. |
Contributor
Author
There was a problem hiding this comment.
@chris-okuda if you ever have the urge to do AST traversal …
There was a problem hiding this comment.
@bbengfort I've been reading about code gen with Go, so I'm ready for whatever task you have for me!
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.
Scope of changes
Uses AST to discover Enum types, their constants, and name values.
Estimated PR Size:
Acceptance criteria
This PR will be merged without review.
Author checklist
Note
Medium Risk
Medium risk because it changes core code-generation discovery logic (package loading, type/const detection, names-variable resolution), which can affect what gets generated and where. Failures will surface at build/generate time but could be subtle across different package/file layouts.
Overview
enumify.Generate/GenerateTestsnow create*_gen.goand*_gen_test.goviagithub.com/dave/jennifer/jen, and introduce file naming helpers based on the triggering$GOFILE.The generator adds a
go/packages/go/typesdiscovery phase (Options.discover) that finds enum types by underlyinguint8, collects their typedconstvalues, auto-detects[Type]Namesvariables (1D/2D string slices/arrays), supports an explicit-namesoverride, and validates required invariants (names var present, zero const present, etc.).Examples are adjusted/expanded (new
calendar.gowith array-backed names and an additionalMonthenum;status.goadds a non-enum type to ensure it’s ignored), and generated example*_gen_test.gofiles are now gitignored;go.mod/go.sumaddjenniferandgolang.org/x/toolsdependencies.Reviewed by Cursor Bugbot for commit fba82e8. Configure here.