-
-
Notifications
You must be signed in to change notification settings - Fork 771
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
Simplify internal parsing to KtFile's #2875
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2875 +/- ##
============================================
- Coverage 80.28% 80.24% -0.04%
+ Complexity 2417 2414 -3
============================================
Files 421 421
Lines 7359 7356 -3
Branches 1346 1345 -1
============================================
- Hits 5908 5903 -5
Misses 756 756
- Partials 695 697 +2
Continue to review full report at Codecov.
|
00f52cc
to
98272d3
Compare
val errors = mutableListOf<PsiErrorElement>() | ||
ktFile.accept(object : KtTreeVisitorVoid() { | ||
override fun visitErrorElement(element: PsiErrorElement) { | ||
errors.add(element) | ||
} | ||
}) | ||
|
||
assertThat(errors).isNotEmpty() |
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.
Is this a behavioral change now, since you had to adapt the test case?
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.
Hm, yes it is. Not sure how to handle this.
In KtTreeCompiler
we throw an exception if the file ending is not kt
or kts
.
In the old implementation the PsiFactory tried to use Language.Any
and because no language was registered was .css
it didn't tried to parse anything and returned null which we checked with error(...)
.
The KtPsiFactory
always tries to parse Kotlin and returns a PsiFile
with errors.
@schalkms @BraisGabin @cortinico should we throw an error on wrong file extension like when parsing directories?
detekt/detekt-core/src/main/kotlin/io/gitlab/arturbosch/detekt/core/KtTreeCompiler.kt
Lines 54 to 58 in 5a0fe62
private fun Path.isKotlinFile(): Boolean { | |
val fullPath = toAbsolutePath().toString() | |
val kotlinEnding = fullPath.substring(fullPath.lastIndexOf('.') + 1) | |
return kotlinEnding in KT_ENDINGS | |
} |
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.
Ok, we ignored it when parsing many files:
detekt/detekt-core/src/main/kotlin/io/gitlab/arturbosch/detekt/core/KtTreeCompiler.kt
Line 31 in 5a0fe62
settings.info("Ignoring a file detekt cannot handle: $path") |
No description provided.