Skip to content

Commit e3deec9

Browse files
sichanyooSichan Yoo
andauthored
chore: ktlint & swiftlint version bumps (#904)
* Update swiftlint and ktlint versions; address new lint warnings; disable questionable property naming rule in ktlint. * Instead of diabling a rule, add suppress to relevant exceptions as needed. * Make warnings fail swiftlint as well. * Remove extra dash --------- Co-authored-by: Sichan Yoo <[email protected]>
1 parent 165edc8 commit e3deec9

File tree

238 files changed

+5589
-3617
lines changed

Some content is hidden

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

238 files changed

+5589
-3617
lines changed

.github/workflows/lint.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ jobs:
2020
if: github.repository == 'smithy-lang/smithy-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
28-
run: swiftlint --reporter github-actions-logging
28+
run: swiftlint --strict --reporter github-actions-logging

Sources/SmithyRetries/DefaultRetryStrategy/ClientSideRateLimiter.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import struct Foundation.TimeInterval
99
import struct Foundation.Date
1010
import func Foundation.pow
1111

12-
actor ClientSideRateLimiter: Sendable {
12+
actor ClientSideRateLimiter {
1313

1414
// these are constants defined in Retry Behavior 2.0
1515
let minFillRate: Double = 0.5

build.gradle.kts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,11 @@ val ktlint by configurations.creating
1919
val ktlintVersion: String by project
2020

2121
dependencies {
22-
ktlint("com.pinterest:ktlint:$ktlintVersion")
22+
ktlint("com.pinterest.ktlint:ktlint-cli:$ktlintVersion")
2323
}
2424

2525
val lintPaths = listOf(
26-
"smithy-swift-codegen/src/**/*.kt",
27-
"smithy-swift-codegen-test-utils/src/**/*.kt"
26+
"smithy-swift-codegen/**/*.kt",
2827
)
2928

3029
tasks.register<JavaExec>("ktlint") {

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ kotlinxBenchmarkVersion=0.3.1
2121

2222
# FIXME - junit5 not working
2323
junitVersion=5.6.2
24-
ktlintVersion=0.40.0
24+
ktlintVersion=1.5.0
2525
kotestVersion=4.6.0
2626
jacocoVersion=0.8.7

settings.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,3 @@ rootProject.name = "smithy-swift"
2828

2929
include("smithy-swift-codegen")
3030
include("smithy-swift-codegen-test")
31-
include("smithy-swift-codegen-test-utils")

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

Lines changed: 69 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ class AuthSchemeResolverGenerator {
4343
private fun renderServiceSpecificAuthResolverParamsStruct(
4444
serviceIndex: ServiceIndex,
4545
ctx: ProtocolGenerator.GenerationContext,
46-
writer: SwiftWriter
46+
writer: SwiftWriter,
4747
) {
4848
writer.apply {
4949
openBlock(
5050
"public struct ${getSdkId(ctx)}${SmithyHTTPAuthAPITypes.AuthSchemeResolverParams.name}: \$N {",
5151
"}",
52-
SmithyHTTPAuthAPITypes.AuthSchemeResolverParams
52+
SmithyHTTPAuthAPITypes.AuthSchemeResolverParams,
5353
) {
5454
write("public let operation: \$N", SwiftTypes.String)
5555

@@ -71,7 +71,10 @@ class AuthSchemeResolverGenerator {
7171
}
7272
}
7373

74-
private fun renderEndpointParamFields(ctx: ProtocolGenerator.GenerationContext, writer: SwiftWriter) {
74+
private fun renderEndpointParamFields(
75+
ctx: ProtocolGenerator.GenerationContext,
76+
writer: SwiftWriter,
77+
) {
7578
writer.apply {
7679
val ruleSetNode = ctx.service.getTrait<EndpointRuleSetTrait>()?.ruleSet
7780
val ruleSet = if (ruleSetNode != null) EndpointRuleSet.fromNode(ruleSetNode) else null
@@ -87,12 +90,15 @@ class AuthSchemeResolverGenerator {
8790
}
8891
}
8992

90-
private fun renderServiceSpecificAuthResolverProtocol(ctx: ProtocolGenerator.GenerationContext, writer: SwiftWriter) {
93+
private fun renderServiceSpecificAuthResolverProtocol(
94+
ctx: ProtocolGenerator.GenerationContext,
95+
writer: SwiftWriter,
96+
) {
9197
writer.apply {
9298
openBlock(
9399
"public protocol ${getServiceSpecificAuthSchemeResolverName(ctx)}: \$N {",
94100
"}",
95-
SmithyHTTPAuthAPITypes.AuthSchemeResolver
101+
SmithyHTTPAuthAPITypes.AuthSchemeResolver,
96102
) {
97103
// This is just a parent protocol that all auth scheme resolvers of a given service must conform to.
98104
write("// Intentionally empty.")
@@ -105,16 +111,19 @@ class AuthSchemeResolverGenerator {
105111
private fun renderServiceSpecificDefaultResolver(
106112
serviceIndex: ServiceIndex,
107113
ctx: ProtocolGenerator.GenerationContext,
108-
writer: SwiftWriter
114+
writer: SwiftWriter,
109115
) {
110116
val sdkId = getSdkId(ctx)
111117

112118
// Model-based auth scheme resolver is internal implementation detail for services that use rules based resolvers,
113119
// and is used as fallback only if endpoint resolver returns no valid auth scheme(s).
114120
val usesRulesBasedResolver = usesRulesBasedAuthResolver(ctx)
115121
val defaultResolverName =
116-
if (usesRulesBasedResolver) "InternalModeled$sdkId$AUTH_SCHEME_RESOLVER"
117-
else "Default$sdkId$AUTH_SCHEME_RESOLVER"
122+
if (usesRulesBasedResolver) {
123+
"InternalModeled$sdkId$AUTH_SCHEME_RESOLVER"
124+
} else {
125+
"Default$sdkId$AUTH_SCHEME_RESOLVER"
126+
}
118127

119128
// Model-based auth scheme resolver should be private internal impl detail if service uses rules-based resolver.
120129
val accessModifier = if (usesRulesBasedResolver) "private" else "public"
@@ -126,15 +135,15 @@ class AuthSchemeResolverGenerator {
126135
"}",
127136
accessModifier,
128137
defaultResolverName,
129-
serviceSpecificAuthResolverProtocol
138+
serviceSpecificAuthResolverProtocol,
130139
) {
131140
write("")
132141
renderResolveAuthSchemeMethod(serviceIndex, ctx, writer)
133142
write("")
134143
renderConstructParametersMethod(
135144
serviceIndex.getEffectiveAuthSchemes(ctx.service).contains(SigV4Trait.ID),
136145
ctx,
137-
writer
146+
writer,
138147
)
139148
}
140149
}
@@ -143,7 +152,7 @@ class AuthSchemeResolverGenerator {
143152
private fun renderResolveAuthSchemeMethod(
144153
serviceIndex: ServiceIndex,
145154
ctx: ProtocolGenerator.GenerationContext,
146-
writer: SwiftWriter
155+
writer: SwiftWriter,
147156
) {
148157
val sdkId = getSdkId(ctx)
149158
val serviceParamsName = sdkId + SmithyHTTPAuthAPITypes.AuthSchemeResolverParams.name
@@ -159,7 +168,10 @@ class AuthSchemeResolverGenerator {
159168
write("var validAuthOptions = [\$N]()", SmithyHTTPAuthAPITypes.AuthOption)
160169
// Cast params to service specific params object
161170
openBlock("guard let serviceParams = params as? \$L else {", "}", serviceParamsName) {
162-
write("throw \$N.authError(\"Service specific auth scheme parameters type must be passed to auth scheme resolver.\")", SmithyTypes.ClientError)
171+
write(
172+
"throw \$N.authError(\"Service specific auth scheme parameters type must be passed to auth scheme resolver.\")",
173+
SmithyTypes.ClientError,
174+
)
163175
}
164176
// Render switch block
165177
renderSwitchBlock(serviceIndex, ctx, writer)
@@ -172,7 +184,7 @@ class AuthSchemeResolverGenerator {
172184
private fun renderSwitchBlock(
173185
serviceIndex: ServiceIndex,
174186
ctx: ProtocolGenerator.GenerationContext,
175-
writer: SwiftWriter
187+
writer: SwiftWriter,
176188
) {
177189
writer.apply {
178190
// Switch block for iterating over operation name cases
@@ -187,11 +199,12 @@ class AuthSchemeResolverGenerator {
187199
opShape.hasTrait(UnsignedPayloadTrait::class.java)
188200
) {
189201
val opName = it.name.toLowerCamelCase()
190-
val validSchemesForOp = serviceIndex.getEffectiveAuthSchemes(
191-
ctx.service,
192-
it,
193-
ServiceIndex.AuthSchemeMode.NO_AUTH_AWARE
194-
)
202+
val validSchemesForOp =
203+
serviceIndex.getEffectiveAuthSchemes(
204+
ctx.service,
205+
it,
206+
ServiceIndex.AuthSchemeMode.NO_AUTH_AWARE,
207+
)
195208
write("case \"$opName\":")
196209
renderSwitchCase(validSchemesForOp, writer)
197210
}
@@ -205,7 +218,10 @@ class AuthSchemeResolverGenerator {
205218
}
206219
}
207220

208-
private fun renderSwitchCase(schemes: Map<ShapeId, Trait>, writer: SwiftWriter) {
221+
private fun renderSwitchCase(
222+
schemes: Map<ShapeId, Trait>,
223+
writer: SwiftWriter,
224+
) {
209225
writer.apply {
210226
indent()
211227
schemes.forEach {
@@ -223,10 +239,16 @@ class AuthSchemeResolverGenerator {
223239
}
224240
}
225241

226-
private fun renderSigV4AuthOption(scheme: Map.Entry<ShapeId, Trait>, writer: SwiftWriter) {
242+
private fun renderSigV4AuthOption(
243+
scheme: Map.Entry<ShapeId, Trait>,
244+
writer: SwiftWriter,
245+
) {
227246
writer.apply {
228247
write("var sigV4Option = \$N(schemeID: \$S)", SmithyHTTPAuthAPITypes.AuthOption, scheme.key)
229-
write("sigV4Option.signingProperties.set(key: \$N.signingName, value: \"${(scheme.value as SigV4Trait).name}\")", SmithyHTTPAuthAPITypes.SigningPropertyKeys)
248+
write(
249+
"sigV4Option.signingProperties.set(key: \$N.signingName, value: \"${(scheme.value as SigV4Trait).name}\")",
250+
SmithyHTTPAuthAPITypes.SigningPropertyKeys,
251+
)
230252
openBlock("guard let region = serviceParams.region else {", "}") {
231253
write("throw \$N.authError(\"Missing region in auth scheme parameters for SigV4 auth scheme.\")", SmithyTypes.ClientError)
232254
}
@@ -238,20 +260,23 @@ class AuthSchemeResolverGenerator {
238260
private fun renderConstructParametersMethod(
239261
hasSigV4: Boolean,
240262
ctx: ProtocolGenerator.GenerationContext,
241-
writer: SwiftWriter
263+
writer: SwiftWriter,
242264
) {
243265
writer.apply {
244266
openBlock(
245267
"public func constructParameters(context: \$N) throws -> \$N {",
246268
"}",
247269
SmithyTypes.Context,
248-
SmithyHTTPAuthAPITypes.AuthSchemeResolverParams
270+
SmithyHTTPAuthAPITypes.AuthSchemeResolverParams,
249271
) {
250272
if (usesRulesBasedAuthResolver(ctx)) {
251273
write("return try Default${getSdkId(ctx) + AUTH_SCHEME_RESOLVER}().constructParameters(context: context)")
252274
} else {
253275
openBlock("guard let opName = context.getOperation() else {", "}") {
254-
write("throw \$N.dataNotFound(\"Operation name not configured in middleware context for auth scheme resolver params construction.\")", SmithyTypes.ClientError)
276+
write(
277+
"throw \$N.dataNotFound(\"Operation name not configured in middleware context for auth scheme resolver params construction.\")",
278+
SmithyTypes.ClientError,
279+
)
255280
}
256281
val paramType = getSdkId(ctx) + SmithyHTTPAuthAPITypes.AuthSchemeResolverParams.name
257282
if (hasSigV4) {
@@ -269,31 +294,35 @@ class AuthSchemeResolverGenerator {
269294
private val AUTH_SCHEME_RESOLVER = "AuthSchemeResolver"
270295

271296
// Utility function for checking if a service relies on endpoint resolver for auth scheme resolution
272-
fun usesRulesBasedAuthResolver(ctx: ProtocolGenerator.GenerationContext): Boolean {
273-
return listOf("s3", "eventbridge", "cloudfront keyvaluestore", "sesv2").contains(ctx.settings.sdkId.lowercase(Locale.US))
274-
}
297+
fun usesRulesBasedAuthResolver(ctx: ProtocolGenerator.GenerationContext): Boolean =
298+
listOf("s3", "eventbridge", "cloudfront keyvaluestore", "sesv2").contains(ctx.settings.sdkId.lowercase(Locale.US))
275299

276300
// Utility function for returning sdkId from generation context
277-
fun getSdkId(ctx: ProtocolGenerator.GenerationContext): String {
278-
return if (ctx.service.hasTrait(ServiceTrait::class.java))
279-
ctx.service.getTrait(ServiceTrait::class.java).get().sdkId.clientName()
280-
else ctx.settings.sdkId.clientName()
281-
}
301+
fun getSdkId(ctx: ProtocolGenerator.GenerationContext): String =
302+
if (ctx.service.hasTrait(ServiceTrait::class.java)) {
303+
ctx.service
304+
.getTrait(ServiceTrait::class.java)
305+
.get()
306+
.sdkId
307+
.clientName()
308+
} else {
309+
ctx.settings.sdkId.clientName()
310+
}
282311

283-
fun getServiceSpecificAuthSchemeResolverName(ctx: ProtocolGenerator.GenerationContext): Symbol {
284-
return buildSymbol {
312+
fun getServiceSpecificAuthSchemeResolverName(ctx: ProtocolGenerator.GenerationContext): Symbol =
313+
buildSymbol {
285314
name = "${getSdkId(ctx)}$AUTH_SCHEME_RESOLVER"
286315
}
287-
}
288316
}
289317
}
290318

291319
fun Parameter.toSymbol(): Symbol {
292-
val swiftType = when (type) {
293-
ParameterType.STRING -> SwiftTypes.String
294-
ParameterType.BOOLEAN -> SwiftTypes.Bool
295-
ParameterType.STRING_ARRAY -> SwiftTypes.StringArray
296-
}
320+
val swiftType =
321+
when (type) {
322+
ParameterType.STRING -> SwiftTypes.String
323+
ParameterType.BOOLEAN -> SwiftTypes.Bool
324+
ParameterType.STRING_ARRAY -> SwiftTypes.StringArray
325+
}
297326
var builder = Symbol.builder().name(swiftType.fullName)
298327
if (!isRequired) {
299328
builder = builder.boxed()

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import software.amazon.smithy.swift.codegen.integration.ProtocolGenerator
1212
import software.amazon.smithy.swift.codegen.integration.SwiftIntegration
1313

1414
class DefaultClientConfigurationIntegration : SwiftIntegration {
15-
override fun clientConfigurations(ctx: ProtocolGenerator.GenerationContext): List<ClientConfiguration> {
16-
return listOf(DefaultClientConfiguration(), DefaultHttpClientConfiguration())
17-
}
15+
override fun clientConfigurations(ctx: ProtocolGenerator.GenerationContext): List<ClientConfiguration> =
16+
listOf(DefaultClientConfiguration(), DefaultHttpClientConfiguration())
1817
}

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,14 @@ import software.amazon.smithy.swift.codegen.integration.SwiftIntegration
2828
import software.amazon.smithy.swift.codegen.model.hasTrait
2929
import java.util.logging.Logger
3030

31-
class DirectedSwiftCodegen(val context: PluginContext) :
32-
DirectedCodegen<GenerationContext, SwiftSettings, SwiftIntegration> {
31+
class DirectedSwiftCodegen(
32+
val context: PluginContext,
33+
) : DirectedCodegen<GenerationContext, SwiftSettings, SwiftIntegration> {
34+
@Suppress("ktlint:standard:property-naming")
3335
private val LOGGER = Logger.getLogger(javaClass.name)
3436

35-
override fun createSymbolProvider(directive: CreateSymbolProviderDirective<SwiftSettings>): SymbolProvider {
36-
return SwiftSymbolProvider(directive.model(), directive.settings())
37-
}
37+
override fun createSymbolProvider(directive: CreateSymbolProviderDirective<SwiftSettings>): SymbolProvider =
38+
SwiftSymbolProvider(directive.model(), directive.settings())
3839

3940
override fun createContext(directive: CreateContextDirective<SwiftSettings, SwiftIntegration>): GenerationContext {
4041
val model = directive.model()
@@ -56,7 +57,7 @@ class DirectedSwiftCodegen(val context: PluginContext) :
5657
directive.settings(),
5758
directive.fileManifest(),
5859
protocolGenerator,
59-
directive.integrations()
60+
directive.integrations(),
6061
)
6162
}
6263

@@ -172,14 +173,16 @@ class DirectedSwiftCodegen(val context: PluginContext) :
172173
val settings = directive.settings()
173174
val symbolProvider = directive.symbolProvider()
174175
val writers = context.writerDelegator()
175-
writers.useShapeWriter(shape) { writer: SwiftWriter -> IntEnumGenerator(model, symbolProvider, writer, shape.asIntEnumShape().get(), settings).render() }
176+
writers.useShapeWriter(
177+
shape,
178+
) { writer: SwiftWriter -> IntEnumGenerator(model, symbolProvider, writer, shape.asIntEnumShape().get(), settings).render() }
176179
}
177180

178181
private fun resolveProtocolGenerator(
179182
integrations: List<SwiftIntegration>,
180183
model: Model,
181184
service: ServiceShape,
182-
settings: SwiftSettings
185+
settings: SwiftSettings,
183186
): ProtocolGenerator? {
184187
val generators = integrations.flatMap { it.protocolGenerators }.associateBy { it.protocol }
185188
val serviceIndex = ServiceIndex.of(model)

0 commit comments

Comments
 (0)