Skip to content

Commit

Permalink
Upgrade Kotlin to 1.9.20 and Ktlint to 1.0.1 (#3301)
Browse files Browse the repository at this point in the history
This PR upgrades Kotlin to 1.9.20, and Ktlint to 1.0.1.

I had to abandon the pretty-format-kotlin pre-commit hook since it was
ignoring our `.editorconfig`, which made it impossible to suppress some
of the newer lints that would be difficult and undesirable to fix. Now
all Ktlint runs go through gradle, so there isn't any way for
inconsistencies to creep in.

I recommend reviewing this PR commit by commit as the commit that runs
Ktlint against the entire repo has a very large diff. When reviewing the
Ktlint formatting changes, be sure to hide whitespace changes to reduce
how much needs to be examined.

----

_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._
  • Loading branch information
jdisanti authored Dec 14, 2023
1 parent 9aa0b53 commit e5227f4
Show file tree
Hide file tree
Showing 436 changed files with 16,823 additions and 13,563 deletions.
2 changes: 2 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ ktlint_standard_filename = disabled
ktlint_standard_max-line-length = disabled
ktlint_standard_argument-list-wrapping = disabled
ktlint_standard_parameter-list-wrapping = disabled
ktlint_standard_property-naming = disabled
ktlint_standard_comment-wrapping = disabled
7 changes: 5 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,18 @@ repos:
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
rev: v2.11.0
hooks:
- id: pretty-format-kotlin
args: [--autofix, --ktlint-version, 0.48.2]
- id: pretty-format-yaml
args: [--autofix, --indent, '2']
- id: pretty-format-rust
entry: rustfmt --edition 2021
files: ^.*\.rs$
- repo: local
hooks:
- id: ktlint
name: Ktlint
entry: ./.pre-commit-hooks/ktlint.sh
language: system
files: ^.*\.kt$
- id: kotlin-block-quotes
name: Kotlin Block Quotes
entry: ./.pre-commit-hooks/kotlin-block-quotes.py
Expand Down
7 changes: 4 additions & 3 deletions .pre-commit-hooks/kotlin-block-quotes.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ def starts_or_ends_block_quote(line, inside_block_quotes):

# Returns the indentation of a line
def line_indent(line):
indent = re.search("[^\s]", line)
indent = re.search(r"[^\s]", line)
if indent != None:
return indent.start(0)
else:
return 0

# Changes the indentation of a line
def adjust_indent(line, indent):
old_indent = re.search("[^\s]", line)
old_indent = re.search(r"[^\s]", line)
if old_indent == None:
return line
line = line[old_indent.start(0):]
Expand Down Expand Up @@ -168,7 +168,8 @@ def fix_file(file_name):
print("INFO: Fixed indentation in `" + file_name + "`.")
return True
else:
print("INFO: `" + file_name + "` is fine.")
# This print is useful when debugging this script, but spammy otherwise. Leave it commented.
# print("INFO: `" + file_name + "` is fine.")
return False

class SelfTest(unittest.TestCase):
Expand Down
13 changes: 13 additions & 0 deletions .pre-commit-hooks/ktlint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash
#
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0
#

set -e

cd "$(git rev-parse --show-toplevel)"
# `-q`: run gradle in quiet mode
# `--console plain`: Turn off the fancy terminal printing in gradle
# `2>/dev/null`: Suppress the build success/failure output at the end since pre-commit will report failures
./gradlew -q --console plain ktlintPreCommit -DktlintPreCommitArgs="$*" 2>/dev/null
4 changes: 2 additions & 2 deletions aws/sdk-codegen/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ dependencies {
}

tasks.compileKotlin {
kotlinOptions.jvmTarget = "1.8"
kotlinOptions.jvmTarget = "11"
}

// Reusable license copySpec
Expand Down Expand Up @@ -67,7 +67,7 @@ if (isTestingEnabled.toBoolean()) {
}

tasks.compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
kotlinOptions.jvmTarget = "11"
}

tasks.test {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,23 @@ import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency
import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig
import software.amazon.smithy.rust.codegen.core.smithy.crateLocation

fun RuntimeConfig.awsRuntimeCrate(name: String, features: Set<String> = setOf()): CargoDependency =
CargoDependency(name, awsRoot().crateLocation(name), features = features)
fun RuntimeConfig.awsRuntimeCrate(
name: String,
features: Set<String> = setOf(),
): CargoDependency = CargoDependency(name, awsRoot().crateLocation(name), features = features)

object AwsCargoDependency {
fun awsConfig(runtimeConfig: RuntimeConfig) = runtimeConfig.awsRuntimeCrate("aws-config")

fun awsCredentialTypes(runtimeConfig: RuntimeConfig) = runtimeConfig.awsRuntimeCrate("aws-credential-types")

fun awsHttp(runtimeConfig: RuntimeConfig) = runtimeConfig.awsRuntimeCrate("aws-http")

fun awsRuntime(runtimeConfig: RuntimeConfig) = runtimeConfig.awsRuntimeCrate("aws-runtime")

fun awsRuntimeApi(runtimeConfig: RuntimeConfig) = runtimeConfig.awsRuntimeCrate("aws-runtime-api")

fun awsSigv4(runtimeConfig: RuntimeConfig) = runtimeConfig.awsRuntimeCrate("aws-sigv4")

fun awsTypes(runtimeConfig: RuntimeConfig) = runtimeConfig.awsRuntimeCrate("aws-types")
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,56 +27,55 @@ import software.amazon.smithy.rustsdk.endpoints.AwsEndpointsStdLib
import software.amazon.smithy.rustsdk.endpoints.OperationInputTestDecorator
import software.amazon.smithy.rustsdk.endpoints.RequireEndpointRules

val DECORATORS: List<ClientCodegenDecorator> = listOf(
// General AWS Decorators
val DECORATORS: List<ClientCodegenDecorator> =
listOf(
CredentialsProviderDecorator(),
RegionDecorator(),
RequireEndpointRules(),
UserAgentDecorator(),
SigV4AuthDecorator(),
HttpRequestChecksumDecorator(),
HttpResponseChecksumDecorator(),
RetryClassifierDecorator(),
IntegrationTestDecorator(),
AwsFluentClientDecorator(),
CrateLicenseDecorator(),
SdkConfigDecorator(),
ServiceConfigDecorator(),
AwsPresigningDecorator(),
AwsCrateDocsDecorator(),
AwsEndpointsStdLib(),
*PromotedBuiltInsDecorators,
GenericSmithySdkConfigSettings(),
OperationInputTestDecorator(),
AwsRequestIdDecorator(),
DisabledAuthDecorator(),
RecursionDetectionDecorator(),
InvocationIdDecorator(),
RetryInformationHeaderDecorator(),
RemoveDefaultsDecorator(),
),

// Service specific decorators
ApiGatewayDecorator().onlyApplyTo("com.amazonaws.apigateway#BackplaneControlService"),
Ec2Decorator().onlyApplyTo("com.amazonaws.ec2#AmazonEC2"),
GlacierDecorator().onlyApplyTo("com.amazonaws.glacier#Glacier"),
Route53Decorator().onlyApplyTo("com.amazonaws.route53#AWSDnsV20130401"),
"com.amazonaws.s3#AmazonS3".applyDecorators(
S3Decorator(),
S3ExtendedRequestIdDecorator(),
),
S3ControlDecorator().onlyApplyTo("com.amazonaws.s3control#AWSS3ControlServiceV20180820"),
STSDecorator().onlyApplyTo("com.amazonaws.sts#AWSSecurityTokenServiceV20110615"),
SSODecorator().onlyApplyTo("com.amazonaws.sso#SWBPortalService"),
TimestreamDecorator().onlyApplyTo("com.amazonaws.timestreamwrite#Timestream_20181101"),
TimestreamDecorator().onlyApplyTo("com.amazonaws.timestreamquery#Timestream_20181101"),

// Only build docs-rs for linux to reduce load on docs.rs
listOf(
DocsRsMetadataDecorator(DocsRsMetadataSettings(targets = listOf("x86_64-unknown-linux-gnu"), allFeatures = true)),
),
).flatten()
// General AWS Decorators
listOf(
CredentialsProviderDecorator(),
RegionDecorator(),
RequireEndpointRules(),
UserAgentDecorator(),
SigV4AuthDecorator(),
HttpRequestChecksumDecorator(),
HttpResponseChecksumDecorator(),
RetryClassifierDecorator(),
IntegrationTestDecorator(),
AwsFluentClientDecorator(),
CrateLicenseDecorator(),
SdkConfigDecorator(),
ServiceConfigDecorator(),
AwsPresigningDecorator(),
AwsCrateDocsDecorator(),
AwsEndpointsStdLib(),
*PromotedBuiltInsDecorators,
GenericSmithySdkConfigSettings(),
OperationInputTestDecorator(),
AwsRequestIdDecorator(),
DisabledAuthDecorator(),
RecursionDetectionDecorator(),
InvocationIdDecorator(),
RetryInformationHeaderDecorator(),
RemoveDefaultsDecorator(),
),
// Service specific decorators
ApiGatewayDecorator().onlyApplyTo("com.amazonaws.apigateway#BackplaneControlService"),
Ec2Decorator().onlyApplyTo("com.amazonaws.ec2#AmazonEC2"),
GlacierDecorator().onlyApplyTo("com.amazonaws.glacier#Glacier"),
Route53Decorator().onlyApplyTo("com.amazonaws.route53#AWSDnsV20130401"),
"com.amazonaws.s3#AmazonS3".applyDecorators(
S3Decorator(),
S3ExtendedRequestIdDecorator(),
),
S3ControlDecorator().onlyApplyTo("com.amazonaws.s3control#AWSS3ControlServiceV20180820"),
STSDecorator().onlyApplyTo("com.amazonaws.sts#AWSSecurityTokenServiceV20110615"),
SSODecorator().onlyApplyTo("com.amazonaws.sso#SWBPortalService"),
TimestreamDecorator().onlyApplyTo("com.amazonaws.timestreamwrite#Timestream_20181101"),
TimestreamDecorator().onlyApplyTo("com.amazonaws.timestreamquery#Timestream_20181101"),
// Only build docs-rs for linux to reduce load on docs.rs
listOf(
DocsRsMetadataDecorator(DocsRsMetadataSettings(targets = listOf("x86_64-unknown-linux-gnu"), allFeatures = true)),
),
).flatten()

class AwsCodegenDecorator : CombinedClientCodegenDecorator(DECORATORS) {
override val name: String = "AwsSdkCodegenDecorator"
Expand Down
Loading

0 comments on commit e5227f4

Please sign in to comment.