Implement -fix flag for go-exhaustruct#152
Draft
jay-babu wants to merge 4 commits into
Draft
Conversation
Implement suggested fixes for the exhaustruct analyzer that automatically add missing struct fields with their zero values when using the -fix flag. Changes: - Add internal/fix package with fix generation logic - Add Type field to structure.Field to enable zero value generation - Update analyzer to use pass.Report() with SuggestedFixes - Support both single-line and multiline composite literals - Generate proper zero values for all Go types (basic, pointers, slices, maps, channels, functions, interfaces, arrays, and structs) - Add tests for zero value generation Closes GaijinEntertainment#151
Author
|
This is fully vibe coded |
Add test coverage for nested struct types including:
- Direct nested structs (Nested{})
- Deeply nested structs (DeepNested{})
- Pointers to nested structs (nil)
- Slices of nested structs (nil)
- Maps with nested struct values (nil)
Update test structs to have multiple fields each:
- Nested: Value, Name, Enabled
- DeepNested: Inner, Label, Count, Tags
This verifies the fix correctly generates empty composite literals
(e.g., Nested{}) for nested struct types, which Go automatically
initializes with zero values for all fields.
Apply automatic fixes for missing struct fields in external types: - analysis.Analyzer, analysis.Diagnostic - packages.Config - ast.Comment, ast.CompositeLit This dogfoods the new -fix functionality on the codebase itself.
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.
Implement suggested fixes for the exhaustruct analyzer that automatically add missing struct fields with their zero values when using the -fix flag.
Changes:
Closes #151