Skip to content

Implement -fix flag for go-exhaustruct#152

Draft
jay-babu wants to merge 4 commits into
GaijinEntertainment:masterfrom
jay-babu:claude/implement-exhaustruct-fix-flag-UW6s9
Draft

Implement -fix flag for go-exhaustruct#152
jay-babu wants to merge 4 commits into
GaijinEntertainment:masterfrom
jay-babu:claude/implement-exhaustruct-fix-flag-UW6s9

Conversation

@jay-babu

Copy link
Copy Markdown

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 #151

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
@jay-babu

Copy link
Copy Markdown
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.
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.

[Feature]: Support for fix flag

2 participants