From bf273519d116d4eb37467d5d2c3709b500c3207d Mon Sep 17 00:00:00 2001 From: Dylan Ratcliffe Date: Wed, 14 Feb 2024 16:17:17 +0000 Subject: [PATCH 1/2] Added config --- .golangci.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.golangci.yml b/.golangci.yml index fa040781..531b17f6 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,3 +1,8 @@ linters: presets: - bugs +linters-settings: + govet: + # Report about shadowed variables. + # Default: false + check-shadowing: true From 713446bece8c55df5c1c49dafca6e3bdca040a92 Mon Sep 17 00:00:00 2001 From: Dylan Ratcliffe Date: Wed, 14 Feb 2024 16:25:05 +0000 Subject: [PATCH 2/2] Fixed variable shadowing --- .golangci.yml | 5 ----- cmd/changes_get_change.go | 2 +- cmd/changes_submit_plan.go | 16 ++++++++-------- 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 531b17f6..fa040781 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,8 +1,3 @@ linters: presets: - bugs -linters-settings: - govet: - # Report about shadowed variables. - # Default: false - check-shadowing: true diff --git a/cmd/changes_get_change.go b/cmd/changes_get_change.go index b4046b26..65f54342 100644 --- a/cmd/changes_get_change.go +++ b/cmd/changes_get_change.go @@ -109,7 +109,7 @@ fetch: for { // use the variable to avoid shadowing var err error - riskRes, err := client.GetChangeRisks(ctx, &connect.Request[sdp.GetChangeRisksRequest]{ + riskRes, err = client.GetChangeRisks(ctx, &connect.Request[sdp.GetChangeRisksRequest]{ Msg: &sdp.GetChangeRisksRequest{ UUID: changeUuid[:], }, diff --git a/cmd/changes_submit_plan.go b/cmd/changes_submit_plan.go index 3dfc5718..ab8f3f6f 100644 --- a/cmd/changes_submit_plan.go +++ b/cmd/changes_submit_plan.go @@ -319,7 +319,7 @@ func mappedItemDiffsFromPlan(ctx context.Context, fileName string, lf log.Fields return nil, fmt.Errorf("failed to parse '%v': %w", fileName, err) } - plannedChangeGroups := plannedChangeGroups{ + plannedChangeGroupsVar := plannedChangeGroups{ supported: map[string][]*sdp.MappedItemDiff{}, unsupported: map[string][]*sdp.MappedItemDiff{}, } @@ -343,7 +343,7 @@ func mappedItemDiffsFromPlan(ctx context.Context, fileName string, lf log.Fields if len(mappings) == 0 { log.WithContext(ctx).WithFields(lf).WithField("terraform-address", resourceChange.Address).Debug("Skipping unmapped resource") - plannedChangeGroups.Add(resourceChange.Type, &sdp.MappedItemDiff{ + plannedChangeGroupsVar.Add(resourceChange.Type, &sdp.MappedItemDiff{ Item: itemDiff, MappingQuery: nil, // unmapped item has no mapping query }) @@ -461,7 +461,7 @@ func mappedItemDiffsFromPlan(ctx context.Context, fileName string, lf log.Fields } } - plannedChangeGroups.Add(resourceChange.Type, &sdp.MappedItemDiff{ + plannedChangeGroupsVar.Add(resourceChange.Type, &sdp.MappedItemDiff{ Item: itemDiff, MappingQuery: newQuery, }) @@ -476,13 +476,13 @@ func mappedItemDiffsFromPlan(ctx context.Context, fileName string, lf log.Fields } supported := "" - numSupported := plannedChangeGroups.NumSupportedChanges() + numSupported := plannedChangeGroupsVar.NumSupportedChanges() if numSupported > 0 { supported = Green.Color(fmt.Sprintf("%v supported", numSupported)) } unsupported := "" - numUnsupported := plannedChangeGroups.NumUnsupportedChanges() + numUnsupported := plannedChangeGroupsVar.NumUnsupportedChanges() if numUnsupported > 0 { unsupported = Yellow.Color(fmt.Sprintf("%v unsupported", numUnsupported)) } @@ -499,14 +499,14 @@ func mappedItemDiffsFromPlan(ctx context.Context, fileName string, lf log.Fields } // Log the types - for typ, plannedChanges := range plannedChangeGroups.supported { + for typ, plannedChanges := range plannedChangeGroupsVar.supported { log.WithContext(ctx).Infof(Green.Color(" ✓ %v (%v)"), typ, len(plannedChanges)) } - for typ, plannedChanges := range plannedChangeGroups.unsupported { + for typ, plannedChanges := range plannedChangeGroupsVar.unsupported { log.WithContext(ctx).Infof(Yellow.Color(" ✗ %v (%v)"), typ, len(plannedChanges)) } - return plannedChangeGroups.MappedItemDiffs(), nil + return plannedChangeGroupsVar.MappedItemDiffs(), nil } func changeTitle(arg string) string {