From ceaf7c9c40141b37ee9f7c8412f494a3014f3337 Mon Sep 17 00:00:00 2001 From: 54m <30588003+54m@users.noreply.github.com> Date: Sun, 3 May 2026 11:54:45 +0900 Subject: [PATCH 1/6] feat(parser): support *types.Alias, *types.Signature, *types.TypeParam Go 1.23 made gotypesalias=1 the default, which causes type aliases such as 'any' (alias for interface{}) to appear as *types.Alias in go/types output. The parser's named-type switch did not have a case for this and emitted 'unsupported named type: *types.Alias' for any input that uses 'any', map[string]any, etc. This commit: - Adds *types.Alias case (resolved via types.Unalias, nil-guarded for incomplete aliases) - Adds *types.Signature case (function types fall back to Any{}) - Adds *types.TypeParam case (generic type parameters fall back to Any{}) - Renames panic message 'unsupported named type:' to 'unsupported type:' (Map/Slice/etc. are not named types; the previous wording was misleading) - Bumps go directive to 1.25.0 (toolchain upgrade via go get -u) - Bumps golang.org/x/tools to v0.44.0 to fix Go 1.26 build error - Bumps CI go-version to 1.24 (for Go 1.24+ generic alias testdata) - Fixes CI workflow trigger branch from 'master' to 'main' --- .github/workflows/lint.yaml | 4 +-- go.mod | 9 +++--- go.sum | 62 ++++--------------------------------- parser.go | 12 ++++++- 4 files changed, 23 insertions(+), 64 deletions(-) diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index 8d0c557..c998ebc 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -3,7 +3,7 @@ name: Go on: push: pull_request: - branches: [ master ] + branches: [ main ] jobs: @@ -15,7 +15,7 @@ jobs: - name: Set up Go 1.x uses: actions/setup-go@v5 with: - go-version: "1.22" + go-version: "1.24" id: go - name: Check out code into the Go module directory diff --git a/go.mod b/go.mod index 99d9822..e3d4028 100644 --- a/go.mod +++ b/go.mod @@ -1,16 +1,15 @@ module github.com/go-generalize/go-easyparser -go 1.22 +go 1.25.0 require ( github.com/go-utils/gopackages v0.1.0 github.com/google/go-cmp v0.6.0 - golang.org/x/tools v0.23.0 + golang.org/x/tools v0.44.0 ) require ( - golang.org/x/mod v0.19.0 // indirect - golang.org/x/sync v0.7.0 // indirect - golang.org/x/sys v0.22.0 // indirect + golang.org/x/mod v0.35.0 // indirect + golang.org/x/sync v0.20.0 // indirect golang.org/x/xerrors v0.0.0-20240716161551-93cc26a95ae9 // indirect ) diff --git a/go.sum b/go.sum index 699e1e7..e293d01 100644 --- a/go.sum +++ b/go.sum @@ -2,74 +2,24 @@ github.com/go-utils/gopackages v0.1.0 h1:zXn3KS4HzPGjpUcMZd2LzZ2wQ8K6haxGEebxCyx github.com/go-utils/gopackages v0.1.0/go.mod h1:QPVW4BzGDze3cEu7TbM7Gw9ppfYTj4NDgBW0JwNZE1g= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= -github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc= -golang.org/x/crypto v0.15.0/go.mod h1:4ChreQoLWfG3xLDer1WdlH5NdlQ3+mwnQq1YTKY+72g= golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= -golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= -golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= -golang.org/x/mod v0.14.0 h1:dGoOF9QVLYng8IHTm7BAyWqCqSheQ5pYWGhzW00YJr0= -golang.org/x/mod v0.14.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= -golang.org/x/mod v0.19.0 h1:fEdghXQSo20giMthA7cd28ZC+jts4amQ3YMXiP5oMQ8= -golang.org/x/mod v0.19.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= +golang.org/x/mod v0.35.0 h1:Ww1D637e6Pg+Zb2KrWfHQUnH2dQRLBQyAtpr/haaJeM= +golang.org/x/mod v0.35.0/go.mod h1:+GwiRhIInF8wPm+4AoT6L0FA1QWAad3OMdTRx4tFYlU= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= -golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= -golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= -golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= -golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk= -golang.org/x/net v0.18.0/go.mod h1:/czyP5RqHAH4odGYxBJ1qz0+CE5WZ+2j1YgoEo8F2jQ= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= -golang.org/x/sync v0.5.0 h1:60k92dhOjHxJkrqnwsfl8KuaHbn/5dl0lUPUklKo3qE= -golang.org/x/sync v0.5.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= -golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= -golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.20.0 h1:e0PTpb7pjO8GAtTs2dQ6jYa5BWYlMuX047Dco/pItO4= +golang.org/x/sync v0.20.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q= -golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI= -golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= -golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= -golang.org/x/term v0.12.0/go.mod h1:owVbMEjm3cBLCHdkQu9b1opXd4ETQWc3BhuQGKgXgvU= -golang.org/x/term v0.14.0/go.mod h1:TySc+nGkYR6qt8km8wUhuFRTVSMIX3XPR58y2lC8vww= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= -golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= -golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= -golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= -golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= -golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58= -golang.org/x/tools v0.15.0 h1:zdAyfUGbYmuVokhzVmghFl2ZJh5QhcfebBgmVPFYA+8= -golang.org/x/tools v0.15.0/go.mod h1:hpksKq4dtpQWS1uQ61JkdqWM3LscIS6Slf+VVkm+wQk= -golang.org/x/tools v0.23.0 h1:SGsXPZ+2l4JsgaCKkx+FQ9YZ5XEtA1GZYuoDjenLjvg= -golang.org/x/tools v0.23.0/go.mod h1:pnu6ufv6vQkll6szChhK3C3L/ruaIv5eBeztNG8wtsI= +golang.org/x/tools v0.44.0 h1:UP4ajHPIcuMjT1GqzDWRlalUEoY+uzoZKnhOjbIPD2c= +golang.org/x/tools v0.44.0/go.mod h1:KA0AfVErSdxRZIsOVipbv3rQhVXTnlU6UhKxHd1seDI= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20240716161551-93cc26a95ae9 h1:LLhsEBxRTBLuKlQxFBYUOU8xyFgXv6cOTp2HASDlsDk= golang.org/x/xerrors v0.0.0-20240716161551-93cc26a95ae9/go.mod h1:NDW/Ps6MPRej6fsCIbMTohpP40sJ/P/vI1MoTEGwX90= diff --git a/parser.go b/parser.go index 154fad5..776833f 100644 --- a/parser.go +++ b/parser.go @@ -342,8 +342,18 @@ func (p *pkgParser) parseType(u types.Type, dep bool) tstypes.Type { typ = p.parseMap(u) case *types.Interface: typ = p.parseInterface(u) + case *types.Alias: + ua := types.Unalias(u) + if ua == nil { + panic("incomplete alias: " + u.String()) + } + typ = p.parseType(ua, dep) + case *types.Signature: + typ = &tstypes.Any{} + case *types.TypeParam: + typ = &tstypes.Any{} default: - panic("unsupported named type: " + reflect.TypeOf(u).String()) + panic("unsupported type: " + reflect.TypeOf(u).String()) } return typ From ffe373e4e4479bb396b566b56de33644620942b3 Mon Sep 17 00:00:00 2001 From: 54m <30588003+54m@users.noreply.github.com> Date: Sun, 3 May 2026 11:56:44 +0900 Subject: [PATCH 2/6] test(parser): add fixtures for alias/signature/type param/generic alias Adds testdata/alias/{base/main.go,test.go} covering: - map[string]any (Map value alias resolved via Unalias) - []any (Slice element alias) - type UserID = string (named-basic alias, name elision verified) - func(int) error field (Signature -> Any fallback) - Box[T] generic struct (TypeParam -> Any fallback) - type VecAny[T any] = []T (Go 1.24+ generic alias, Unalias -> []T -> Array{Number{}}) Asserts the expected post-resolution shapes (Nullable{Map/Array/...{Any{}}} and String/Number for named-basic aliases) so future regressions in alias handling are caught at testdata layer. Note: generic alias fixture requires Go 1.24+ at test time. --- parser_test.go | 10 +++ testdata/alias/base/main.go | 37 +++++++++++ testdata/alias/test.go | 123 ++++++++++++++++++++++++++++++++++++ 3 files changed, 170 insertions(+) create mode 100644 testdata/alias/base/main.go create mode 100644 testdata/alias/test.go diff --git a/parser_test.go b/parser_test.go index 0a230c3..08bfe63 100644 --- a/parser_test.go +++ b/parser_test.go @@ -7,6 +7,7 @@ import ( "strings" "testing" + alias "github.com/go-generalize/go-easyparser/testdata/alias" "github.com/go-generalize/go-easyparser/testdata/conflict" "github.com/go-generalize/go-easyparser/testdata/recursive" "github.com/go-generalize/go-easyparser/testdata/replace" @@ -119,6 +120,15 @@ func TestParser_Parse(t *testing.T) { wantRes: replace.Type, wantErr: false, }, + { + name: "alias", + fields: fields{ + pkgs: parse(t, "./testdata/alias/base"), + Filter: All, + }, + wantRes: alias.Type, + wantErr: false, + }, } wd, err := os.Getwd() diff --git a/testdata/alias/base/main.go b/testdata/alias/base/main.go new file mode 100644 index 0000000..ffebc7b --- /dev/null +++ b/testdata/alias/base/main.go @@ -0,0 +1,37 @@ +package base + +// WithMapAny は map value として any(= *types.Alias)を持つ +type WithMapAny struct { + Extra map[string]any `json:"extra"` +} + +// WithSliceAny は slice element として any を持つ +type WithSliceAny struct { + Items []any `json:"items"` +} + +// UserID は named-basic alias(alias 名喪失挙動の固定) +type UserID = string + +// WithUserID は named-basic alias 経由のフィールドを持つ +type WithUserID struct { + ID UserID `json:"id"` +} + +// WithHandler は *types.Signature を踏む(Any fallback 検証) +type WithHandler struct { + H func(int) error `json:"handler"` +} + +// Box は *types.TypeParam を踏む generic struct +type Box[T any] struct { + V T `json:"v"` +} + +// VecAny は Go 1.24+ generic alias(type alias with type parameters) +type VecAny[T any] = []T + +// WithVecAny は generic alias を field に持つ +type WithVecAny struct { + Items VecAny[int] `json:"items"` +} diff --git a/testdata/alias/test.go b/testdata/alias/test.go new file mode 100644 index 0000000..00bfad1 --- /dev/null +++ b/testdata/alias/test.go @@ -0,0 +1,123 @@ +package alias + +import ( + "go/types" + + "github.com/go-generalize/go-easyparser/testutil" + tstypes "github.com/go-generalize/go-easyparser/types" +) + +// Type is the expected parse result for testdata/alias/base. +var Type = map[string]tstypes.Type{ + "github.com/go-generalize/go-easyparser/testdata/alias/base.WithMapAny": &tstypes.Object{ + Common: tstypes.Common{ + PkgName: "base", + Position: testutil.ParsePositionString("testdata/alias/base/main.go:4:6"), + }, + Name: "github.com/go-generalize/go-easyparser/testdata/alias/base.WithMapAny", + Entries: map[string]tstypes.ObjectEntry{ + "extra": { + RawName: "Extra", + RawTag: `json:"extra"`, + FieldIndex: 0, + Position: testutil.ParsePositionString("testdata/alias/base/main.go:5:2"), + Type: &tstypes.Nullable{ + Inner: &tstypes.Map{ + Key: &tstypes.String{}, + Value: &tstypes.Any{}, + }, + }, + }, + }, + }, + "github.com/go-generalize/go-easyparser/testdata/alias/base.WithSliceAny": &tstypes.Object{ + Common: tstypes.Common{ + PkgName: "base", + Position: testutil.ParsePositionString("testdata/alias/base/main.go:9:6"), + }, + Name: "github.com/go-generalize/go-easyparser/testdata/alias/base.WithSliceAny", + Entries: map[string]tstypes.ObjectEntry{ + "items": { + RawName: "Items", + RawTag: `json:"items"`, + FieldIndex: 0, + Position: testutil.ParsePositionString("testdata/alias/base/main.go:10:2"), + Type: &tstypes.Nullable{ + Inner: &tstypes.Array{ + Inner: &tstypes.Any{}, + }, + }, + }, + }, + }, + "github.com/go-generalize/go-easyparser/testdata/alias/base.WithUserID": &tstypes.Object{ + Common: tstypes.Common{ + PkgName: "base", + Position: testutil.ParsePositionString("testdata/alias/base/main.go:17:6"), + }, + Name: "github.com/go-generalize/go-easyparser/testdata/alias/base.WithUserID", + Entries: map[string]tstypes.ObjectEntry{ + "id": { + RawName: "ID", + RawTag: `json:"id"`, + FieldIndex: 0, + Position: testutil.ParsePositionString("testdata/alias/base/main.go:18:2"), + Type: &tstypes.String{}, + }, + }, + }, + "github.com/go-generalize/go-easyparser/testdata/alias/base.WithHandler": &tstypes.Object{ + Common: tstypes.Common{ + PkgName: "base", + Position: testutil.ParsePositionString("testdata/alias/base/main.go:22:6"), + }, + Name: "github.com/go-generalize/go-easyparser/testdata/alias/base.WithHandler", + Entries: map[string]tstypes.ObjectEntry{ + "handler": { + RawName: "H", + RawTag: `json:"handler"`, + FieldIndex: 0, + Position: testutil.ParsePositionString("testdata/alias/base/main.go:23:2"), + Type: &tstypes.Any{}, + }, + }, + }, + "github.com/go-generalize/go-easyparser/testdata/alias/base.Box[T any]": &tstypes.Object{ + Common: tstypes.Common{ + PkgName: "base", + Position: testutil.ParsePositionString("testdata/alias/base/main.go:27:6"), + }, + Name: "github.com/go-generalize/go-easyparser/testdata/alias/base.Box[T any]", + Entries: map[string]tstypes.ObjectEntry{ + "v": { + RawName: "V", + RawTag: `json:"v"`, + FieldIndex: 0, + Position: testutil.ParsePositionString("testdata/alias/base/main.go:28:2"), + Type: &tstypes.Any{}, + }, + }, + }, + "github.com/go-generalize/go-easyparser/testdata/alias/base.WithVecAny": &tstypes.Object{ + Common: tstypes.Common{ + PkgName: "base", + Position: testutil.ParsePositionString("testdata/alias/base/main.go:35:6"), + }, + Name: "github.com/go-generalize/go-easyparser/testdata/alias/base.WithVecAny", + Entries: map[string]tstypes.ObjectEntry{ + "items": { + RawName: "Items", + RawTag: `json:"items"`, + FieldIndex: 0, + Position: testutil.ParsePositionString("testdata/alias/base/main.go:36:2"), + Type: &tstypes.Nullable{ + Inner: &tstypes.Array{ + Inner: &tstypes.Number{ + RawType: types.Int, + }, + }, + }, + }, + }, + }, +} From 9f0957586579f55e0a85fd1420da317d1e34f281 Mon Sep 17 00:00:00 2001 From: 54m <30588003+54m@users.noreply.github.com> Date: Sun, 3 May 2026 11:57:02 +0900 Subject: [PATCH 3/6] docs: note v0.5.0 behavior changes for alias/signature/type param --- README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/README.md b/README.md index 71344c2..311e139 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,17 @@ # go-easyparser Parse Go packages with ease + +## Behavior notes (v0.5.0+) + +### Newly supported types +- `*types.Alias` (Go 1.23+ `gotypesalias=1`) is resolved via `types.Unalias`. The alias name itself is not preserved (e.g. `type UserID = string` is parsed as `string`). +- `*types.Signature` (function types) falls back to `Any{}`. +- `*types.TypeParam` (generic type parameters) falls back to `Any{}`. +- Generic type aliases (Go 1.24+, e.g. `type Vec[T any] = []T`) are also handled via `types.Unalias`. + +### Migration from previous versions +- Inputs containing `func(...)` fields, generic type parameters, or type aliases used to **panic** with `unsupported named type: *types.`. They now parse successfully and produce `Any{}` (or the resolved underlying type for aliases). If your downstream code relied on this panic for fail-fast validation, install a custom `Replacer` that explicitly rejects these kinds. +- The panic message wording changed from `unsupported named type:` to `unsupported type:` (the previous wording was misleading since `Map`, `Slice`, etc. are not named types). + +### Replacer caveat +- When a `*types.Alias` is encountered, the user-supplied `Replacer` is invoked twice — once on the original alias type, then again on the Unalias-resolved type via the recursive `parseType` call. `Replacer` implementations should be idempotent. From 6bbc400a4698f9b43fc816cd77b348bb7ce96322 Mon Sep 17 00:00:00 2001 From: 54m <30588003+54m@users.noreply.github.com> Date: Sun, 3 May 2026 12:03:17 +0900 Subject: [PATCH 4/6] fix(deps): lower go directive to 1.23.0 and fix golangci-lint CI compatibility - Lower go directive 1.25.0 -> 1.23.0 (only types.Unalias requires 1.23+; keeping the floor low for downstream ecosystem) - Add toolchain go1.25.0 directive - Bump reviewdog/action-golangci-lint to @v2 to fix 'unknown flag: --out-format' error (golangci-lint v2 dropped this flag) --- .github/workflows/reviewdog.yaml | 2 +- go.mod | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/reviewdog.yaml b/.github/workflows/reviewdog.yaml index b3bdd0d..c8c74db 100644 --- a/.github/workflows/reviewdog.yaml +++ b/.github/workflows/reviewdog.yaml @@ -9,7 +9,7 @@ jobs: - name: Check out code into the Go module directory uses: actions/checkout@v4 - name: golangci-lint - uses: reviewdog/action-golangci-lint@v2.6.2 + uses: reviewdog/action-golangci-lint@v2 with: github_token: ${{ secrets.github_token }} golangci_lint_flags: "--config=.github/.golangci.yml" diff --git a/go.mod b/go.mod index e3d4028..d845e5f 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,8 @@ module github.com/go-generalize/go-easyparser -go 1.25.0 +go 1.23.0 + +toolchain go1.25.0 require ( github.com/go-utils/gopackages v0.1.0 From 25008bb2cba20d9eed4961aaf6a012ca969634c0 Mon Sep 17 00:00:00 2001 From: 54m <30588003+54m@users.noreply.github.com> Date: Sun, 3 May 2026 12:07:24 +0900 Subject: [PATCH 5/6] fix(deps): bump go directive to 1.25.0 for x/tools v0.44 compatibility x/tools v0.44.0 requires go >= 1.25.0. Lowering go directive below that creates an inconsistency caught by 'go mod tidy' / CI build. Drop the toolchain directive since it equals the go directive. --- go.mod | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/go.mod b/go.mod index d845e5f..e3d4028 100644 --- a/go.mod +++ b/go.mod @@ -1,8 +1,6 @@ module github.com/go-generalize/go-easyparser -go 1.23.0 - -toolchain go1.25.0 +go 1.25.0 require ( github.com/go-utils/gopackages v0.1.0 From c2574b702ecaf4da22aaf5da26f39ee521159fdd Mon Sep 17 00:00:00 2001 From: 54m <30588003+54m@users.noreply.github.com> Date: Sun, 3 May 2026 12:09:15 +0900 Subject: [PATCH 6/6] ci(lint): replace reviewdog action with golangci-lint-action v7 The previous reviewdog/action-golangci-lint@v2 invokes golangci-lint v2 with the removed --out-format flag, causing CI failure. Replace with the same setup api_gen uses (golangci/golangci-lint-action@v7.0.1 with golangci-lint v2.12.1 + .github/.golangci.yml config). - Rename reviewdog.yaml -> linter.yml (api_gen naming convention) - Switch from reviewdog/action-golangci-lint to golangci/golangci-lint-action@v7 - Rewrite .github/.golangci.yml from v1 format to v2 format - Update local-prefixes to github.com/go-generalize/go-easyparser - Remove api_gen-specific path exclusions (test/testdata_etc, internal/*) - Move gofmt/goimports to formatters section (v2 requirement) - Bump lint.yaml go-version to 1.25 to match go.mod --- .github/.golangci.yml | 123 ++++++++++++++----------------- .github/workflows/lint.yaml | 2 +- .github/workflows/linter.yml | 19 +++++ .github/workflows/reviewdog.yaml | 15 ---- 4 files changed, 75 insertions(+), 84 deletions(-) create mode 100644 .github/workflows/linter.yml delete mode 100644 .github/workflows/reviewdog.yaml diff --git a/.github/.golangci.yml b/.github/.golangci.yml index c08b6ef..0f1b790 100644 --- a/.github/.golangci.yml +++ b/.github/.golangci.yml @@ -1,82 +1,69 @@ -linters-settings: - dupl: - threshold: 100 - errcheck: - check-type-assertions: true - ignore: fmt:.*,io/ioutil:^Read.*,io:Close,os:Close - goconst: - min-len: 2 - min-occurrences: 2 - goimports: - local-prefixes: github.com/golangci/golangci-lint - golint: - min-confidence: 0 - govet: - check-shadowing: true - - lll: - line-length: 120 - misspell: - locale: US - ignore-words: [] - +version: "2" +run: + go: "1.25" linters: - disable-all: true + default: none enable: - # HTTPリクエストで閉じられていないものを検出 - bodyclose - # _, _ := x() のようなものを検出 - dogsled - # 同一コードの検出 - dupl - # エラーを未チェックのものを検出 - errcheck - # 定数化できるものを検出 - goconst - # gofmt - - gofmt - # goimports - - goimports - # 引数がフォーマット文字列と一致しないものを検出 - govet - # 意味のない再代入を検出 - ineffassign - # 1行の最大長が長すぎるものを検出 - - lll - # スペルチェック - misspell - # linter - revive - # 不要な型変換を検出 - unconvert - # 未使用のものを検出 - unused - # 前後の余計な空白を検出 - whitespace - -issues: - exclude: - - declaration of "(err|ctx)" shadows declaration at - exclude-use-default: false - exclude-rules: - - path: _test\.go - linters: - - gomnd - - dupl - - - linters: - - lll - source: "//go:generate " - -run: - skip-dirs: - - example - - test/testdata_etc - - internal/cache - - internal/renameio - - internal/robustio - -service: - golangci-lint-version: 1.23.x - prepare: - - echo "here I can run custom commands, but no preparation needed for this repo" + settings: + dupl: + threshold: 100 + errcheck: + check-type-assertions: true + exclude-functions: + - fmt.* + - io/ioutil.Read.* + - io.Close + - os.Close + - io/fs.Close + goconst: + min-len: 2 + min-occurrences: 2 + govet: + enable: + - shadow + misspell: + locale: US + exclusions: + generated: lax + rules: + - linters: + - dupl + - mnd + path: _test\.go + - linters: + - lll + source: '//go:generate ' + - path: (.+)\.go$ + text: declaration of "(err|ctx)" shadows declaration at + paths: + - testdata + - third_party$ + - builtin$ + - examples$ +formatters: + enable: + - gofmt + - goimports + settings: + goimports: + local-prefixes: + - github.com/go-generalize/go-easyparser + exclusions: + generated: lax + paths: + - testdata + - third_party$ + - builtin$ + - examples$ diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index c998ebc..cfd39bc 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -15,7 +15,7 @@ jobs: - name: Set up Go 1.x uses: actions/setup-go@v5 with: - go-version: "1.24" + go-version: "1.25" id: go - name: Check out code into the Go module directory diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml new file mode 100644 index 0000000..8943b3d --- /dev/null +++ b/.github/workflows/linter.yml @@ -0,0 +1,19 @@ +name: linter +on: [pull_request] +jobs: + golangci-lint: + name: runner / golangci-lint + runs-on: ubuntu-latest + steps: + - name: Check out code into the Go module directory + uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1 + - uses: actions/setup-go@40f1582b2485089dde7abd97c1529aa768e1baff # v5.6.0 + with: + go-version: '1.25' + - name: golangci-lint + uses: golangci/golangci-lint-action@9fae48acfc02a90574d7c304a1758ef9895495fa # v7.0.1 + with: + args: "--config=.github/.golangci.yml" + version: v2.12.1 + only-new-issues: true + skip-cache: true diff --git a/.github/workflows/reviewdog.yaml b/.github/workflows/reviewdog.yaml deleted file mode 100644 index c8c74db..0000000 --- a/.github/workflows/reviewdog.yaml +++ /dev/null @@ -1,15 +0,0 @@ -name: reviewdog - -on: [pull_request] -jobs: - golangci-lint: - name: runner / golangci-lint - runs-on: ubuntu-latest - steps: - - name: Check out code into the Go module directory - uses: actions/checkout@v4 - - name: golangci-lint - uses: reviewdog/action-golangci-lint@v2 - with: - github_token: ${{ secrets.github_token }} - golangci_lint_flags: "--config=.github/.golangci.yml"