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
Switch order of correctable rules and other rules #3317
Conversation
Interestingly, the previous code caused a crash in (detekt#2693). The problem is that we run Ktlint/CommentSpacing before running LongMethod. Because CommentSpacing mutates the ktfile.text, but does not update ktfile.viewerProvider.document, resulting in inconsistency and crash. Note that this commit is merely a short-term fix. In the long term, we should think be more careful in rule running order, while leveraging parallelism to optimize the runtime.
Fun fact: I almost spent my day debugging this. I initially thought this is a Kotlin compiler bug and started by refactoring the code to extract |
Codecov Report
@@ Coverage Diff @@
## master #3317 +/- ##
=========================================
Coverage 80.27% 80.27%
Complexity 2676 2676
=========================================
Files 443 443
Lines 8142 8142
Branches 1548 1548
=========================================
Hits 6536 6536
Misses 775 775
Partials 831 831
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't merge this because it will break the html report and the position of a lot of issues. If you first run the no correctable and then the correctable ones all the issues that you found before could have change its position.
We need to find other way to fix this.
The problem is that KtFile doesn't update itself correctly. Right? So we could open an issue to jetbrains. But that could be really slow so, how could we fix it in our end? Who is using that value that is not updated? Our rules? Or the ktlint rules?
That's a good point. Let me summarize the dilemma:
There are several ways to fix them:
There is a collection of tangential issues related to this: Overall autocorrection is a difficult problem. I am wondering if Ktlint owners can shed some lights (The ordering marker interface was added in pinterest/ktlint#101 and modified in pinterest/ktlint#158) |
Other option is to run the correctable ones first and, if there is any change, regenerate the KtFile. This one would be slower. |
I may not have the privilege, but is it possible to convert this PR to a discussion? If not, let's create a new discussion and close this PR |
It seems that we can't convert PRs in conversations. But I think that this is better suited in an issue. This is a bug. |
Interestingly, the previous code caused a crash in (#2693). The problem is that we run Ktlint/CommentSpacing before running LongMethod. Because CommentSpacing mutates the
ktfile.text
, but does not updateKtfile.viewerProvider.document
, resulting in an inconsistent state and eventually crash (#2693 (comment))Note that this commit is merely a short-term fix. In the long term, we should be more careful in rule running order, while leveraging parallelism to optimize the runtime.
Test
I verified that the correct violations
CommentSpacing
are reported in the sample project (https://github.com/andrey-bolduzev/detekt_issue_2693) after the change. Before this change, it will crash withjava.lang.IndexOutOfBoundsException: Wrong offset: 834. Should be in range: [0, 833]