Skip to content

Conversation

@0marperez
Copy link
Contributor

Issue #, if available:
N/A

Description of changes:

  • Function to create deprecatedUntilVersion ktlint rule based on major and minor version.
  • Function to create Gradle tasks to run minor-version-strategy ktlint rules
  • GH action to run new Gradle task from above

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

@0marperez 0marperez marked this pull request as ready for review September 16, 2025 21:52
@0marperez 0marperez requested a review from a team as a code owner September 16, 2025 21:52
minorVersionBumpKtlint(project(":ktlint-rules:minor-version-strategy"))
}

tasks.register<JavaExec>("minorVersionBumpScan") {
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: validateMinorVersionBump?

}

tasks.test {
useJUnitPlatform()
Copy link
Member

Choose a reason for hiding this comment

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

You shouldn't need this useJUnitPlatform() call

Comment on lines 41 to 45
if (autoCorrect) {
node.treeParent.treeParent?.let {
it.treeParent.removeChild(it)
}
}
Copy link
Member

Choose a reason for hiding this comment

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

I think we should remove autocorrect from this rule, deleting APIs should be an intentional action, not something our linter does

Copy link
Contributor Author

@0marperez 0marperez Sep 17, 2025

Choose a reason for hiding this comment

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

It won't run on every lint, only when someone executes the new Gradle task (fixMinorVersionBump). We should delete deprecated APIs when they're scheduled for removal, why not automate it?

Copy link
Member

Choose a reason for hiding this comment

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

Deleting APIs is a sensitive operation and should not be automated

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed, we'll likely have to make other manual changes after deleting a deprecated API such as replacing its usage in calling functions.

Copy link
Member

Choose a reason for hiding this comment

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

naming: ApisScheduledForRemovalRule is awkward and long, how about DeprecatedApiRule?

* Creates a ktlint rule that detects APIs annotated with @DeprecatedUntilVersion for the specified versions.
* If autocorrect is enabled, the API will be deleted.
*/
fun apisScheduledForRemovalRule(major: Int, minor: Int): Rule =
Copy link
Member

Choose a reason for hiding this comment

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

I don't see how this rule provider function gets connected to the Gradle task. Where do we pass the major / minor versions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's not used in the Gradle task, it's for the downstream ktlint-rules:minor-version-strategy modules to create the same rule with different major/minor versions.

https://github.com/aws/aws-sdk-kotlin/blob/minor-version-strategy-sdk/ktlint-rules/minor-version-strategy/src/main/kotlin/aws/sdk/kotlin/ktlintrules/minorversionstrategy/MinorVersionStrategyRuleSetProvider.kt#L23-L24

Copy link
Member

Choose a reason for hiding this comment

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

Yeah I saw that after reviewing your aws-sdk-kotlin PR. I wish the rule could be registered here for a given Project

main {
dependencies {
implementation(libs.ktlint.cli.ruleset.core)
api(libs.ktlint.cli.ruleset.core)
Copy link
Member

Choose a reason for hiding this comment

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

Was this never needed as implementation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It worked as an implementation before, but now it's an API so downstream consumers of this module don’t also need to depend on libs.ktlint.cli.ruleset.core.

https://github.com/aws/aws-sdk-kotlin/blob/minor-version-strategy-sdk/ktlint-rules/minor-version-strategy/build.gradle.kts#L14

emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit,
) {
if (node.elementType == ElementType.ANNOTATION_ENTRY) {
val sdkVersion = System.getProperty("sdkVersion").split(".")
Copy link
Member

Choose a reason for hiding this comment

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

Diving deeper, do we have to use a system property here? There's no way to inspect the gradle.properties and pull out the sdkVersion from there?

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 gradleProperties = Properties().apply {
    load(File("gradle.properties").inputStream())
}

val sdkVersion = gradleProperties.getProperty("sdkVersion")

@0marperez 0marperez merged commit 684ed83 into main Sep 18, 2025
7 checks passed
@0marperez 0marperez deleted the minor-version-strategy branch September 18, 2025 20:36
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.

3 participants