Repository navigation
fix(kotlin): count character literals - #790
Merged
Merged
Conversation
Kotlin only declared the double quote, so a character literal holding one, such as '"', opened a string that ran on to the next " in the file and turned the comments and blank lines in between into code. Declare ' as a quote, and the backtick as well, so the apostrophe in a backticked name like `it doesn't crash` does not open a character literal of its own. The Kotlin counter is taught the same two quotes so it keeps agreeing with the generic loop.
Owner
|
TY |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Kotlin only had
"as a quote, so a character literal holding one, like'"', opened a string that ran to the next"in the file and turned the comments and blank lines in between into code. For example:was counted as all code.
This adds
'as a quote, and the backtick too, so the apostrophe in a backticked test name like`it doesn't crash`doesn't open a character literal of its own (adding'on its own turned such test files into all code). The Kotlin counter behind--exp-per-language-countersgets the same two quotes, so it keeps agreeing with the generic loop. I ran it against okhttp and kotlinx.coroutines withSCC_DIFF_KOTLIN_CORPUSand the two agreed on all 1612 files.On okhttp this mostly gives back comment and blank lines in files that use
'"', such asHttpHeaders.ktandMultipartBody.kt. The one file that got worse isRequestTest.kt, which has a"""raw string containing both"and an apostrophe; raw strings aren't modelled for Kotlin yet, and that would be a separate change.I explicitly license this contribution under the MIT licence.