Skip to content

Commit

Permalink
process the ast.FuncLit node as is.
Browse files Browse the repository at this point in the history
close #10

Signed-off-by: Vladislav Fursov <[email protected]>
  • Loading branch information
ghostiam committed May 7, 2024
1 parent e4f751a commit 0981b03
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ func (c *processor) processInner(expr ast.Expr) {
c.write("*")
c.processInner(x.X)

case *ast.CompositeLit, *ast.TypeAssertExpr, *ast.ArrayType:
case *ast.CompositeLit, *ast.TypeAssertExpr, *ast.ArrayType, *ast.FuncLit:
// Process the node as is.
c.write(formatNode(x))

Expand Down
11 changes: 11 additions & 0 deletions testdata/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package testdata

import (
"fmt"
"strings"

"github.com/ghostiam/protogetter/testdata/proto"
)
Expand Down Expand Up @@ -93,6 +94,11 @@ func testInvalid(t *proto.Test) {

t.RepeatedEmbeddeds = append(t.GetRepeatedEmbeddeds(), t.RepeatedEmbeddeds...) // want `avoid direct access to proto field t\.RepeatedEmbeddeds, use t\.GetRepeatedEmbeddeds\(\) instead`
t.RepeatedEmbeddeds = append(t.RepeatedEmbeddeds, t.Embedded) // want `avoid direct access to proto field t\.Embedded, use t\.GetEmbedded\(\) instead`

// Issue #10
_ = many[slicesIndexFunc(many, func(m *proto.Test) bool {
return strings.Contains(strings.ToLower(m.GetS()), "specific value")
})].GetS()
}

func testValid(t *proto.Test) {
Expand Down Expand Up @@ -174,3 +180,8 @@ func testValid(t *proto.Test) {
t.RepeatedEmbeddeds = append(t.RepeatedEmbeddeds, t.GetEmbedded())
t.RepeatedEmbeddeds = append(t.RepeatedEmbeddeds, &proto.Embedded{})
}

// stubs
func slicesIndexFunc[S ~[]E, E any](s S, f func(E) bool) int {
return 0
}
11 changes: 11 additions & 0 deletions testdata/test.go.golden
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package testdata

import (
"fmt"
"strings"

"github.com/ghostiam/protogetter/testdata/proto"
)
Expand Down Expand Up @@ -93,6 +94,11 @@ func testInvalid(t *proto.Test) {

t.RepeatedEmbeddeds = append(t.GetRepeatedEmbeddeds(), t.GetRepeatedEmbeddeds()...) // want `avoid direct access to proto field t\.RepeatedEmbeddeds, use t\.GetRepeatedEmbeddeds\(\) instead`
t.RepeatedEmbeddeds = append(t.RepeatedEmbeddeds, t.GetEmbedded()) // want `avoid direct access to proto field t\.Embedded, use t\.GetEmbedded\(\) instead`

// Issue #10
_ = many[slicesIndexFunc(many, func(m *proto.Test) bool {
return strings.Contains(strings.ToLower(m.GetS()), "specific value")
})].GetS()
}

func testValid(t *proto.Test) {
Expand Down Expand Up @@ -174,3 +180,8 @@ func testValid(t *proto.Test) {
t.RepeatedEmbeddeds = append(t.RepeatedEmbeddeds, t.GetEmbedded())
t.RepeatedEmbeddeds = append(t.RepeatedEmbeddeds, &proto.Embedded{})
}

// stubs
func slicesIndexFunc[S ~[]E, E any](s S, f func(E) bool) int {
return 0
}

0 comments on commit 0981b03

Please sign in to comment.