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

Stop creating in-memory KtFile when file path is provided #7250

Merged
merged 3 commits into from May 6, 2024

Conversation

3flex
Copy link
Member

@3flex 3flex commented May 3, 2024

Copy link

codecov bot commented May 5, 2024

Codecov Report

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

Project coverage is 84.75%. Comparing base (1d6b738) to head (982dd37).

Files Patch % Lines
.../main/kotlin/io/github/detekt/parser/KtCompiler.kt 66.66% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #7250      +/-   ##
============================================
- Coverage     84.75%   84.75%   -0.01%     
- Complexity     3994     3996       +2     
============================================
  Files           577      577              
  Lines         12130    12133       +3     
  Branches       2484     2486       +2     
============================================
+ Hits          10281    10283       +2     
  Misses          624      624              
- Partials       1225     1226       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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.

Is the last commit related with this PR? Any way, LGTM.

3flex added 3 commits May 6, 2024 17:15
This is required when loading KtFile using standard methods
The new methods will create KtFile with virtualPath.path set correctly
The same instance of a KtFile will be reused in some circumstances. To
avoid issues the modifiedText must be reset.
@3flex 3flex marked this pull request as ready for review May 6, 2024 07:17
@3flex
Copy link
Member Author

3flex commented May 6, 2024

Is the last commit related with this PR?

It is, yes. If it's not done in AutoCorrectLevelSpec.kt then the tests will fail because the same PsiFile is being reused between tests, and the modified text persists between them. This wasn't a problem before because detekt would always create a new copy of every file it analysed, but that doesn't happen after this PR.

There may be scenarios in IDE or other usages where the same PsiFile is also reused so I figured it's safest to defend against that by making a similar change in KtFileModifier.kt

@3flex 3flex enabled auto-merge (squash) May 6, 2024 07:20
@3flex 3flex merged commit 731735b into detekt:main May 6, 2024
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants