Skip to content

Commit 84181c7

Browse files
sichanyooSichan Yoo
and
Sichan Yoo
authored
chore: ktlint & swiftlint version bumps (#1887)
* Update swiftlint version, ktlint version, and fix new lint warnings. * Make warnings fail swiftlint as well. --------- Co-authored-by: Sichan Yoo <[email protected]>
1 parent a96c824 commit 84181c7

File tree

109 files changed

+1879
-1185
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

109 files changed

+1879
-1185
lines changed

.github/workflows/lint.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ jobs:
2020
if: github.repository == 'awslabs/aws-sdk-swift' || github.event_name == 'pull_request'
2121
runs-on: ubuntu-latest
2222
container:
23-
image: ghcr.io/realm/swiftlint:0.54.0
23+
image: ghcr.io/realm/swiftlint:0.58.2
2424
steps:
2525
- name: Checkout sources
2626
uses: actions/checkout@v2
2727
- name: Run swiftlint on AWSClientRuntime
28-
run: swiftlint --reporter github-actions-logging
28+
run: swiftlint --strict --reporter github-actions-logging

build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ allprojects {
1818
val ktlint by configurations.creating
1919
val ktlintVersion: String by project
2020
dependencies {
21-
ktlint("com.pinterest:ktlint:$ktlintVersion")
21+
ktlint("com.pinterest.ktlint:ktlint-cli:$ktlintVersion")
2222
}
2323

2424
val lintPaths = listOf(

codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/AWSAuthUtils.kt

+15-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import software.amazon.smithy.swift.codegen.model.hasTrait
2121
import software.amazon.smithy.swift.codegen.utils.AuthUtils
2222

2323
open class AWSAuthUtils(
24-
private val ctx: ProtocolGenerator.GenerationContext
24+
private val ctx: ProtocolGenerator.GenerationContext,
2525
) : AuthUtils(ctx) {
2626
companion object {
2727
/**
@@ -31,12 +31,16 @@ open class AWSAuthUtils(
3131
* @param serviceShape service shape for the API
3232
* @return if the SigV4 trait is used by the service.
3333
*/
34-
fun isSupportedAuthentication(model: Model, serviceShape: ServiceShape): Boolean =
34+
fun isSupportedAuthentication(
35+
model: Model,
36+
serviceShape: ServiceShape,
37+
): Boolean =
3538
ServiceIndex
3639
.of(model)
3740
.getAuthSchemes(serviceShape)
3841
.values
3942
.any { it.javaClass == SigV4Trait::class.java }
43+
4044
/**
4145
* Get the SigV4Trait auth name to sign request for
4246
*
@@ -56,13 +60,20 @@ open class AWSAuthUtils(
5660
* @param operation operation shape
5761
* @return if SigV4Trait is an auth scheme for the operation and service.
5862
*/
59-
fun hasSigV4AuthScheme(model: Model, service: ServiceShape, operation: OperationShape): Boolean {
63+
fun hasSigV4AuthScheme(
64+
model: Model,
65+
service: ServiceShape,
66+
operation: OperationShape,
67+
): Boolean {
6068
val auth = ServiceIndex.of(model).getEffectiveAuthSchemes(service.id, operation.id)
6169
return auth.containsKey(SigV4Trait.ID) && !operation.hasTrait<OptionalAuthTrait>()
6270
}
6371
}
6472

65-
override fun addAdditionalSchemes(writer: SwiftWriter, authSchemeList: MutableList<String>): List<String> {
73+
override fun addAdditionalSchemes(
74+
writer: SwiftWriter,
75+
authSchemeList: MutableList<String>,
76+
): List<String> {
6677
val effectiveAuthSchemes = ServiceIndex(ctx.model).getEffectiveAuthSchemes(ctx.service)
6778

6879
val sdkId = AuthSchemeResolverGenerator.getSdkId(ctx)

codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/AWSClientConfigurationIntegration.kt

+9-6
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,14 @@ import software.amazon.smithy.swift.codegen.integration.SwiftIntegration
1919
import software.amazon.smithy.swift.codegen.integration.plugins.DefaultAWSClientPlugin
2020

2121
class AWSClientConfigurationIntegration : SwiftIntegration {
22-
override fun clientConfigurations(ctx: ProtocolGenerator.GenerationContext): List<ClientConfiguration> {
23-
return listOf(AWSDefaultClientConfiguration(), AWSRegionClientConfiguration(), AWSEndpointClientConfiguration(ctx))
24-
}
22+
override fun clientConfigurations(ctx: ProtocolGenerator.GenerationContext): List<ClientConfiguration> =
23+
listOf(AWSDefaultClientConfiguration(), AWSRegionClientConfiguration(), AWSEndpointClientConfiguration(ctx))
2524

26-
override fun plugins(serviceConfig: ServiceConfig): List<Plugin> {
27-
return listOf(DefaultAWSClientPlugin(), EndpointPlugin(serviceConfig), DefaultAWSAuthSchemePlugin(serviceConfig), AuthSchemePlugin(serviceConfig))
28-
}
25+
override fun plugins(serviceConfig: ServiceConfig): List<Plugin> =
26+
listOf(
27+
DefaultAWSClientPlugin(),
28+
EndpointPlugin(serviceConfig),
29+
DefaultAWSAuthSchemePlugin(serviceConfig),
30+
AuthSchemePlugin(serviceConfig),
31+
)
2932
}

codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/AWSHTTPBindingProtocolGenerator.kt

+14-11
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import software.amazon.smithy.swift.codegen.testModuleName
2626
abstract class AWSHTTPBindingProtocolGenerator(
2727
customizations: HTTPProtocolCustomizable,
2828
) : HTTPBindingProtocolGenerator(customizations) {
29-
3029
override var serviceErrorProtocolSymbol: Symbol = AWSClientRuntimeTypes.Core.AWSServiceError
3130

3231
override val retryErrorInfoProviderSymbol: Symbol
@@ -41,8 +40,9 @@ abstract class AWSHTTPBindingProtocolGenerator(
4140
open val protocolTestTagsToIgnore: Set<String> = setOf()
4241

4342
override val shouldRenderEncodableConformance = false
44-
override fun generateProtocolUnitTests(ctx: ProtocolGenerator.GenerationContext): Int {
45-
return HttpProtocolTestGenerator(
43+
44+
override fun generateProtocolUnitTests(ctx: ProtocolGenerator.GenerationContext): Int =
45+
HttpProtocolTestGenerator(
4646
ctx,
4747
requestTestBuilder,
4848
responseTestBuilder,
@@ -52,11 +52,8 @@ abstract class AWSHTTPBindingProtocolGenerator(
5252
protocolTestsToIgnore,
5353
protocolTestTagsToIgnore,
5454
).generateProtocolTests() + renderEndpointsTests(ctx)
55-
}
5655

57-
override fun generateSmokeTests(ctx: ProtocolGenerator.GenerationContext) {
58-
return AWSSmokeTestGenerator(ctx).generateSmokeTests()
59-
}
56+
override fun generateSmokeTests(ctx: ProtocolGenerator.GenerationContext) = AWSSmokeTestGenerator(ctx).generateSmokeTests()
6057

6158
fun renderEndpointsTests(ctx: ProtocolGenerator.GenerationContext): Int {
6259
val ruleSetNode = ctx.service.getTrait<EndpointRuleSetTrait>()?.ruleSet
@@ -69,21 +66,27 @@ abstract class AWSHTTPBindingProtocolGenerator(
6966
}
7067

7168
ctx.delegator.useFileWriter("Tests/${ctx.settings.testModuleName}/EndpointResolverTest.swift") { swiftWriter ->
72-
testCount = + EndpointTestGenerator(testsTrait, ruleSet, ctx).render(swiftWriter)
69+
testCount = +EndpointTestGenerator(testsTrait, ruleSet, ctx).render(swiftWriter)
7370
}
7471
}
7572

7673
return testCount
7774
}
7875

79-
override fun addProtocolSpecificMiddleware(ctx: ProtocolGenerator.GenerationContext, operation: OperationShape) {
76+
override fun addProtocolSpecificMiddleware(
77+
ctx: ProtocolGenerator.GenerationContext,
78+
operation: OperationShape,
79+
) {
8080
operationMiddleware.appendMiddleware(
8181
operation,
82-
AWSOperationEndpointResolverMiddleware(ctx, customizations.endpointMiddlewareSymbol)
82+
AWSOperationEndpointResolverMiddleware(ctx, customizations.endpointMiddlewareSymbol),
8383
)
8484
}
8585

86-
override fun addUserAgentMiddleware(ctx: ProtocolGenerator.GenerationContext, operation: OperationShape) {
86+
override fun addUserAgentMiddleware(
87+
ctx: ProtocolGenerator.GenerationContext,
88+
operation: OperationShape,
89+
) {
8790
operationMiddleware.appendMiddleware(operation, UserAgentMiddleware(ctx.settings))
8891
}
8992
}

codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/AWSHTTPProtocolCustomizations.kt

+9-7
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,12 @@ import software.amazon.smithy.swift.codegen.model.isInputEventStream
2323
import software.amazon.smithy.swift.codegen.model.isOutputEventStream
2424

2525
abstract class AWSHTTPProtocolCustomizations : DefaultHTTPProtocolCustomizations() {
26-
27-
override fun renderContextAttributes(ctx: ProtocolGenerator.GenerationContext, writer: SwiftWriter, serviceShape: ServiceShape, op: OperationShape) {
26+
override fun renderContextAttributes(
27+
ctx: ProtocolGenerator.GenerationContext,
28+
writer: SwiftWriter,
29+
serviceShape: ServiceShape,
30+
op: OperationShape,
31+
) {
2832
// FIXME handle indentation properly or do swift formatting after the fact
2933
val config = AWSServiceConfig(writer, ctx)
3034
if (config.serviceSpecificConfigProperties().any { it.memberName == "accountIdEndpointMode" }) {
@@ -45,7 +49,7 @@ abstract class AWSHTTPProtocolCustomizations : DefaultHTTPProtocolCustomizations
4549
override fun renderEventStreamAttributes(
4650
ctx: ProtocolGenerator.GenerationContext,
4751
writer: SwiftWriter,
48-
op: OperationShape
52+
op: OperationShape,
4953
) {
5054
if (op.isInputEventStream(ctx.model) && op.isOutputEventStream(ctx.model)) {
5155
writer.write("\$N(context: context)", AWSSDKEventStreamsAuthTypes.setupBidirectionalStreaming)
@@ -67,10 +71,8 @@ abstract class AWSHTTPProtocolCustomizations : DefaultHTTPProtocolCustomizations
6771
override fun serviceClient(
6872
ctx: ProtocolGenerator.GenerationContext,
6973
writer: SwiftWriter,
70-
serviceConfig: ServiceConfig
71-
): HttpProtocolServiceClient {
72-
return AWSHttpProtocolServiceClient(ctx, writer, serviceConfig)
73-
}
74+
serviceConfig: ServiceConfig,
75+
): HttpProtocolServiceClient = AWSHttpProtocolServiceClient(ctx, writer, serviceConfig)
7476

7577
override val endpointMiddlewareSymbol: Symbol = AWSClientRuntimeTypes.Core.AWSEndpointResolverMiddleware
7678

codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/AWSHttpProtocolClientGeneratorFactory.kt

+10-2
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,17 @@ class AWSHttpProtocolClientGeneratorFactory : HttpProtocolClientGeneratorFactory
2121
serviceName: String,
2222
defaultContentType: String,
2323
httpProtocolCustomizable: HTTPProtocolCustomizable,
24-
operationMiddleware: OperationMiddleware
24+
operationMiddleware: OperationMiddleware,
2525
): HttpProtocolClientGenerator {
2626
val config = AWSServiceConfig(writer, ctx)
27-
return HttpProtocolClientGenerator(ctx, writer, config, httpBindingResolver, defaultContentType, httpProtocolCustomizable, operationMiddleware)
27+
return HttpProtocolClientGenerator(
28+
ctx,
29+
writer,
30+
config,
31+
httpBindingResolver,
32+
defaultContentType,
33+
httpProtocolCustomizable,
34+
operationMiddleware,
35+
)
2836
}
2937
}

codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/AWSHttpProtocolServiceClient.kt

+17-13
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import software.amazon.smithy.swift.codegen.utils.toUpperCamelCase
3030
class AWSHttpProtocolServiceClient(
3131
private val ctx: ProtocolGenerator.GenerationContext,
3232
private val writer: SwiftWriter,
33-
private val serviceConfig: ServiceConfig
33+
private val serviceConfig: ServiceConfig,
3434
) : HttpProtocolServiceClient(ctx, writer, serviceConfig) {
3535
override fun renderConvenienceInitFunctions(serviceSymbol: Symbol) {
3636
writer.openBlock("public convenience init(region: \$N) throws {", "}", SwiftTypes.String) {
@@ -44,22 +44,26 @@ class AWSHttpProtocolServiceClient(
4444
}
4545
}
4646

47-
override fun overrideConfigProperties(properties: List<ConfigProperty>): List<ConfigProperty> {
48-
return properties.mapNotNull { property ->
47+
override fun overrideConfigProperties(properties: List<ConfigProperty>): List<ConfigProperty> =
48+
properties.mapNotNull { property ->
4949
when (property.name) {
5050
"authSchemeResolver" -> {
5151
ConfigProperty("authSchemeResolver", SmithyHTTPAuthAPITypes.AuthSchemeResolver, authSchemeResolverDefaultProvider)
5252
}
5353
"authSchemes" -> {
54-
ConfigProperty("authSchemes", SmithyHTTPAuthAPITypes.AuthSchemes.toOptional(), AWSAuthUtils(ctx).authSchemesDefaultProvider)
54+
ConfigProperty(
55+
"authSchemes",
56+
SmithyHTTPAuthAPITypes.AuthSchemes.toOptional(),
57+
AWSAuthUtils(ctx).authSchemesDefaultProvider,
58+
)
5559
}
5660
"bearerTokenIdentityResolver" -> {
5761
if (AuthUtils(ctx).isSupportedAuthScheme(HttpBearerAuthTrait.ID)) {
5862
ConfigProperty(
5963
"bearerTokenIdentityResolver",
6064
SmithyIdentityTypes.BearerTokenIdentityResolver.toGeneric(),
6165
{ it.format("\$N()", AWSSDKIdentityTypes.DefaultBearerTokenIdentityResolverChain) },
62-
true
66+
true,
6367
)
6468
} else {
6569
property
@@ -70,7 +74,7 @@ class AWSHttpProtocolServiceClient(
7074
"retryStrategyOptions",
7175
SmithyRetriesAPITypes.RetryStrategyOptions,
7276
{ it.format("AWSClientConfigDefaultsProvider.retryStrategyOptions(awsRetryMode, maxAttempts)") },
73-
true
77+
true,
7478
)
7579
}
7680
"clientLogMode" -> {
@@ -112,13 +116,12 @@ class AWSHttpProtocolServiceClient(
112116
AWSClientRuntimeTypes.Core.AWSClientConfigDefaultsProvider,
113117
)
114118
},
115-
true
119+
true,
116120
)
117121
}
118122
else -> property
119123
}
120124
}
121-
}
122125

123126
override fun renderCustomConfigInitializer(properties: List<ConfigProperty>) {
124127
renderRegionConfigInitializer(properties)
@@ -173,9 +176,10 @@ class AWSHttpProtocolServiceClient(
173176
writer.write("")
174177
}
175178

176-
private val authSchemeResolverDefaultProvider = DefaultProvider(
177-
{ writer.format("Default\$LAuthSchemeResolver()", AuthSchemeResolverGenerator.getSdkId(ctx)) },
178-
false,
179-
false
180-
)
179+
private val authSchemeResolverDefaultProvider =
180+
DefaultProvider(
181+
{ writer.format("Default\$LAuthSchemeResolver()", AuthSchemeResolverGenerator.getSdkId(ctx)) },
182+
false,
183+
false,
184+
)
181185
}

codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/AWSServiceConfig.kt

+6-6
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ import software.amazon.smithy.swift.codegen.utils.toLowerCamelCase
2222
const val ENDPOINT_RESOLVER = "endpointResolver"
2323
const val AUTH_SCHEME_RESOLVER = "authSchemeResolver"
2424

25-
class AWSServiceConfig(writer: SwiftWriter, val ctx: ProtocolGenerator.GenerationContext) :
26-
ServiceConfig(writer, ctx.symbolProvider.toSymbol(ctx.service).name, ctx.service.sdkId) {
27-
25+
class AWSServiceConfig(
26+
writer: SwiftWriter,
27+
val ctx: ProtocolGenerator.GenerationContext,
28+
) : ServiceConfig(writer, ctx.symbolProvider.toSymbol(ctx.service).name, ctx.service.sdkId) {
2829
override fun serviceSpecificConfigProperties(): List<ConfigField> {
2930
var configs = mutableListOf<ConfigField>()
3031

@@ -41,10 +42,9 @@ class AWSServiceConfig(writer: SwiftWriter, val ctx: ProtocolGenerator.Generatio
4142
}
4243
}
4344

44-
fun ShapeType.toSwiftType(): Symbol {
45-
return when (this) {
45+
fun ShapeType.toSwiftType(): Symbol =
46+
when (this) {
4647
ShapeType.STRING -> SwiftTypes.String
4748
ShapeType.BOOLEAN -> SwiftTypes.Bool
4849
else -> throw IllegalArgumentException("Unsupported shape type: $this")
4950
}
50-
}

0 commit comments

Comments
 (0)