Skip to content

Commit

Permalink
chore(lint): Switch to copyloopvar linter for Go 1.22+ (#150)
Browse files Browse the repository at this point in the history
The `exportloopref` linter is no longer needed due to a
change in how loop variables work in Go 1.22+

See https://go.dev/blog/loopvar-preview for more information
  • Loading branch information
mheap authored Nov 28, 2024
1 parent 4c15b26 commit d53b0d3
Show file tree
Hide file tree
Showing 14 changed files with 1 addition and 57 deletions.
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ linters:
- dogsled
- durationcheck
- exhaustive
- exportloopref
- copyloopvar
- gci
- goconst
- gofmt
Expand Down
24 changes: 0 additions & 24 deletions pkg/file/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ func (b *stateBuilder) consumerGroups() {
}

for _, cg := range b.targetContent.ConsumerGroups {
cg := cg
current, err := b.currentState.ConsumerGroups.Get(*cg.Name)
if utils.Empty(cg.ID) {
if errors.Is(err, state.ErrNotFound) {
Expand Down Expand Up @@ -290,7 +289,6 @@ func (b *stateBuilder) certificates() {

func (b *stateBuilder) ingestSNIs(snis []kong.SNI) error {
for _, sni := range snis {
sni := sni
currentSNI, err := b.currentState.SNIs.Get(*sni.Name)
if utils.Empty(sni.ID) {
if errors.Is(err, state.ErrNotFound) {
Expand All @@ -316,7 +314,6 @@ func (b *stateBuilder) caCertificates() {
}

for _, c := range b.targetContent.CACertificates {
c := c
cert, err := b.currentState.CACertificates.Get(*c.Cert)
if utils.Empty(c.ID) {
if errors.Is(err, state.ErrNotFound) {
Expand Down Expand Up @@ -412,7 +409,6 @@ func (b *stateBuilder) consumers() {
}

for _, c := range b.targetContent.Consumers {
c := c

var (
consumer *state.Consumer
Expand Down Expand Up @@ -602,7 +598,6 @@ func (b *stateBuilder) ingestIntoConsumerGroup(consumer FConsumer) error {

func (b *stateBuilder) ingestKeyAuths(creds []kong.KeyAuth) error {
for _, cred := range creds {
cred := cred
existingCred, err := b.currentState.KeyAuths.Get(*cred.Key)
if utils.Empty(cred.ID) {
if errors.Is(err, state.ErrNotFound) {
Expand All @@ -626,7 +621,6 @@ func (b *stateBuilder) ingestKeyAuths(creds []kong.KeyAuth) error {

func (b *stateBuilder) ingestBasicAuths(creds []kong.BasicAuth) error {
for _, cred := range creds {
cred := cred
existingCred, err := b.currentState.BasicAuths.Get(*cred.Username)
if utils.Empty(cred.ID) {
if errors.Is(err, state.ErrNotFound) {
Expand All @@ -650,7 +644,6 @@ func (b *stateBuilder) ingestBasicAuths(creds []kong.BasicAuth) error {

func (b *stateBuilder) ingestHMACAuths(creds []kong.HMACAuth) error {
for _, cred := range creds {
cred := cred
existingCred, err := b.currentState.HMACAuths.Get(*cred.Username)
if utils.Empty(cred.ID) {
if errors.Is(err, state.ErrNotFound) {
Expand All @@ -674,7 +667,6 @@ func (b *stateBuilder) ingestHMACAuths(creds []kong.HMACAuth) error {

func (b *stateBuilder) ingestJWTAuths(creds []kong.JWTAuth) error {
for _, cred := range creds {
cred := cred
existingCred, err := b.currentState.JWTAuths.Get(*cred.Key)
if utils.Empty(cred.ID) {
if errors.Is(err, state.ErrNotFound) {
Expand All @@ -698,7 +690,6 @@ func (b *stateBuilder) ingestJWTAuths(creds []kong.JWTAuth) error {

func (b *stateBuilder) ingestOauth2Creds(creds []kong.Oauth2Credential) error {
for _, cred := range creds {
cred := cred
existingCred, err := b.currentState.Oauth2Creds.Get(*cred.ClientID)
if utils.Empty(cred.ID) {
if errors.Is(err, state.ErrNotFound) {
Expand All @@ -722,7 +713,6 @@ func (b *stateBuilder) ingestOauth2Creds(creds []kong.Oauth2Credential) error {

func (b *stateBuilder) ingestACLGroups(creds []kong.ACLGroup) error {
for _, cred := range creds {
cred := cred
if utils.Empty(cred.ID) {
existingCred, err := b.currentState.ACLGroups.Get(
*cred.Consumer.ID,
Expand All @@ -746,7 +736,6 @@ func (b *stateBuilder) ingestACLGroups(creds []kong.ACLGroup) error {
func (b *stateBuilder) ingestMTLSAuths(creds []kong.MTLSAuth) {
kong230Version := semver.MustParse("2.3.0")
for _, cred := range creds {
cred := cred
// normally, we'd want to look up existing resources in this case
// however, this is impossible here: mtls-auth simply has no unique fields other than ID,
// so we don't--schema validation requires the ID
Expand Down Expand Up @@ -876,7 +865,6 @@ func (b *stateBuilder) services() {
}

for _, s := range b.targetContent.Services {
s := s
err := b.ingestService(&s)
if err != nil {
b.err = err
Expand Down Expand Up @@ -950,7 +938,6 @@ func (b *stateBuilder) ingestService(s *FService) error {

// routes for the service
for _, r := range s.Routes {
r := r
r.Service = utils.GetServiceReference(s.Service)
if err := b.ingestRoute(*r); err != nil {
return err
Expand All @@ -965,7 +952,6 @@ func (b *stateBuilder) routes() {
}

for _, r := range b.targetContent.Routes {
r := r
if err := b.ingestRoute(r); err != nil {
b.err = err
return
Expand Down Expand Up @@ -1007,7 +993,6 @@ func (b *stateBuilder) vaults() {
}

for _, v := range b.targetContent.Vaults {
v := v
vault, err := b.currentState.Vaults.Get(*v.Prefix)
if utils.Empty(v.ID) {
if errors.Is(err, state.ErrNotFound) {
Expand All @@ -1034,7 +1019,6 @@ func (b *stateBuilder) licenses() {
}

for _, l := range b.targetContent.Licenses {
l := l
// Fill with a random ID if the ID is not given.
// If ID is not given in the file to sync from, a NEW license will be created.
if utils.Empty(l.ID) {
Expand All @@ -1051,7 +1035,6 @@ func (b *stateBuilder) rbacRoles() {
}

for _, r := range b.targetContent.RBACRoles {
r := r
role, err := b.currentState.RBACRoles.Get(*r.Name)
if utils.Empty(r.ID) {
if errors.Is(err, state.ErrNotFound) {
Expand All @@ -1069,7 +1052,6 @@ func (b *stateBuilder) rbacRoles() {
b.rawState.RBACRoles = append(b.rawState.RBACRoles, &r.RBACRole)
// rbac endpoint permissions for the role
for _, ep := range r.EndpointPermissions {
ep := ep
ep.Role = &kong.RBACRole{ID: kong.String(*r.ID)}
b.rawState.RBACEndpointPermissions = append(b.rawState.RBACEndpointPermissions, &ep.RBACEndpointPermission)
}
Expand Down Expand Up @@ -1146,7 +1128,6 @@ func (b *stateBuilder) upstreams() {
}

for _, u := range b.targetContent.Upstreams {
u := u
ups, err := b.currentState.Upstreams.Get(*u.Name)
if utils.Empty(u.ID) {
if errors.Is(err, state.ErrNotFound) {
Expand Down Expand Up @@ -1181,7 +1162,6 @@ func (b *stateBuilder) upstreams() {

func (b *stateBuilder) ingestTargets(targets []kong.Target) error {
for _, t := range targets {
t := t

if t.Target != nil && hasIPv6Format(*t.Target) {
normalizedTarget, err := normalizeIPv6(*t.Target)
Expand Down Expand Up @@ -1215,7 +1195,6 @@ func (b *stateBuilder) plugins() {

var plugins []FPlugin
for _, p := range b.targetContent.Plugins {
p := p
if p.Consumer != nil && !utils.Empty(p.Consumer.ID) {
c, err := b.intermediate.Consumers.GetByIDOrUsername(*p.Consumer.ID)
if errors.Is(err, state.ErrNotFound) {
Expand Down Expand Up @@ -1287,7 +1266,6 @@ func (b *stateBuilder) filterChains() {

var filterChains []FFilterChain
for _, f := range b.targetContent.FilterChains {
f := f
if f.Service != nil && !utils.Empty(f.Service.ID) {
s, err := b.intermediate.Services.Get(*f.Service.ID)
if errors.Is(err, state.ErrNotFound) {
Expand Down Expand Up @@ -1476,7 +1454,6 @@ func (b *stateBuilder) ingestRoute(r FRoute) error {

func (b *stateBuilder) ingestPlugins(plugins []FPlugin) error {
for _, p := range plugins {
p := p
cID, rID, sID, cgID := pluginRelations(&p.Plugin)
plugin, err := b.currentState.Plugins.GetByProp(*p.Name,
sID, rID, cID, cgID)
Expand Down Expand Up @@ -1543,7 +1520,6 @@ func pluginRelations(plugin *kong.Plugin) (cID, rID, sID, cgID string) {

func (b *stateBuilder) ingestFilterChains(filterChains []FFilterChain) error {
for _, f := range filterChains {
f := f
rID, sID := filterChainRelations(&f.FilterChain)
filterChain, err := b.currentState.FilterChains.GetByProp(sID, rID)
if utils.Empty(f.ID) {
Expand Down
14 changes: 0 additions & 14 deletions pkg/file/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,6 @@ func fetchService(id string, kongState *state.KongState, config WriteConfig) (*F
return nil, err
}
for _, p := range plugins {
p := p
if p.Route != nil || p.Consumer != nil || p.ConsumerGroup != nil {
continue
}
Expand All @@ -370,7 +369,6 @@ func fetchService(id string, kongState *state.KongState, config WriteConfig) (*F
return compareOrder(s.Plugins[i], s.Plugins[j])
})
for _, r := range routes {
r := r
r.Service = nil
route, err := getFRouteFromRoute(r, kongState, config)
if err != nil {
Expand Down Expand Up @@ -405,7 +403,6 @@ func populateServicelessRoutes(kongState *state.KongState, file *Content,
return err
}
for _, r := range routes {
r := r
if r.Service != nil {
continue
}
Expand All @@ -429,7 +426,6 @@ func populatePlugins(kongState *state.KongState, file *Content,
return err
}
for _, p := range plugins {
p := p
associations := 0
if p.Consumer != nil {
associations++
Expand Down Expand Up @@ -551,7 +547,6 @@ func populateUpstreams(kongState *state.KongState, file *Content,
return err
}
for _, t := range targets {
t := t
t.Upstream = nil
utils.ZeroOutID(t, t.Target.Target, config.WithID)
utils.ZeroOutTimestamps(t)
Expand Down Expand Up @@ -611,7 +606,6 @@ func populateCertificates(kongState *state.KongState, file *Content,
return err
}
for _, s := range snis {
s := s
s.Certificate = nil
utils.ZeroOutID(s, s.Name, config.WithID)
utils.ZeroOutTimestamps(s)
Expand Down Expand Up @@ -668,7 +662,6 @@ func populateConsumers(kongState *state.KongState, file *Content,
return err
}
for _, p := range plugins {
p := p
if p.Service != nil || p.Route != nil || p.ConsumerGroup != nil {
continue
}
Expand All @@ -687,7 +680,6 @@ func populateConsumers(kongState *state.KongState, file *Content,
return err
}
for _, k := range keyAuths {
k := k
utils.ZeroOutID(k, k.Key, config.WithID)
utils.ZeroOutTimestamps(k)
utils.MustRemoveTags(k, config.SelectTags)
Expand All @@ -699,7 +691,6 @@ func populateConsumers(kongState *state.KongState, file *Content,
return err
}
for _, k := range hmacAuth {
k := k
k.Consumer = nil
utils.ZeroOutID(k, k.Username, config.WithID)
utils.ZeroOutTimestamps(k)
Expand All @@ -711,7 +702,6 @@ func populateConsumers(kongState *state.KongState, file *Content,
return err
}
for _, k := range jwtSecrets {
k := k
k.Consumer = nil
utils.ZeroOutID(k, k.Key, config.WithID)
utils.ZeroOutTimestamps(k)
Expand All @@ -723,7 +713,6 @@ func populateConsumers(kongState *state.KongState, file *Content,
return err
}
for _, k := range basicAuths {
k := k
k.Consumer = nil
utils.ZeroOutID(k, k.Username, config.WithID)
utils.ZeroOutTimestamps(k)
Expand All @@ -735,7 +724,6 @@ func populateConsumers(kongState *state.KongState, file *Content,
return err
}
for _, k := range oauth2Creds {
k := k
k.Consumer = nil
utils.ZeroOutID(k, k.ClientID, config.WithID)
utils.ZeroOutTimestamps(k)
Expand All @@ -747,7 +735,6 @@ func populateConsumers(kongState *state.KongState, file *Content,
return err
}
for _, k := range aclGroups {
k := k
k.Consumer = nil
utils.ZeroOutID(k, k.Group, config.WithID)
utils.ZeroOutTimestamps(k)
Expand All @@ -759,7 +746,6 @@ func populateConsumers(kongState *state.KongState, file *Content,
return err
}
for _, k := range mtlsAuths {
k := k
utils.ZeroOutTimestamps(k)
utils.MustRemoveTags(k, config.SelectTags)
k.Consumer = nil
Expand Down
1 change: 0 additions & 1 deletion pkg/state/document_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ func TestDocumentCollection_Add(t *testing.T) {
}
k.Add(d1)
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
if err := k.Add(tt.args.document); (err != nil) != tt.wantErr {
Expand Down
4 changes: 0 additions & 4 deletions pkg/state/filter_chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,6 @@ func TestFilterChainsCollection_Add(t *testing.T) {
}

for _, tt := range commonCases {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()

Expand All @@ -259,7 +258,6 @@ func TestFilterChainsCollection_Add(t *testing.T) {
}

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -371,7 +369,6 @@ func TestFilterChainsCollection_Update(t *testing.T) {
})

for _, tt := range commonCases {
tt := tt
if utils.Empty(tt.filterChain.ID) {
continue
}
Expand Down Expand Up @@ -406,7 +403,6 @@ func TestFilterChainsCollection_Update(t *testing.T) {
}

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()

Expand Down
4 changes: 0 additions & 4 deletions pkg/state/license_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ func TestLicenseCollection_Add(t *testing.T) {
}

for _, tc := range testCases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
initialState := state()
c := initialState.Licenses
Expand Down Expand Up @@ -91,7 +90,6 @@ func TestLicenseCollection_Get(t *testing.T) {
}

for _, tc := range testCases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
initialState := state()
c := initialState.Licenses
Expand Down Expand Up @@ -143,7 +141,6 @@ func TestLicenseCollection_Update(t *testing.T) {
}

for _, tc := range testCases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
initialState := state()
c := initialState.Licenses
Expand Down Expand Up @@ -186,7 +183,6 @@ func TestLicenseCollection_Delete(t *testing.T) {
}

for _, tc := range testCases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
initialState := state()
c := initialState.Licenses
Expand Down
Loading

0 comments on commit d53b0d3

Please sign in to comment.