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.
In manual mode the plugin shows all LintErrors. Users want to be able to choose to autocorrect a specific LintError, while at the same time ignoring other LintErrors.
When selecting a block of code in a file, the user want to be able to format only the LintErrors in the selected text.
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):
[X] Commit message are well written. In addition to a short title, the commit message also explain why a change is made.
[ ] At least one commit message contains a reference Closes #<xxx> or Fixes #<xxx> (replace<xxx> with issue number)
[X] Tests are added
[X] KtLint format has been applied on source code itself and violations are fixed
[X] PR title is short and clear (it is used as description in the release changelog)
[X] Snapshot documentation in case documentation is to be released together with a code change
[ ] Release documentation in case documentation is related to a released version of ktlint and has to be published as soon as the change is merged to master
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 allLintError
having an autocorrect should be fixed when invoking theformat
functionality.manual
mode the plugin shows allLintError
s. Users want to be able to choose to autocorrect a specificLintError
, while at the same time ignoring otherLintErrors
.LintError
s in the selected text.To avoid breaking changes in Ktlint 1.x, a new
RuleAutocorrectApproveHandler
interface is added. This interfaces defines the new signatures for functionsbeforeVisitChildNodes
andafterVisitChildNodes
. Rules that implement this interface will request the API Consumer to approve to autocorrect aLintError
before continuing with formatting the code.Closes #2658
Checklist
Before submitting the PR, please check following (checks which are not relevant may be ignored):
Closes #<xxx>
orFixes #<xxx>
(replace<xxx>
with issue number)Documentation is updated. See difference between snapshot and release documentation