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

Remove PsiFile.lineSeparator #7240

Merged
merged 4 commits into from May 6, 2024
Merged

Remove PsiFile.lineSeparator #7240

merged 4 commits into from May 6, 2024

Conversation

BraisGabin
BraisGabin previously approved these changes May 5, 2024
Copy link
Member

@BraisGabin BraisGabin left a 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 :)

3flex added 3 commits May 6, 2024 09:47
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.
Comment on lines +29 to +31
checkNotNull(virtualFile.detectedLineSeparator) {
"Line separator was not automatically detected. This is unexpected."
}
Copy link
Member

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 KtFiles will say \n because we clean the line separator by using the function convertLineSeparators here:

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.

Copy link
Member Author

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.

@BraisGabin BraisGabin dismissed their stale review May 5, 2024 23:54

Because of the last commit

@3flex 3flex marked this pull request as ready for review May 6, 2024 00:23
This is required when loading KtFile using standard methods
Copy link

codecov bot commented May 6, 2024

Codecov Report

Attention: Patch coverage is 33.33333% with 2 lines in your changes are missing coverage. Please review.

Project coverage is 84.75%. Comparing base (b01bc7a) to head (1831c94).

Files Patch % Lines
...io/gitlab/arturbosch/detekt/core/KtFileModifier.kt 0.00% 1 Missing and 1 partial ⚠️
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.
📢 Have feedback on the report? Share it here.

@3flex 3flex merged commit 1d6b738 into detekt:main May 6, 2024
20 of 21 checks passed
@3flex 3flex deleted the location-5 branch May 6, 2024 07:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api breaking change Marker for breaking changes which should be highlighted in the changelog core parser psi-utils
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants