Skip to content

Add Rule Version Filtering Based on @SinceKtlint Annotations #942

@hugoncosta

Description

@hugoncosta

Enhancement: Add Rule Version Filtering Based on @SinceKtlint Annotations

Expected Behavior

Add a new configuration option to KtLint plugin that allows users to filter out rules that were introduced after a specified KtLint version. This would use the existing @SinceKtlint annotations present on all rules to determine which rules to include.

Proposed Configuration:

ktlint {
    version.set("1.5.0")
    maxRuleVersion.set("0.46.0") // Only include rules introduced up to version 0.46.0
}

Why do I want this?
Upgrading to higher versions of Kotlin (e.g. 2.1.0) requires a newer version of Ktlint (we're currently on 1.2.1). If I upgrade it, I will cause failures due to the new rules not being respected, which I'd like to avoid.

With the proposed feature, I would be able to upgrade to the latest version (e.g. 1.7.1) which does have Kotlin 2.2 compatibility without having to introduce all the new rules between 1.2.1 and 1.7.1. This would then allow me to upgrade the rule set on my own time.

Current Behavior

No filtering allowed unless I manually exclude new rules myself.

Additional Information

  • Current version of ktlint: all

I initially proposed this in pinterest/ktlint#3099 but was redirected to the plugin itself (you can see the discussion in the thread). Let me know your thoughts on this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions