Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for formatting a specific violation in a piece of code containing multiple violations #2658

Closed
paul-dingemans opened this issue May 15, 2024 · 0 comments · Fixed by #2671
Milestone

Comments

@paul-dingemans
Copy link
Collaborator

The Ktlint formatting fixes all violations in a given piece of code for which an autocorrect is available. Given a piece of code that contains multiple violations that can be autocorrected, it is not easily possible to indicate that only one specific violations needs to be fixed.

When the ktlint-intellij-plugin is used in manual the user wants/needs to resolve the violations one by one in order to pick and choose which violations have to be corrected. See nbadal/ktlint-intellij-plugin#482

paul-dingemans added a commit that referenced this issue May 28, 2024
paul-dingemans added a commit that referenced this issue May 28, 2024
paul-dingemans added a commit that referenced this issue May 28, 2024
paul-dingemans added a commit that referenced this issue May 28, 2024
paul-dingemans added a commit that referenced this issue May 28, 2024
paul-dingemans added a commit that referenced this issue May 28, 2024
@paul-dingemans paul-dingemans added this to the 1.3.0 milestone May 28, 2024
paul-dingemans added a commit that referenced this issue May 28, 2024
paul-dingemans added a commit that referenced this issue May 28, 2024
…or not (#2671)

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 `LintError`s. 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 `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 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
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 a pull request may close this issue.

1 participant