Skip to content

Commit

Permalink
Upgrade Kotlin and Ktlint (smithy-lang#2392)
Browse files Browse the repository at this point in the history
* Upgrade Kotlin to 1.7.21

* Upgrade Ktlint to 0.48.2

* Run `pre-commit run --all-files` to fix broken Ktlints

* Fix string comparison broken by code formatting
  • Loading branch information
jdisanti committed Feb 22, 2023
1 parent ec1a551 commit 85d2ace
Show file tree
Hide file tree
Showing 74 changed files with 431 additions and 263 deletions.
8 changes: 7 additions & 1 deletion .editorconfig
Expand Up @@ -9,5 +9,11 @@ indent_size = 4
indent_style = space
insert_final_newline = true
max_line_length = 120

# Ktlint-specific config
disabled_rules = filename, max-line-length, argument-list-wrapping, parameter-list-wrapping
ktlint_standard = enabled
ktlint_experimental = disabled
ktlint_standard_filename = disabled
ktlint_standard_max-line-length = disabled
ktlint_standard_argument-list-wrapping = disabled
ktlint_standard_parameter-list-wrapping = disabled
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Expand Up @@ -20,10 +20,10 @@ repos:
files: ^.*$
pass_filenames: false
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
rev: v2.5.0
rev: v2.6.0
hooks:
- id: pretty-format-kotlin
args: [--autofix, --ktlint-version, 0.46.1]
args: [--autofix, --ktlint-version, 0.48.2]
- id: pretty-format-yaml
args: [--autofix, --indent, '2']
- id: pretty-format-rust
Expand Down
2 changes: 1 addition & 1 deletion aws/SDK_CHANGELOG.next.json
Expand Up @@ -498,4 +498,4 @@
}
],
"aws-sdk-model": []
}
}
Expand Up @@ -130,7 +130,9 @@ class RegionDecorator : ClientCodegenDecorator {
object : EndpointCustomization {
override fun loadBuiltInFromServiceConfig(parameter: Parameter, configRef: String): Writable? {
return when (parameter.builtIn) {
Builtins.REGION.builtIn -> writable { rust("$configRef.region.as_ref().map(|r|r.as_ref().to_owned())") }
Builtins.REGION.builtIn -> writable {
rust("$configRef.region.as_ref().map(|r|r.as_ref().to_owned())")
}
else -> null
}
}
Expand Down
Expand Up @@ -37,7 +37,9 @@ class AccountIdAutofill : OperationCustomization() {
val input = operation.inputShape(model)
return if (input.memberNames.contains("accountId")) {
AccountIdAutofill()
} else null
} else {
null
}
}
}
}
Expand Up @@ -49,7 +49,9 @@ class Route53Decorator : ClientCodegenDecorator {
operation.inputShape(codegenContext.model).members().find { it.hasTrait<TrimResourceId>() }
return if (hostedZoneMember != null) {
baseCustomizations + TrimResourceIdCustomization(codegenContext.symbolProvider.toMemberName(hostedZoneMember))
} else baseCustomizations
} else {
baseCustomizations
}
}

private fun isResourceId(shape: Shape): Boolean {
Expand Down
Expand Up @@ -250,8 +250,7 @@ class AwsEndpointDecorator : ClientCodegenDecorator {
}

ServiceConfig.ConfigStruct -> rust("endpoint_url: Option<String>,")
ServiceConfig.ConfigStructAdditionalDocs -> emptySection
ServiceConfig.Extras -> emptySection
else -> {}
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion aws/sdk/build.gradle.kts
Expand Up @@ -52,7 +52,9 @@ dependencies {

// Class and functions for service and protocol membership for SDK generation

val awsServices: AwsServices by lazy { discoverServices(properties.get("aws.sdk.models.path"), loadServiceMembership()) }
val awsServices: AwsServices by lazy {
discoverServices(properties.get("aws.sdk.models.path"), loadServiceMembership())
}
val eventStreamAllowList: Set<String> by lazy { eventStreamAllowList() }
val crateVersioner by lazy { aws.sdk.CrateVersioner.defaultFor(rootProject, properties) }

Expand Down
8 changes: 3 additions & 5 deletions build.gradle.kts
Expand Up @@ -14,9 +14,7 @@ buildscript {
}
}

plugins {
kotlin("jvm") version "1.3.72" apply false
}
plugins { }

allprojects {
repositories {
Expand Down Expand Up @@ -61,7 +59,7 @@ tasks.register<JavaExec>("ktlint") {
group = "Verification"
classpath = configurations.getByName("ktlint")
mainClass.set("com.pinterest.ktlint.Main")
args = listOf("--verbose", "--relative", "--") + lintPaths
args = listOf("--log-level=info", "--relative", "--") + lintPaths
// https://github.com/pinterest/ktlint/issues/1195#issuecomment-1009027802
jvmArgs("--add-opens", "java.base/java.lang=ALL-UNNAMED")
}
Expand All @@ -71,7 +69,7 @@ tasks.register<JavaExec>("ktlintFormat") {
group = "formatting"
classpath = configurations.getByName("ktlint")
mainClass.set("com.pinterest.ktlint.Main")
args = listOf("--verbose", "--relative", "--format", "--") + lintPaths
args = listOf("--log-level=info", "--relative", "--format", "--") + lintPaths
// https://github.com/pinterest/ktlint/issues/1195#issuecomment-1009027802
jvmArgs("--add-opens", "java.base/java.lang=ALL-UNNAMED")
}
10 changes: 7 additions & 3 deletions buildSrc/src/main/kotlin/CodegenTestCommon.kt
Expand Up @@ -62,7 +62,7 @@ enum class Cargo(val toString: String) {
CHECK("cargoCheck"),
TEST("cargoTest"),
DOCS("cargoDoc"),
CLIPPY("cargoClippy");
CLIPPY("cargoClippy"),
}

private fun generateCargoWorkspace(pluginName: String, tests: List<CodegenTest>) =
Expand All @@ -86,7 +86,9 @@ private fun codegenTests(properties: PropertyRetriever, allTests: List<CodegenTe
allTests
}
require(ret.isNotEmpty()) {
"None of the provided module overrides (`$modulesOverride`) are valid test services (`${allTests.map { it.module }}`)"
"None of the provided module overrides (`$modulesOverride`) are valid test services (`${allTests.map {
it.module
}}`)"
}
return ret
}
Expand Down Expand Up @@ -115,7 +117,9 @@ fun cargoCommands(properties: PropertyRetriever): List<Cargo> {
AllCargoCommands
}
require(ret.isNotEmpty()) {
"None of the provided cargo commands (`$cargoCommandsOverride`) are valid cargo commands (`${AllCargoCommands.map { it.toString }}`)"
"None of the provided cargo commands (`$cargoCommandsOverride`) are valid cargo commands (`${AllCargoCommands.map {
it.toString
}}`)"
}
return ret
}
Expand Down
4 changes: 3 additions & 1 deletion buildSrc/src/main/kotlin/aws/sdk/DocsLandingPage.kt
Expand Up @@ -44,7 +44,9 @@ fun Project.docsLandingPage(awsServices: AwsServices, outputPath: File) {
/**
* Generate a link to the examples for a given service
*/
private fun examplesLink(service: AwsService, project: Project) = service.examplesUri(project)?.let { "([examples]($it))" }
private fun examplesLink(service: AwsService, project: Project) = service.examplesUri(project)?.let {
"([examples]($it))"
}

/**
* Generate a link to the docs
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/aws/sdk/ModelMetadata.kt
Expand Up @@ -11,7 +11,7 @@ import java.io.File
enum class ChangeType {
UNCHANGED,
FEATURE,
DOCUMENTATION
DOCUMENTATION,
}

/** Model metadata toml file */
Expand Down
10 changes: 6 additions & 4 deletions buildSrc/src/main/kotlin/aws/sdk/ServiceLoader.kt
Expand Up @@ -135,9 +135,9 @@ fun Project.discoverServices(awsModelsPath: String?, serviceMembership: Membersh
serviceMembership.exclusions.forEach { disabledService ->
check(baseModules.contains(disabledService)) {
"Service $disabledService was explicitly disabled but no service was generated with that name. Generated:\n ${
baseModules.joinToString(
"\n ",
)
baseModules.joinToString(
"\n ",
)
}"
}
}
Expand Down Expand Up @@ -206,7 +206,9 @@ fun parseMembership(rawList: String): Membership {
}

val conflictingMembers = inclusions.intersect(exclusions)
require(conflictingMembers.isEmpty()) { "$conflictingMembers specified both for inclusion and exclusion in $rawList" }
require(conflictingMembers.isEmpty()) {
"$conflictingMembers specified both for inclusion and exclusion in $rawList"
}

return Membership(inclusions, exclusions)
}
Expand Up @@ -100,7 +100,7 @@ private class ApiKeyOperationCustomization(private val runtimeConfig: RuntimeCon
"""
${section.request}.properties_mut().insert(api_key_config.clone());
let api_key = api_key_config.api_key();
""",
""",
)
val definitionName = authDefinition.getName()
if (authDefinition.getIn() == HttpApiKeyAuthTrait.Location.QUERY) {
Expand Down
Expand Up @@ -16,7 +16,9 @@ class ClientDocsGenerator : LibRsCustomization() {
return when (section) {
is LibRsSection.ModuleDocumentation -> if (section.subsection == LibRsSection.CrateOrganization) {
crateLayout()
} else emptySection
} else {
emptySection
}
else -> emptySection
}
}
Expand Down
Expand Up @@ -90,7 +90,9 @@ internal class EndpointConfigCustomization(
/// let config = $moduleUseName::Config::builder().endpoint_resolver(prefix_resolver);
/// ```
"""
} else ""
} else {
""
}
rustTemplate(
"""
/// Sets the endpoint resolver to use when making requests.
Expand Down
Expand Up @@ -74,10 +74,9 @@ class AwsPartitionResolver(runtimeConfig: RuntimeConfig, private val partitionsD
)

override fun structFieldInit() = writable {
val json = Node.printJson(partitionsDotJson).dq()
rustTemplate(
"""partition_resolver: #{PartitionResolver}::new_from_json(b${
Node.printJson(partitionsDotJson).dq()
}).expect("valid JSON")""",
"""partition_resolver: #{PartitionResolver}::new_from_json(b$json).expect("valid JSON")""",
*codegenScope,
)
}
Expand Down
Expand Up @@ -136,15 +136,15 @@ class FluentClientGenerator(
"smithy_inst" to generics.smithyInst,
"client" to RuntimeType.smithyClient(runtimeConfig),
"client_docs" to writable
{
customizations.forEach {
it.section(
FluentClientSection.FluentClientDocs(
serviceShape,
),
)(this)
}
},
{
customizations.forEach {
it.section(
FluentClientSection.FluentClientDocs(
serviceShape,
),
)(this)
}
},
)
writer.rustBlockTemplate(
"impl${generics.inst} Client${generics.inst} #{bounds:W}",
Expand All @@ -156,7 +156,9 @@ class FluentClientGenerator(
val fullPath = operation.fullyQualifiedFluentBuilder(symbolProvider)
val maybePaginated = if (operation.isPaginated(model)) {
"\n/// This operation supports pagination; See [`into_paginator()`]($fullPath::into_paginator)."
} else ""
} else {
""
}

val output = operation.outputShape(model)
val operationOk = symbolProvider.toSymbol(output)
Expand Down Expand Up @@ -201,10 +203,10 @@ class FluentClientGenerator(
writer.rust(
"""
pub fn ${
clientOperationFnName(
operation,
symbolProvider,
)
clientOperationFnName(
operation,
symbolProvider,
)
}(&self) -> fluent_builders::$name${generics.inst} {
fluent_builders::$name::new(self.handle.clone())
}
Expand Down
Expand Up @@ -63,7 +63,9 @@ class IdempotencyTokenProviderCustomization : NamedCustomization<ServiceConfig>(
rust("make_token: self.make_token.unwrap_or_else(#T::default_provider),", RuntimeType.IdempotencyToken)
}

is ServiceConfig.DefaultForTests -> writable { rust("""${section.configBuilderRef}.set_make_token(Some("00000000-0000-4000-8000-000000000000".into()));""") }
is ServiceConfig.DefaultForTests -> writable {
rust("""${section.configBuilderRef}.set_make_token(Some("00000000-0000-4000-8000-000000000000".into()));""")
}

else -> writable { }
}
Expand Down
Expand Up @@ -52,6 +52,7 @@ class ErrorGenerator(
is StructureSection.AdditionalDebugFields -> {
rust("""${section.formatterName}.field("meta", &self.meta);""")
}
else -> {}
}
}
},
Expand Down Expand Up @@ -90,6 +91,8 @@ class ErrorGenerator(
is BuilderSection.AdditionalFieldsInBuild -> {
rust("meta: self.meta.unwrap_or_default(),")
}

else -> {}
}
}
},
Expand Down
Expand Up @@ -53,7 +53,9 @@ class ServiceErrorGenerator(
private val symbolProvider = codegenContext.symbolProvider
private val model = codegenContext.model

private val allErrors = operations.flatMap { it.allErrors(model) }.map { it.id }.distinctBy { it.getName(codegenContext.serviceShape) }
private val allErrors = operations.flatMap {
it.allErrors(model)
}.map { it.id }.distinctBy { it.getName(codegenContext.serviceShape) }
.map { codegenContext.model.expectShape(it, StructureShape::class.java) }
.sortedBy { it.id.getName(codegenContext.serviceShape) }

Expand Down
Expand Up @@ -246,10 +246,10 @@ class ProtocolTestGenerator(
expectedShape: StructureShape,
) {
if (!protocolSupport.responseDeserialization || (
!protocolSupport.errorDeserialization && expectedShape.hasTrait(
!protocolSupport.errorDeserialization && expectedShape.hasTrait(
ErrorTrait::class.java,
)
)
)
) {
rust("/* test case disabled for this protocol (not yet supported) */")
return
Expand Down Expand Up @@ -356,7 +356,7 @@ class ProtocolTestGenerator(
assertOk(rustWriter) {
rustWriter.write(
"#T(&body, ${
rustWriter.escape(body).dq()
rustWriter.escape(body).dq()
}, #T::from(${(mediaType ?: "unknown").dq()}))",
RuntimeType.protocolTest(codegenContext.runtimeConfig, "validate_body"),
RuntimeType.protocolTest(codegenContext.runtimeConfig, "MediaType"),
Expand Down
Expand Up @@ -350,7 +350,9 @@ class HttpBoundProtocolTraitImplGenerator(

val err = if (BuilderGenerator.hasFallibleBuilder(outputShape, symbolProvider)) {
".map_err(${format(errorSymbol)}::unhandled)?"
} else ""
} else {
""
}

writeCustomizations(customizations, OperationSection.MutateOutput(customizations, operationShape))

Expand Down
Expand Up @@ -205,7 +205,9 @@ class FakeSigningDecorator : ClientCodegenDecorator {
codegenContext: ClientCodegenContext,
baseCustomizations: List<ConfigCustomization>,
): List<ConfigCustomization> {
return baseCustomizations.filterNot { it is EventStreamSigningConfig } + FakeSigningConfig(codegenContext.runtimeConfig)
return baseCustomizations.filterNot {
it is EventStreamSigningConfig
} + FakeSigningConfig(codegenContext.runtimeConfig)
}
}

Expand Down
Expand Up @@ -94,7 +94,9 @@ internal class ServiceConfigGeneratorTest {
}
ServiceConfig.BuilderStruct -> writable { rust("config_field: Option<u64>") }
ServiceConfig.BuilderImpl -> emptySection
ServiceConfig.BuilderBuild -> writable { rust("config_field: self.config_field.unwrap_or_default(),") }
ServiceConfig.BuilderBuild -> writable {
rust("config_field: self.config_field.unwrap_or_default(),")
}
else -> emptySection
}
}
Expand Down
Expand Up @@ -222,7 +222,9 @@ fun RustType.asArgument(name: String) = Argument(
fun RustType.render(fullyQualified: Boolean = true): String {
val namespace = if (fullyQualified) {
this.namespace?.let { "$it::" } ?: ""
} else ""
} else {
""
}
val base = when (this) {
is RustType.Unit -> this.name
is RustType.Bool -> this.name
Expand Down Expand Up @@ -426,7 +428,7 @@ enum class AttributeKind {
/**
* Outer attributes, written without the bang after the hash, apply to the thing that follows the attribute.
*/
Outer
Outer,
}

/**
Expand Down

0 comments on commit 85d2ace

Please sign in to comment.