Skip to content

Commit

Permalink
fix: skip function declarations for ast parser
Browse files Browse the repository at this point in the history
Skip `FuncDect` because funcs may declare fields inside it, where
fields could be handled as a part of current type.

Fix: #28
  • Loading branch information
g4s8 committed Apr 24, 2024
1 parent f917c17 commit 9099fd8
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ func (v *astVisitor) Visit(n ast.Node) ast.Visitor {
fieldNode.typeName = expr.Name
}
return v.push(fieldNode, true)
case *ast.FuncDecl:
return nil
}
return v
}
Expand Down
11 changes: 11 additions & 0 deletions inspector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,17 @@ func TestInspector(t *testing.T) {
},
},
},
{
name: "funcs.go",
all: true,
expect: []*EnvDocItem{
{
Name: "SOME_VALUE",
Opts: EnvVarOptions{Default: "somevalue"},
Doc: "this is some value",
},
},
},
} {
scopes := c.expectScopes
if scopes == nil {
Expand Down
18 changes: 18 additions & 0 deletions testdata/funcs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package testdata

// Test case for #21 where the envdoc panics if target type function presents.

//go:generate envdoc -output test.md --all
type aconfig struct {
// this is some value
somevalue string `env:"SOME_VALUE" envDefault:"somevalue"`
}

// when this function is present, go generate panics with "expected type node root child, got nodeField ()".
func someFuncThatTakesInput(configs ...interface{}) {
// this is some comment
}

func (a *aconfig) someFuncThatTakesInput(configs ...interface{}) {
// this is some comment
}

0 comments on commit 9099fd8

Please sign in to comment.