Skip to content

Conversation

@0marperez
Copy link
Contributor

@0marperez 0marperez commented Sep 10, 2025

Issue #, if available:
N/A

Description of changes:

#42 broke our custom ktlint rules.
This PR fixes our custom ktlint rules

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

attribute(Bundling.BUNDLING_ATTRIBUTE, objects.named(Bundling.SHADOWED))
}
}
ktlint("aws.sdk.kotlin.gradle:ktlint-rules:$repoToolsVersion")
Copy link
Contributor Author

@0marperez 0marperez Sep 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@0marperez 0marperez marked this pull request as ready for review September 10, 2025 21:41
@0marperez 0marperez requested a review from a team as a code owner September 10, 2025 21:41
import org.jetbrains.kotlin.com.intellij.lang.ASTNode

class MultilineIfElseBlockRule : Rule(RuleId("multiline-if-else-block"), About()) {
class MultilineIfElseBlockRule : Rule(RuleId("custom-ktlint-rules:multiline-if-else-block"), About()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit/naming: aws-ktlint-rules

Copy link
Contributor Author

@0marperez 0marperez Sep 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about repo-tools?
The rules would be logged by ktlint like this:

Summary error count (descending) by rule:
  repo-tools:copyright-header: 1
  repo-tools:expression-body: 1
  standard:indent: 1

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the full aws-kotlin-repo-tools-rules would be better

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something with a -rules suffix for sure

* @param lintPaths list of paths relative to the project root to lint (or not lint).
*/
fun Project.configureLinting(lintPaths: List<String>) {
fun Project.configureLinting(lintPaths: List<String>, repoToolsVersion: String) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a fan of having to keep track of aws-kotlin-repo-tools version in a second place. We have access to the Project, can't we dive in and find the aws-kotlin-repo-tools version?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the caller side, if you can get the aws-kotlin-repo-tools version from libs.versions.toml and pass it to configureLinting, that would work too

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a fan of having to keep track of aws-kotlin-repo-tools version in a second place. We have access to the Project, can't we dive in and find the aws-kotlin-repo-tools version?

We don't keep track of the current version in repo tools like we do in the other repos so we can't do that unless we make bigger changes

From the caller side, if you can get the aws-kotlin-repo-tools version from libs.versions.toml and pass it to configureLinting, that would work too

That's what I'm planning to do, I made sure we can do so before I posted the PR

Copy link
Member

@lauzadis lauzadis Sep 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Project in this context is aws-sdk-kotlin, smithy-kotlin, aws-crt-kotlin which do declare a version of aws-kotlin-repo-tools in their libs.versions.toml file and should be accessible, but your other solution is fine too

That's what I'm planning to do

Ok 👍 , as long as we don't have to configure the aws-kotlin-repo-tools version in two places

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we get the version from inside configureLinting?

fun Project.configureLinting(lintPaths: List<String>) {
    val repoToolsVersion = project
        .configurations
        .filter { it.isCanBeResolved }
        .flatMap { it.resolvedConfiguration.resolvedArtifacts }
        .map { it.moduleVersion.id }
        .filter { it.group == "aws.sdk.kotlin.gradle" && it.name == "build-support" }
        .map { it.version }
        .distinct()
        .single()
    ...
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't as far as I know, this code returns an empty list. The list is already empty by the flatMap call.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code worked:

    val repoToolsVersion = extensions
        .getByType<VersionCatalogsExtension>()
        .named("libs")
        .findVersion("aws-kotlin-repo-tools-version")
        .get()
        .requiredVersion

@0marperez 0marperez changed the title misc: fix custom ktlint rules fix: custom ktlint rules Sep 10, 2025
@0marperez 0marperez merged commit c17e9c4 into main Sep 11, 2025
7 checks passed
@0marperez 0marperez deleted the fix-custom-rules branch September 11, 2025 15:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants