Unverified Commit 852c2ec2 authored by John DiSanti's avatar John DiSanti Committed by GitHub
Browse files

Upgrade Ktlint and fix lint configuration (#1572)

* Exclude sigv4 test suite from pre-commit file endings hook
* Upgrade Ktlint
* Make Gradle ktlint target consistent with pre-commit

They were previously running two separate rulesets since pre-commit
pulls in the standard ruleset, and that wasn't pulled into the Gradle
dependencies.

* Fix Gradle Ktlint paths
* Establish editorconfig for Ktlint
* Fix Ktlint lints
* Enable `trailing-commas` rule
* Fix block quote indentation
parent 68feb37e
Loading
Loading
Loading
Loading

.editorconfig

0 → 100644
+9 −0
Original line number Diff line number Diff line
[*.{kt,kts}]
ij_kotlin_allow_trailing_comma = true
ij_kotlin_allow_trailing_comma_on_call_site = true
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
+2 −1
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@ repos:
  hooks:
  - id: check-yaml
  - id: end-of-file-fixer
    exclude: ^aws/rust-runtime/aws-sigv4/aws-sig-v4-test-suite/
  - id: trailing-whitespace
- repo: local
  hooks:
@@ -22,7 +23,7 @@ repos:
  rev: v1.6.1
  hooks:
  - id: pretty-format-kotlin
    args: [--autofix, --ktlint-version, 0.45.2]
    args: [--autofix, --ktlint-version, 0.46.1]
  - id: pretty-format-yaml
    args: [--autofix, --indent, '2']
  - id: pretty-format-rust
+1 −1
Original line number Diff line number Diff line
@@ -25,7 +25,7 @@ dependencies {
}

val allCodegenTests = listOf(
    CodegenTest("com.amazonaws.apigateway#BackplaneControlService", "apigateway")
    CodegenTest("com.amazonaws.apigateway#BackplaneControlService", "apigateway"),
)

project.registerGenerateSmithyBuildTask(rootProject, pluginName, allCodegenTests)
+1 −1
Original line number Diff line number Diff line
@@ -51,7 +51,7 @@ val DECORATORS = listOf(
    Route53Decorator(),

    // Only build docs-rs for linux to reduce load on docs.rs
    DocsRsMetadataDecorator(DocsRsMetadataSettings(targets = listOf("x86_64-unknown-linux-gnu"), allFeatures = true))
    DocsRsMetadataDecorator(DocsRsMetadataSettings(targets = listOf("x86_64-unknown-linux-gnu"), allFeatures = true)),
)

class AwsCodegenDecorator : CombinedCodegenDecorator<ClientCodegenContext>(DECORATORS) {
+10 −10
Original line number Diff line number Diff line
@@ -54,7 +54,7 @@ class AwsEndpointDecorator : RustCodegenDecorator<ClientCodegenContext> {

    override fun configCustomizations(
        codegenContext: ClientCodegenContext,
        baseCustomizations: List<ConfigCustomization>
        baseCustomizations: List<ConfigCustomization>,
    ): List<ConfigCustomization> {
        return baseCustomizations + EndpointConfigCustomization(codegenContext, endpoints(SdkSettings.from(codegenContext.settings)))
    }
@@ -62,14 +62,14 @@ class AwsEndpointDecorator : RustCodegenDecorator<ClientCodegenContext> {
    override fun operationCustomizations(
        codegenContext: ClientCodegenContext,
        operation: OperationShape,
        baseCustomizations: List<OperationCustomization>
        baseCustomizations: List<OperationCustomization>,
    ): List<OperationCustomization> {
        return baseCustomizations + EndpointResolverFeature(codegenContext.runtimeConfig, operation)
    }

    override fun libRsCustomizations(
        codegenContext: ClientCodegenContext,
        baseCustomizations: List<LibRsCustomization>
        baseCustomizations: List<LibRsCustomization>,
    ): List<LibRsCustomization> {
        return baseCustomizations + PubUseEndpoint(codegenContext.runtimeConfig)
    }
@@ -84,7 +84,7 @@ class EndpointConfigCustomization(private val coreCodegenContext: CoreCodegenCon
        when (section) {
            is ServiceConfig.ConfigStruct -> rust(
                "pub (crate) endpoint_resolver: ::std::sync::Arc<dyn #T>,",
                resolveAwsEndpoint
                resolveAwsEndpoint,
            )
            is ServiceConfig.ConfigImpl -> emptySection
            is ServiceConfig.BuilderStruct ->
@@ -120,7 +120,7 @@ class EndpointConfigCustomization(private val coreCodegenContext: CoreCodegenCon
                    }
                    """,
                    "ResolveAwsEndpoint" to resolveAwsEndpoint,
                    "aws_types" to awsTypes(runtimeConfig).asType()
                    "aws_types" to awsTypes(runtimeConfig).asType(),
                )
            ServiceConfig.BuilderBuild -> {
                val resolverGenerator = EndpointResolverGenerator(coreCodegenContext, endpointData)
@@ -148,7 +148,7 @@ class EndpointResolverFeature(private val runtimeConfig: RuntimeConfig, private
                    """
                    #T::set_endpoint_resolver(&mut ${section.request}.properties_mut(), ${section.config}.endpoint_resolver.clone());
                    """,
                    runtimeConfig.awsEndpoint().asType()
                    runtimeConfig.awsEndpoint().asType(),
                )
            }
            else -> emptySection
@@ -162,7 +162,7 @@ class PubUseEndpoint(private val runtimeConfig: RuntimeConfig) : LibRsCustomizat
            is LibRsSection.Body -> writable {
                rust(
                    "pub use #T::endpoint::Endpoint;",
                    CargoDependency.SmithyHttp(runtimeConfig).asType()
                    CargoDependency.SmithyHttp(runtimeConfig).asType(),
                )
            }
            else -> emptySection
@@ -186,7 +186,7 @@ class EndpointResolverGenerator(coreCodegenContext: CoreCodegenContext, private
            "PartitionResolver" to awsEndpoint.member("PartitionResolver"),
            "ResolveAwsEndpoint" to awsEndpoint.member("ResolveAwsEndpoint"),
            "SigningService" to awsTypes.member("SigningService"),
            "SigningRegion" to awsTypes.member("region::SigningRegion")
            "SigningRegion" to awsTypes.member("region::SigningRegion"),
        )

    fun resolver(): RuntimeType {
@@ -243,7 +243,7 @@ class EndpointResolverGenerator(coreCodegenContext: CoreCodegenContext, private
            #{Partition}::builder()
                .id(${partition.id.dq()})
                .region_regex(r##"${partition.regionRegex}"##)""",
            *codegenScope
            *codegenScope,
        )
        withBlock(".default_endpoint(", ")") {
            with(partition.defaults) {
@@ -367,7 +367,7 @@ class EndpointResolverGenerator(coreCodegenContext: CoreCodegenContext, private
                """
                #{CredentialScope}::builder()
                """,
                *codegenScope
                *codegenScope,
            )
            objectNode.getStringMember("service").map {
                rustTemplate(
Loading