Skip to content

chore: Remove unneeded Go linter exceptions #3247

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Apr 9, 2025
2 changes: 1 addition & 1 deletion internal/common/conversion/string_framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func ToTFMapOfSlices(ctx context.Context, values map[string][]string) (basetypes
return types.MapValueFrom(ctx, types.ListType{ElemType: types.StringType}, values)
}

func ToTFMapOfString(ctx context.Context, diags *diag.Diagnostics, values *map[string]string) basetypes.MapValue { //nolint:gocritic // easy usage from sdk fields
func ToTFMapOfString(ctx context.Context, diags *diag.Diagnostics, values map[string]string) basetypes.MapValue {
if values == nil {
return basetypes.NewMapNull(types.StringType)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2081,10 +2081,9 @@ func configAdvanced(t *testing.T, usePreviewProvider bool, projectID, clusterNam
if p.TlsCipherConfigMode != nil {
tlsCipherConfigModeStr = fmt.Sprintf(`tls_cipher_config_mode = %[1]q`, *p.TlsCipherConfigMode)
if p.CustomOpensslCipherConfigTls12 != nil && len(*p.CustomOpensslCipherConfigTls12) > 0 {
//nolint:gocritic // reason: simplifying string array construction
customOpensslCipherConfigTLS12Str = fmt.Sprintf(
`custom_openssl_cipher_config_tls12 = ["%s"]`,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixes: sprintfQuotedString: use %q instead of "%s" for quoted strings (gocritic)

strings.Join(*p.CustomOpensslCipherConfigTls12, `", "`),
`custom_openssl_cipher_config_tls12 = [%s]`,
acc.JoinQuotedStrings(*p.CustomOpensslCipherConfigTls12),
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func NewLabelsObjType(ctx context.Context, diags *diag.Diagnostics, input *[]adm
elms[key] = value
}
}
return conversion.ToTFMapOfString(ctx, diags, &elms)
return conversion.ToTFMapOfString(ctx, diags, elms)
}

func NewReplicationSpecsObjType(ctx context.Context, input *[]admin.ReplicationSpec20240805, diags *diag.Diagnostics, apiInfo *ExtraAPIInfo) types.List {
Expand Down Expand Up @@ -159,7 +159,7 @@ func convertReplicationSpecs(ctx context.Context, input *[]admin.ReplicationSpec
Id: types.StringValue(legacyID),
ExternalId: types.StringValue(conversion.SafeValue(item.Id)),
NumShards: types.Int64Value(1),
ContainerId: conversion.ToTFMapOfString(ctx, diags, &containerIDs),
ContainerId: conversion.ToTFMapOfString(ctx, diags, containerIDs),
RegionConfigs: regionConfigs,
ZoneId: types.StringValue(conversion.SafeValue(item.ZoneId)),
ZoneName: types.StringValue(conversion.SafeValue(item.ZoneName)),
Expand Down Expand Up @@ -218,7 +218,7 @@ func convertReplicationSpecsLegacy(ctx context.Context, input *[]admin.Replicati
}
containerIDs := selectContainerIDs(&item, apiInfo.ContainerIDs)
tfModels = append(tfModels, TFReplicationSpecsModel{
ContainerId: conversion.ToTFMapOfString(ctx, diags, &containerIDs),
ContainerId: conversion.ToTFMapOfString(ctx, diags, containerIDs),
ExternalId: types.StringValue(""), // Not meaningful with legacy schema
Id: types.StringValue(legacyID),
RegionConfigs: regionConfigs,
Expand All @@ -237,7 +237,7 @@ func NewTagsObjType(ctx context.Context, diags *diag.Diagnostics, input *[]admin
elms[item.GetKey()] = item.GetValue()
}
}
return conversion.ToTFMapOfString(ctx, diags, &elms)
return conversion.ToTFMapOfString(ctx, diags, elms)
}

func NewPrivateEndpointObjType(ctx context.Context, input *[]admin.ClusterDescriptionConnectionStringsPrivateEndpoint, diags *diag.Diagnostics) types.List {
Expand Down
15 changes: 6 additions & 9 deletions internal/service/cluster/resource_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"os"
"regexp"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -1472,10 +1471,9 @@ func configAdvancedConf(projectID, name, autoscalingEnabled string,
if p.TlsCipherConfigMode != nil {
tlsCipherConfigModeStr = fmt.Sprintf(`tls_cipher_config_mode = %[1]q`, *p.TlsCipherConfigMode)
if p.CustomOpensslCipherConfigTls12 != nil && len(*p.CustomOpensslCipherConfigTls12) > 0 {
//nolint:gocritic // reason: simplifying string array construction
customOpensslCipherConfigTLS12Str = fmt.Sprintf(
`custom_openssl_cipher_config_tls12 = ["%s"]`,
strings.Join(*p.CustomOpensslCipherConfigTls12, `", "`),
`custom_openssl_cipher_config_tls12 = [%s]`,
acc.JoinQuotedStrings(*p.CustomOpensslCipherConfigTls12),
)
}
}
Expand Down Expand Up @@ -1577,10 +1575,9 @@ func configAdvancedConfPartial(projectID, name, autoscalingEnabled string, p *ad
if p.TlsCipherConfigMode != nil {
tlsCipherConfigModeStr = fmt.Sprintf(`tls_cipher_config_mode = %[1]q`, *p.TlsCipherConfigMode)
if p.CustomOpensslCipherConfigTls12 != nil && len(*p.CustomOpensslCipherConfigTls12) > 0 {
//nolint:gocritic // reason: simplifying string array construction
customOpensslCipherConfigTLS12Str = fmt.Sprintf(
`custom_openssl_cipher_config_tls12 = ["%s"]`,
strings.Join(*p.CustomOpensslCipherConfigTls12, `", "`),
`custom_openssl_cipher_config_tls12 = [%s]`,
acc.JoinQuotedStrings(*p.CustomOpensslCipherConfigTls12),
)
}
}
Expand Down Expand Up @@ -1900,8 +1897,8 @@ func testAccMongoDBAtlasClusterAWSConfigdWithLabels(projectID, name, backupEnabl
for _, label := range labels {
labelsConf += fmt.Sprintf(`
labels {
key = "%s"
value = "%s"
key = %q
value = %q
}
`, label.Key, label.Value)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
//nolint:gocritic
package encryptionatrestprivateendpoint

import (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
//nolint:gocritic
package encryptionatrestprivateendpoint

import (
Expand Down
9 changes: 9 additions & 0 deletions internal/testutil/acc/advanced_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package acc
import (
"context"
"fmt"
"strings"
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
Expand Down Expand Up @@ -232,3 +233,11 @@ func ConfigBasicDedicated(projectID, name, zoneName string) string {
}
`, projectID, name, zoneNameLine)
}

func JoinQuotedStrings(list []string) string {
quoted := make([]string, len(list))
for i, item := range list {
quoted[i] = fmt.Sprintf("%q", item)
}
return strings.Join(quoted, ", ")
}
2 changes: 1 addition & 1 deletion internal/testutil/unit/http_mocker.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type MockHTTPDataConfig struct {
IsDiffMustSubstrings []string // Only include diff request for specific substrings, for example /clusters (avoids project create requests)
QueryVars []string // Substitute this query vars. Useful when differentiating responses based on query args, for example ?providerName=AWS/AZURE returns different responses
AllowMissingRequests bool // When false will require all API calls to be made.
AllowOutOfOrder bool // When true will allow a GET request returned after a POST to be returned before the POST.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think AllowOutOfOrder is not being used anymore, can @EspenAlbert you please confirm?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although not used anywhere in the code, it can be helpful while debugging. I would prefer to keep it

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, keeping, adding comment

AllowOutOfOrder bool // When true will allow a GET request returned after a POST to be returned before the POST. Not used but kept for debugging.
}

func (c MockHTTPDataConfig) WithAllowOutOfOrder() MockHTTPDataConfig { //nolint: gocritic // Want each test run to have its own config (hugeParam: c is heavy (112 bytes); consider passing it by pointer)
Expand Down
Loading