From 4ec197664a206890a44245f5c0cbcb8110d68cb5 Mon Sep 17 00:00:00 2001 From: Henry Woody Date: Thu, 11 Apr 2024 18:47:11 +0100 Subject: [PATCH] entgql: improve var name collision avoidance in toCursor (#572) Improves variable name collision avoidance in the `toCursor` method of the pager types in the `gql_pagination` template by suffixing all hard-coded variables names with an underscore. --- entgql/internal/todo/ent/gql_pagination.go | 24 +++++++++---------- .../internal/todogotype/ent/gql_pagination.go | 16 ++++++------- .../internal/todopulid/ent/gql_pagination.go | 24 +++++++++---------- .../internal/todouuid/ent/gql_pagination.go | 24 +++++++++---------- entgql/template/pagination.tmpl | 8 +++---- 5 files changed, 48 insertions(+), 48 deletions(-) diff --git a/entgql/internal/todo/ent/gql_pagination.go b/entgql/internal/todo/ent/gql_pagination.go index 26d14cf89..8a950a382 100644 --- a/entgql/internal/todo/ent/gql_pagination.go +++ b/entgql/internal/todo/ent/gql_pagination.go @@ -476,11 +476,11 @@ func (p *categoryPager) applyFilter(query *CategoryQuery) (*CategoryQuery, error } func (p *categoryPager) toCursor(c *Category) Cursor { - cs := make([]any, 0, len(p.order)) - for _, po := range p.order { - cs = append(cs, po.Field.toCursor(c).Value) + cs_ := make([]any, 0, len(p.order)) + for _, o_ := range p.order { + cs_ = append(cs_, o_.Field.toCursor(c).Value) } - return Cursor{ID: c.ID, Value: cs} + return Cursor{ID: c.ID, Value: cs_} } func (p *categoryPager) applyCursors(query *CategoryQuery, after, before *Cursor) (*CategoryQuery, error) { @@ -1165,11 +1165,11 @@ func (p *groupPager) applyFilter(query *GroupQuery) (*GroupQuery, error) { } func (p *groupPager) toCursor(gr *Group) Cursor { - cs := make([]any, 0, len(p.order)) - for _, po := range p.order { - cs = append(cs, po.Field.toCursor(gr).Value) + cs_ := make([]any, 0, len(p.order)) + for _, o_ := range p.order { + cs_ = append(cs_, o_.Field.toCursor(gr).Value) } - return Cursor{ID: gr.ID, Value: cs} + return Cursor{ID: gr.ID, Value: cs_} } func (p *groupPager) applyCursors(query *GroupQuery, after, before *Cursor) (*GroupQuery, error) { @@ -1995,11 +1995,11 @@ func (p *todoPager) applyFilter(query *TodoQuery) (*TodoQuery, error) { } func (p *todoPager) toCursor(t *Todo) Cursor { - cs := make([]any, 0, len(p.order)) - for _, po := range p.order { - cs = append(cs, po.Field.toCursor(t).Value) + cs_ := make([]any, 0, len(p.order)) + for _, o_ := range p.order { + cs_ = append(cs_, o_.Field.toCursor(t).Value) } - return Cursor{ID: t.ID, Value: cs} + return Cursor{ID: t.ID, Value: cs_} } func (p *todoPager) applyCursors(query *TodoQuery, after, before *Cursor) (*TodoQuery, error) { diff --git a/entgql/internal/todogotype/ent/gql_pagination.go b/entgql/internal/todogotype/ent/gql_pagination.go index bf65247a9..0aebdc670 100644 --- a/entgql/internal/todogotype/ent/gql_pagination.go +++ b/entgql/internal/todogotype/ent/gql_pagination.go @@ -474,11 +474,11 @@ func (p *categoryPager) applyFilter(query *CategoryQuery) (*CategoryQuery, error } func (p *categoryPager) toCursor(c *Category) Cursor { - cs := make([]any, 0, len(p.order)) - for _, po := range p.order { - cs = append(cs, po.Field.toCursor(c).Value) + cs_ := make([]any, 0, len(p.order)) + for _, o_ := range p.order { + cs_ = append(cs_, o_.Field.toCursor(c).Value) } - return Cursor{ID: c.marshalID(), Value: cs} + return Cursor{ID: c.marshalID(), Value: cs_} } func (p *categoryPager) applyCursors(query *CategoryQuery, after, before *Cursor) (*CategoryQuery, error) { @@ -1643,11 +1643,11 @@ func (p *todoPager) applyFilter(query *TodoQuery) (*TodoQuery, error) { } func (p *todoPager) toCursor(t *Todo) Cursor { - cs := make([]any, 0, len(p.order)) - for _, po := range p.order { - cs = append(cs, po.Field.toCursor(t).Value) + cs_ := make([]any, 0, len(p.order)) + for _, o_ := range p.order { + cs_ = append(cs_, o_.Field.toCursor(t).Value) } - return Cursor{ID: t.ID, Value: cs} + return Cursor{ID: t.ID, Value: cs_} } func (p *todoPager) applyCursors(query *TodoQuery, after, before *Cursor) (*TodoQuery, error) { diff --git a/entgql/internal/todopulid/ent/gql_pagination.go b/entgql/internal/todopulid/ent/gql_pagination.go index 9e134650a..1455f3a82 100644 --- a/entgql/internal/todopulid/ent/gql_pagination.go +++ b/entgql/internal/todopulid/ent/gql_pagination.go @@ -474,11 +474,11 @@ func (p *categoryPager) applyFilter(query *CategoryQuery) (*CategoryQuery, error } func (p *categoryPager) toCursor(c *Category) Cursor { - cs := make([]any, 0, len(p.order)) - for _, po := range p.order { - cs = append(cs, po.Field.toCursor(c).Value) + cs_ := make([]any, 0, len(p.order)) + for _, o_ := range p.order { + cs_ = append(cs_, o_.Field.toCursor(c).Value) } - return Cursor{ID: c.ID, Value: cs} + return Cursor{ID: c.ID, Value: cs_} } func (p *categoryPager) applyCursors(query *CategoryQuery, after, before *Cursor) (*CategoryQuery, error) { @@ -1145,11 +1145,11 @@ func (p *groupPager) applyFilter(query *GroupQuery) (*GroupQuery, error) { } func (p *groupPager) toCursor(gr *Group) Cursor { - cs := make([]any, 0, len(p.order)) - for _, po := range p.order { - cs = append(cs, po.Field.toCursor(gr).Value) + cs_ := make([]any, 0, len(p.order)) + for _, o_ := range p.order { + cs_ = append(cs_, o_.Field.toCursor(gr).Value) } - return Cursor{ID: gr.ID, Value: cs} + return Cursor{ID: gr.ID, Value: cs_} } func (p *groupPager) applyCursors(query *GroupQuery, after, before *Cursor) (*GroupQuery, error) { @@ -1430,11 +1430,11 @@ func (p *todoPager) applyFilter(query *TodoQuery) (*TodoQuery, error) { } func (p *todoPager) toCursor(t *Todo) Cursor { - cs := make([]any, 0, len(p.order)) - for _, po := range p.order { - cs = append(cs, po.Field.toCursor(t).Value) + cs_ := make([]any, 0, len(p.order)) + for _, o_ := range p.order { + cs_ = append(cs_, o_.Field.toCursor(t).Value) } - return Cursor{ID: t.ID, Value: cs} + return Cursor{ID: t.ID, Value: cs_} } func (p *todoPager) applyCursors(query *TodoQuery, after, before *Cursor) (*TodoQuery, error) { diff --git a/entgql/internal/todouuid/ent/gql_pagination.go b/entgql/internal/todouuid/ent/gql_pagination.go index 599cc7b41..4b1756f64 100644 --- a/entgql/internal/todouuid/ent/gql_pagination.go +++ b/entgql/internal/todouuid/ent/gql_pagination.go @@ -474,11 +474,11 @@ func (p *categoryPager) applyFilter(query *CategoryQuery) (*CategoryQuery, error } func (p *categoryPager) toCursor(c *Category) Cursor { - cs := make([]any, 0, len(p.order)) - for _, po := range p.order { - cs = append(cs, po.Field.toCursor(c).Value) + cs_ := make([]any, 0, len(p.order)) + for _, o_ := range p.order { + cs_ = append(cs_, o_.Field.toCursor(c).Value) } - return Cursor{ID: c.ID, Value: cs} + return Cursor{ID: c.ID, Value: cs_} } func (p *categoryPager) applyCursors(query *CategoryQuery, after, before *Cursor) (*CategoryQuery, error) { @@ -1145,11 +1145,11 @@ func (p *groupPager) applyFilter(query *GroupQuery) (*GroupQuery, error) { } func (p *groupPager) toCursor(gr *Group) Cursor { - cs := make([]any, 0, len(p.order)) - for _, po := range p.order { - cs = append(cs, po.Field.toCursor(gr).Value) + cs_ := make([]any, 0, len(p.order)) + for _, o_ := range p.order { + cs_ = append(cs_, o_.Field.toCursor(gr).Value) } - return Cursor{ID: gr.ID, Value: cs} + return Cursor{ID: gr.ID, Value: cs_} } func (p *groupPager) applyCursors(query *GroupQuery, after, before *Cursor) (*GroupQuery, error) { @@ -1430,11 +1430,11 @@ func (p *todoPager) applyFilter(query *TodoQuery) (*TodoQuery, error) { } func (p *todoPager) toCursor(t *Todo) Cursor { - cs := make([]any, 0, len(p.order)) - for _, po := range p.order { - cs = append(cs, po.Field.toCursor(t).Value) + cs_ := make([]any, 0, len(p.order)) + for _, o_ := range p.order { + cs_ = append(cs_, o_.Field.toCursor(t).Value) } - return Cursor{ID: t.ID, Value: cs} + return Cursor{ID: t.ID, Value: cs_} } func (p *todoPager) applyCursors(query *TodoQuery, after, before *Cursor) (*TodoQuery, error) { diff --git a/entgql/template/pagination.tmpl b/entgql/template/pagination.tmpl index 5ddfa8fbd..ce39dadad 100644 --- a/entgql/template/pagination.tmpl +++ b/entgql/template/pagination.tmpl @@ -271,12 +271,12 @@ func (p *{{ $pager }}) applyFilter(query *{{ $query }}) (*{{ $query }}, error) { {{ $r := $node.Receiver }} func (p *{{ $pager }}) toCursor({{ $r }} *{{ $name }}) Cursor { {{- if $multiOrder }} - cs := make([]any, 0, len(p.order)) - for _, po := range p.order { - cs = append(cs, po.Field.toCursor({{ $r }}).Value) + cs_ := make([]any, 0, len(p.order)) + for _, o_ := range p.order { + cs_ = append(cs_, o_.Field.toCursor({{ $r }}).Value) } {{- $marshalID := and $idType.Mixed (gqlMarshaler $node.ID) }} - return Cursor{ID: {{ $r }}.{{ if $marshalID }}marshalID(){{ else }}ID{{ end }}, Value: cs} + return Cursor{ID: {{ $r }}.{{ if $marshalID }}marshalID(){{ else }}ID{{ end }}, Value: cs_} {{- else }} return p.order.Field.toCursor({{ $r }}) {{- end }}