Skip to content
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

linter: Add perfsprint #39975

Merged
merged 10 commits into from
Nov 4, 2024
1 change: 1 addition & 0 deletions .ci/.golangci2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ linters-settings:
- strconv.ParseFloat
- strconv.ParseInt
- strings.SplitN
# - big.Int.Text # Not sure how to specify a method

run:
timeout: 75m
7 changes: 7 additions & 0 deletions .ci/.golangci3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ linters:
- nolintlint
- nosprintfhostport
- paralleltest
- perfsprint
- predeclared
- revive
- staticcheck
Expand All @@ -154,6 +155,12 @@ linters-settings:
- paralleltest
- tparallel
- unparam
perfsprint:
int-conversion: true
err-error: false
errorf: false
sprintf1: true
strconcat: false
predeclared:
ignore: cap,close,copy,delete,len,new,min,max
revive:
Expand Down
6 changes: 3 additions & 3 deletions internal/acctest/acctest.go
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@ func CheckResourceAttrJMES(name, key, jmesPath, value string) resource.TestCheck
case float64:
v = strconv.FormatFloat(x, 'f', -1, 64)
case bool:
v = fmt.Sprint(x)
v = strconv.FormatBool(x)
default:
return fmt.Errorf(`%[1]s: Attribute %[2]q, JMESPath %[3]q got "%#[4]v" (%[4]T)`, name, key, jmesPath, result)
}
Expand Down Expand Up @@ -767,7 +767,7 @@ func CheckResourceAttrJMESPair(nameFirst, keyFirst, jmesPath, nameSecond, keySec
case float64:
value = strconv.FormatFloat(x, 'f', -1, 64)
case bool:
value = fmt.Sprint(x)
value = strconv.FormatBool(x)
default:
return fmt.Errorf(`%[1]s: Attribute %[2]q, JMESPath %[3]q got "%#[4]v" (%[4]T)`, nameFirst, keyFirst, jmesPath, result)
}
Expand Down Expand Up @@ -817,7 +817,7 @@ func CheckResourceAttrJMESNotExists(name, key, jmesPath string) resource.TestChe
case float64:
v = strconv.FormatFloat(x, 'f', -1, 64)
case bool:
v = fmt.Sprint(x)
v = strconv.FormatBool(x)
default:
return fmt.Errorf(`%[1]s: Attribute %[2]q, JMESPath %[3]q got "%#[4]v" (%[4]T), expected no attribute`, name, key, jmesPath, result)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/service/acmpca/certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ func resourceCertificateRevoke(ctx context.Context, d *schema.ResourceData, meta
log.Printf("[INFO] Revoking ACM PCA Certificate: %s", d.Id())
_, err = conn.RevokeCertificate(ctx, &acmpca.RevokeCertificateInput{
CertificateAuthorityArn: aws.String(d.Get("certificate_authority_arn").(string)),
CertificateSerial: aws.String(fmt.Sprintf("%x", serial)),
CertificateSerial: aws.String(serial.Text(16)), //nolint:mnd // Should be excluded, but not sure how to specify a method
RevocationReason: types.RevocationReasonUnspecified,
})

Expand Down
3 changes: 2 additions & 1 deletion internal/service/apigateway/authorizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"context"
"fmt"
"log"
"strconv"
"strings"

"github.com/aws/aws-sdk-go-v2/aws"
Expand Down Expand Up @@ -254,7 +255,7 @@ func resourceAuthorizerUpdate(ctx context.Context, d *schema.ResourceData, meta
operations = append(operations, types.PatchOperation{
Op: types.OpReplace,
Path: aws.String("/authorizerResultTtlInSeconds"),
Value: aws.String(fmt.Sprintf("%d", d.Get("authorizer_result_ttl_in_seconds").(int))),
Value: aws.String(strconv.Itoa(d.Get("authorizer_result_ttl_in_seconds").(int))),
})
}
if d.HasChange("identity_validation_expression") {
Expand Down
3 changes: 2 additions & 1 deletion internal/service/apigateway/method.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"context"
"fmt"
"log"
"strconv"
"strings"

"github.com/aws/aws-sdk-go-v2/aws"
Expand Down Expand Up @@ -249,7 +250,7 @@ func resourceMethodUpdate(ctx context.Context, d *schema.ResourceData, meta inte
operations = append(operations, types.PatchOperation{
Op: types.OpReplace,
Path: aws.String("/apiKeyRequired"),
Value: aws.String(fmt.Sprintf("%t", d.Get("api_key_required").(bool))),
Value: aws.String(strconv.FormatBool(d.Get("api_key_required").(bool))),
})
}

Expand Down
15 changes: 8 additions & 7 deletions internal/service/apigateway/method_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"context"
"fmt"
"log"
"strconv"
"strings"

"github.com/aws/aws-sdk-go-v2/aws"
Expand Down Expand Up @@ -175,7 +176,7 @@ func resourceMethodSettingsUpdate(ctx context.Context, d *schema.ResourceData, m
ops = append(ops, types.PatchOperation{
Op: types.OpReplace,
Path: aws.String(prefix + "metrics/enabled"),
Value: aws.String(fmt.Sprintf("%t", d.Get("settings.0.metrics_enabled").(bool))),
Value: aws.String(strconv.FormatBool(d.Get("settings.0.metrics_enabled").(bool))),
})
}
if d.HasChange("settings.0.logging_level") {
Expand All @@ -189,14 +190,14 @@ func resourceMethodSettingsUpdate(ctx context.Context, d *schema.ResourceData, m
ops = append(ops, types.PatchOperation{
Op: types.OpReplace,
Path: aws.String(prefix + "logging/dataTrace"),
Value: aws.String(fmt.Sprintf("%t", d.Get("settings.0.data_trace_enabled").(bool))),
Value: aws.String(strconv.FormatBool(d.Get("settings.0.data_trace_enabled").(bool))),
})
}
if d.HasChange("settings.0.throttling_burst_limit") {
ops = append(ops, types.PatchOperation{
Op: types.OpReplace,
Path: aws.String(prefix + "throttling/burstLimit"),
Value: aws.String(fmt.Sprintf("%d", d.Get("settings.0.throttling_burst_limit").(int))),
Value: aws.String(strconv.Itoa(d.Get("settings.0.throttling_burst_limit").(int))),
})
}
if d.HasChange("settings.0.throttling_rate_limit") {
Expand All @@ -210,28 +211,28 @@ func resourceMethodSettingsUpdate(ctx context.Context, d *schema.ResourceData, m
ops = append(ops, types.PatchOperation{
Op: types.OpReplace,
Path: aws.String(prefix + "caching/enabled"),
Value: aws.String(fmt.Sprintf("%t", d.Get("settings.0.caching_enabled").(bool))),
Value: aws.String(strconv.FormatBool(d.Get("settings.0.caching_enabled").(bool))),
})
}
if v, ok := d.GetOkExists("settings.0.cache_ttl_in_seconds"); ok {
ops = append(ops, types.PatchOperation{
Op: types.OpReplace,
Path: aws.String(prefix + "caching/ttlInSeconds"),
Value: aws.String(fmt.Sprintf("%d", v.(int))),
Value: aws.String(strconv.Itoa(v.(int))),
})
}
if d.HasChange("settings.0.cache_data_encrypted") {
ops = append(ops, types.PatchOperation{
Op: types.OpReplace,
Path: aws.String(prefix + "caching/dataEncrypted"),
Value: aws.String(fmt.Sprintf("%t", d.Get("settings.0.cache_data_encrypted").(bool))),
Value: aws.String(strconv.FormatBool(d.Get("settings.0.cache_data_encrypted").(bool))),
})
}
if d.HasChange("settings.0.require_authorization_for_cache_control") {
ops = append(ops, types.PatchOperation{
Op: types.OpReplace,
Path: aws.String(prefix + "caching/requireAuthorizationForCacheControl"),
Value: aws.String(fmt.Sprintf("%t", d.Get("settings.0.require_authorization_for_cache_control").(bool))),
Value: aws.String(strconv.FormatBool(d.Get("settings.0.require_authorization_for_cache_control").(bool))),
})
}
if d.HasChange("settings.0.unauthorized_cache_control_header_strategy") {
Expand Down
5 changes: 3 additions & 2 deletions internal/service/apigateway/request_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"context"
"fmt"
"log"
"strconv"
"strings"

"github.com/aws/aws-sdk-go-v2/aws"
Expand Down Expand Up @@ -132,15 +133,15 @@ func resourceRequestValidatorUpdate(ctx context.Context, d *schema.ResourceData,
operations = append(operations, types.PatchOperation{
Op: types.OpReplace,
Path: aws.String("/validateRequestBody"),
Value: aws.String(fmt.Sprintf("%t", d.Get("validate_request_body").(bool))),
Value: aws.String(strconv.FormatBool(d.Get("validate_request_body").(bool))),
})
}

if d.HasChange("validate_request_parameters") {
operations = append(operations, types.PatchOperation{
Op: types.OpReplace,
Path: aws.String("/validateRequestParameters"),
Value: aws.String(fmt.Sprintf("%t", d.Get("validate_request_parameters").(bool))),
Value: aws.String(strconv.FormatBool(d.Get("validate_request_parameters").(bool))),
})
}

Expand Down
7 changes: 4 additions & 3 deletions internal/service/apigateway/stage.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"context"
"fmt"
"log"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -300,7 +301,7 @@ func resourceStageUpdate(ctx context.Context, d *schema.ResourceData, meta inter
operations = append(operations, types.PatchOperation{
Op: types.OpReplace,
Path: aws.String("/cacheClusterEnabled"),
Value: aws.String(fmt.Sprintf("%t", d.Get("cache_cluster_enabled").(bool))),
Value: aws.String(strconv.FormatBool(d.Get("cache_cluster_enabled").(bool))),
})
waitForCache = true
}
Expand Down Expand Up @@ -352,7 +353,7 @@ func resourceStageUpdate(ctx context.Context, d *schema.ResourceData, meta inter
operations = append(operations, types.PatchOperation{
Op: types.OpReplace,
Path: aws.String("/tracingEnabled"),
Value: aws.String(fmt.Sprintf("%t", d.Get("xray_tracing_enabled").(bool))),
Value: aws.String(strconv.FormatBool(d.Get("xray_tracing_enabled").(bool))),
})
}
if d.HasChange("documentation_version") {
Expand Down Expand Up @@ -644,7 +645,7 @@ func appendCanarySettingsPatchOperations(operations []types.PatchOperation, oldC
operations = append(operations, types.PatchOperation{
Op: types.OpReplace,
Path: aws.String("/canarySettings/useStageCache"),
Value: aws.String(fmt.Sprintf("%t", newUseStageCache)),
Value: aws.String(strconv.FormatBool(newUseStageCache)),
})
}

Expand Down
3 changes: 2 additions & 1 deletion internal/service/cloudtrail/trail_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package cloudtrail_test
import (
"context"
"fmt"
"strconv"
"testing"

"github.com/YakDriver/regexache"
Expand Down Expand Up @@ -834,7 +835,7 @@ func testAccCheckLogValidationEnabled(n string, desired bool, trail *types.Trail
return fmt.Errorf("No enable_log_file_validation attribute defined for %s, expected %t",
n, desired)
}
desiredInString := fmt.Sprintf("%t", desired)
desiredInString := strconv.FormatBool(desired)
if enabled != desiredInString {
return fmt.Errorf("Expected log validation status %s, saved %s", desiredInString, enabled)
}
Expand Down
3 changes: 2 additions & 1 deletion internal/service/ec2/ec2_ami_ids_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"context"
"fmt"
"slices"
"strconv"
"time"

"github.com/YakDriver/regexache"
Expand Down Expand Up @@ -131,7 +132,7 @@ func dataSourceAMIIDsRead(ctx context.Context, d *schema.ResourceData, meta inte
imageIDs = append(imageIDs, aws.ToString(image.ImageId))
}

d.SetId(fmt.Sprintf("%d", create.StringHashcode(fmt.Sprintf("%#v", input))))
d.SetId(strconv.Itoa(create.StringHashcode(fmt.Sprintf("%#v", input))))
d.Set(names.AttrIDs, imageIDs)

return diags
Expand Down
6 changes: 3 additions & 3 deletions internal/service/ec2/ec2_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1290,23 +1290,23 @@ func TestAccEC2Instance_IPv6AddressCount(t *testing.T) {
Config: testAccInstance_ipv6AddressCount(rName, originalCount),
Check: resource.ComposeTestCheckFunc(
testAccCheckInstanceExists(ctx, resourceName, &original),
resource.TestCheckResourceAttr(resourceName, "ipv6_address_count", fmt.Sprint(originalCount)),
resource.TestCheckResourceAttr(resourceName, "ipv6_address_count", strconv.Itoa(originalCount)),
),
},
{
Config: testAccInstance_ipv6AddressCount(rName, updatedCount),
Check: resource.ComposeTestCheckFunc(
testAccCheckInstanceExists(ctx, resourceName, &updated),
testAccCheckInstanceNotRecreated(&original, &updated),
resource.TestCheckResourceAttr(resourceName, "ipv6_address_count", fmt.Sprint(updatedCount)),
resource.TestCheckResourceAttr(resourceName, "ipv6_address_count", strconv.Itoa(updatedCount)),
),
},
{
Config: testAccInstance_ipv6AddressCount(rName, shrunkenCount),
Check: resource.ComposeTestCheckFunc(
testAccCheckInstanceExists(ctx, resourceName, &updated),
testAccCheckInstanceNotRecreated(&original, &updated),
resource.TestCheckResourceAttr(resourceName, "ipv6_address_count", fmt.Sprint(shrunkenCount)),
resource.TestCheckResourceAttr(resourceName, "ipv6_address_count", strconv.Itoa(shrunkenCount)),
),
},
},
Expand Down
7 changes: 4 additions & 3 deletions internal/service/events/api_destination_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package events_test
import (
"context"
"fmt"
"strconv"
"testing"

"github.com/YakDriver/regexache"
Expand Down Expand Up @@ -130,7 +131,7 @@ func TestAccEventsAPIDestination_optional(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "http_method", httpMethod),
resource.TestCheckResourceAttr(resourceName, "invocation_endpoint", invocationEndpoint),
resource.TestCheckResourceAttr(resourceName, names.AttrDescription, description),
resource.TestCheckResourceAttr(resourceName, "invocation_rate_limit_per_second", fmt.Sprint(invocationRateLimitPerSecond)),
resource.TestCheckResourceAttr(resourceName, "invocation_rate_limit_per_second", strconv.Itoa(invocationRateLimitPerSecond)),
),
},
{
Expand All @@ -153,7 +154,7 @@ func TestAccEventsAPIDestination_optional(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "http_method", httpMethodModified),
resource.TestCheckResourceAttr(resourceName, "invocation_endpoint", invocationEndpointModified),
resource.TestCheckResourceAttr(resourceName, names.AttrDescription, descriptionModified),
resource.TestCheckResourceAttr(resourceName, "invocation_rate_limit_per_second", fmt.Sprint(invocationRateLimitPerSecondModified)),
resource.TestCheckResourceAttr(resourceName, "invocation_rate_limit_per_second", strconv.Itoa(invocationRateLimitPerSecondModified)),
),
},
{
Expand All @@ -171,7 +172,7 @@ func TestAccEventsAPIDestination_optional(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "http_method", httpMethodModified),
resource.TestCheckResourceAttr(resourceName, "invocation_endpoint", invocationEndpointModified),
resource.TestCheckResourceAttr(resourceName, names.AttrDescription, descriptionModified),
resource.TestCheckResourceAttr(resourceName, "invocation_rate_limit_per_second", fmt.Sprint(invocationRateLimitPerSecond)),
resource.TestCheckResourceAttr(resourceName, "invocation_rate_limit_per_second", strconv.Itoa(invocationRateLimitPerSecond)),
),
},
},
Expand Down
Loading
Loading