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
Remove PsiFile.lineSeparator #7240
Conversation
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.
I reviewed the new commits in this PR (the ones that are not in the previous ones) and it looks really good :)
detekt-cli/src/test/kotlin/io/gitlab/arturbosch/detekt/cli/runners/RunnerSpec.kt
Show resolved
Hide resolved
detekt only needs to set this itself when compiling KtFile directly. When other methods are used to create KtFiles the line separator is automatically set.
checkNotNull(virtualFile.detectedLineSeparator) { | ||
"Line separator was not automatically detected. This is unexpected." | ||
} |
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.
I'm not 100% sure about this. I think that all the KtFile
s will say \n
because we clean the line separator by using the function convertLineSeparators
here:
detekt/detekt-parser/src/main/kotlin/io/github/detekt/parser/KtCompiler.kt
Lines 27 to 36 in b01bc7a
fun createKtFile(@Language("kotlin") content: String, path: Path): KtFile { | |
val psiFile = psiFileFactory.createPhysicalFile(path.name, StringUtilRt.convertLineSeparators(content)) | |
return psiFile.apply { | |
val normalizedAbsolutePath = path.absolute().normalize() | |
this.absolutePath = normalizedAbsolutePath | |
this.lineSeparator = content.determineLineSeparator() | |
} | |
} | |
} |
c86160b stops that "cleaning" for one of the fuctions but the other one still uses it. I realised of this while reviewing this commit d36b3dc.
I assume that it is ok to stop using convertLineSeparators
but I guess that we should stop using it in this PR otherwise we are breaking something. And if the tests doesn't spot this we should first check our tests to be sure that we have proper coverage for this.
Or maybe I'm just wrong, that can be also true.
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.
I think that all the KtFiles will say
\n
When #7255 gets merged the createKtFile function is moved so it's used by tests only, so neither function will make copies of the file text or try detecting line separators at all. The tests you commented on also ensure that everything works, at least when calling via CLI, which is what the Gradle plugin uses. That covers all bases with autocorrect.
For now though, please check the updates to createKtFile
in this PR. It now stores the detected line separator using virtualFile.setDetectedLineSeparator
: https://github.com/detekt/detekt/pull/7240/files#diff-5dc598360678521200286ef06ac96f589ea689b19e935b5f8dd058dfada7850cR32 which could be \r\n
or \n
depending on platform.
This is required when loading KtFile using standard methods
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #7240 +/- ##
============================================
- Coverage 84.77% 84.75% -0.02%
Complexity 3994 3994
============================================
Files 578 577 -1
Lines 12131 12130 -1
Branches 2483 2484 +1
============================================
- Hits 10284 10281 -3
- Misses 623 624 +1
- Partials 1224 1225 +1 ☔ View full report in Codecov by Sentry. |
Waiting on merge of: