Skip to content

Commit 0981b03

Browse files
committed
process the ast.FuncLit node as is.
close #10 Signed-off-by: Vladislav Fursov <[email protected]>
1 parent e4f751a commit 0981b03

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

processor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ func (c *processor) processInner(expr ast.Expr) {
218218
c.write("*")
219219
c.processInner(x.X)
220220

221-
case *ast.CompositeLit, *ast.TypeAssertExpr, *ast.ArrayType:
221+
case *ast.CompositeLit, *ast.TypeAssertExpr, *ast.ArrayType, *ast.FuncLit:
222222
// Process the node as is.
223223
c.write(formatNode(x))
224224

testdata/test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package testdata
22

33
import (
44
"fmt"
5+
"strings"
56

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

9495
t.RepeatedEmbeddeds = append(t.GetRepeatedEmbeddeds(), t.RepeatedEmbeddeds...) // want `avoid direct access to proto field t\.RepeatedEmbeddeds, use t\.GetRepeatedEmbeddeds\(\) instead`
9596
t.RepeatedEmbeddeds = append(t.RepeatedEmbeddeds, t.Embedded) // want `avoid direct access to proto field t\.Embedded, use t\.GetEmbedded\(\) instead`
97+
98+
// Issue #10
99+
_ = many[slicesIndexFunc(many, func(m *proto.Test) bool {
100+
return strings.Contains(strings.ToLower(m.GetS()), "specific value")
101+
})].GetS()
96102
}
97103

98104
func testValid(t *proto.Test) {
@@ -174,3 +180,8 @@ func testValid(t *proto.Test) {
174180
t.RepeatedEmbeddeds = append(t.RepeatedEmbeddeds, t.GetEmbedded())
175181
t.RepeatedEmbeddeds = append(t.RepeatedEmbeddeds, &proto.Embedded{})
176182
}
183+
184+
// stubs
185+
func slicesIndexFunc[S ~[]E, E any](s S, f func(E) bool) int {
186+
return 0
187+
}

testdata/test.go.golden

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package testdata
22

33
import (
44
"fmt"
5+
"strings"
56

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

9495
t.RepeatedEmbeddeds = append(t.GetRepeatedEmbeddeds(), t.GetRepeatedEmbeddeds()...) // want `avoid direct access to proto field t\.RepeatedEmbeddeds, use t\.GetRepeatedEmbeddeds\(\) instead`
9596
t.RepeatedEmbeddeds = append(t.RepeatedEmbeddeds, t.GetEmbedded()) // want `avoid direct access to proto field t\.Embedded, use t\.GetEmbedded\(\) instead`
97+
98+
// Issue #10
99+
_ = many[slicesIndexFunc(many, func(m *proto.Test) bool {
100+
return strings.Contains(strings.ToLower(m.GetS()), "specific value")
101+
})].GetS()
96102
}
97103

98104
func testValid(t *proto.Test) {
@@ -174,3 +180,8 @@ func testValid(t *proto.Test) {
174180
t.RepeatedEmbeddeds = append(t.RepeatedEmbeddeds, t.GetEmbedded())
175181
t.RepeatedEmbeddeds = append(t.RepeatedEmbeddeds, &proto.Embedded{})
176182
}
183+
184+
// stubs
185+
func slicesIndexFunc[S ~[]E, E any](s S, f func(E) bool) int {
186+
return 0
187+
}

0 commit comments

Comments
 (0)