pinterest / ktlint

An anti-bikeshedding Kotlin linter with built-in formatter
https://pinterest.github.io/ktlint/
MIT License
6.06k stars 504 forks source link

Let API Consumer decide whether a LintError has to be autocorrected, or not #2671

Closed paul-dingemans closed 1 month ago

paul-dingemans commented 1 month ago

Description

When formatting code, the API Consumer should be able to decide whether a LintError has to be autocorrected, or not. In most cases the API Consumer wants to autocorrect all errors that have an autocorrect fix when formatting the code.

The ktlint-intellij-plugin has two use cases in which not all LintError having an autocorrect should be fixed when invoking the format functionality.

To avoid breaking changes in Ktlint 1.x, a new RuleAutocorrectApproveHandler interface is added. This interfaces defines the new signatures for functions beforeVisitChildNodes and afterVisitChildNodes. Rules that implement this interface will request the API Consumer to approve to autocorrect a LintError before continuing with formatting the code.

Closes #2658

Checklist

Before submitting the PR, please check following (checks which are not relevant may be ignored):

Documentation is updated. See difference between snapshot and release documentation