Skip to content

Commit

Permalink
Merge pull request #7 from g4s8/empty-doc-panic
Browse files Browse the repository at this point in the history
fix: don't panic on empty field doc
  • Loading branch information
g4s8 authored Feb 6, 2024
2 parents 445e54b + 27688e4 commit 1b8b8fb
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
7 changes: 4 additions & 3 deletions inspector.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,11 +235,12 @@ func (i *inspector) parseField(f *ast.Field) (out []envField) {
item.typeRef = fieldType.Name
case *ast.StructType:
nameGen := fastRandString(16)
i.getStruct(&ast.TypeSpec{
typeSpec := &ast.TypeSpec{
Name: &ast.Ident{Name: nameGen},
Type: fieldType,
Doc: &ast.CommentGroup{List: f.Doc.List},
})
Doc: f.Doc,
}
i.getStruct(typeSpec)
item.typeRef = nameGen
posRange := [2]token.Pos{fieldType.Pos(), fieldType.End()}
i.anonymousStructs[posRange] = anonymousStruct{
Expand Down
14 changes: 14 additions & 0 deletions inspector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,20 @@ func TestInspector(t *testing.T) {
},
},
},
{
name: "nodocs.go",
typeName: "Config",
expect: []EnvDocItem{
{
Children: []EnvDocItem{
{
Name: "REPO_CONN",
Opts: EnvVarOptions{Required: true, NonEmpty: true},
},
},
},
},
},
} {
scopes := c.expectScopes
if scopes == nil {
Expand Down
7 changes: 7 additions & 0 deletions testdata/nodocs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package main

type Config struct {
Repo struct {
Conn string `env:"CONN,notEmpty"`
} `envPrefix:"REPO_"`
}

0 comments on commit 1b8b8fb

Please sign in to comment.