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

detekt doesn't respect ktlint RunAfterRule constraints #5259

Closed
3flex opened this issue Aug 31, 2022 · 4 comments · Fixed by #6159
Closed

detekt doesn't respect ktlint RunAfterRule constraints #5259

3flex opened this issue Aug 31, 2022 · 4 comments · Fixed by #6159
Assignees
Labels
bug formatting never gets stale Mark Issues/PRs that should not be closed as they won't get stale

Comments

@3flex
Copy link
Member

3flex commented Aug 31, 2022

Expected Behavior

detekt runs ktlint rules in the order that ktlint expects.

Observed Behavior

ktlint has a few different visitor modifiers that add constraints to the order rules are run in.

detekt checks and respects RunAsLateAsPossible and RunOnRootNodeOnly constraints, but does not check RunAfterRule. This can affect results when using autocorrect and individual rules aren't run in the correct order.

See https://github.com/pinterest/ktlint/blob/0.46.1/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/Rule.kt#L39-L60

Steps to Reproduce

I don't have a reproducer, but discovered this when doing some other work on the formatting rule set.

Context

Can affect autocorrect.

Your Environment

  • Version of detekt used:
  • Version of Gradle used (if applicable):
  • Gradle scan link (add --scan option when running the gradle task):
  • Operating System and version:
  • Link to your project (if it's a public repository):
@schalkms
Copy link
Member

schalkms commented Sep 2, 2022

Interesting…
I remember a few bug reports regarding auto-correct. It’s good that we finally discovered the reason for it.
Do you have any ideas how we can fix it in detekt?

@3flex
Copy link
Member Author

3flex commented Sep 3, 2022

Probably reimplementing some version of https://github.com/pinterest/ktlint/blob/master/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/internal/RuleRunnerSorter.kt (used in 0.47, in 0.46 the class is RuleSorter) and sorting rules accordingly.

@github-actions
Copy link

github-actions bot commented Dec 3, 2022

This issue is stale because it has been open 90 days with no activity. Please comment or this will be closed in 7 days.

@github-actions github-actions bot added the stale label Dec 3, 2022
@3flex
Copy link
Member Author

3flex commented Dec 3, 2022

Not stale

@github-actions github-actions bot removed the stale label Dec 4, 2022
@cortinico cortinico added the never gets stale Mark Issues/PRs that should not be closed as they won't get stale label Dec 13, 2022
@chao2zhang chao2zhang self-assigned this May 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug formatting never gets stale Mark Issues/PRs that should not be closed as they won't get stale
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants