-
Notifications
You must be signed in to change notification settings - Fork 289
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
Escape soft and modifier keywords #994
Conversation
Failure is due to ktlint, my guess is that it doesn't like trailing commas. Will see if there's a newer version, otherwise will remove the comma. |
4105e8c
to
564dd59
Compare
I'm uneasy about this to be honest. Could we scope this down at all to only specific problematic spots? |
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 fine with this. Fix the problem, and then pull it back where we can. Better than playing whack-a-mole long-term.
Since there's an unknown number of problematic spots (enum value with constructor arguments is just an example) I think we'll be in a better spot if we catch all potential problems. Agree this is not needed in a lot of constructs, but maybe we can figure out a way to allow-list constructs that only require escaping the hard keywords? Open to ideas, but gonna merge this for now as it fixes the bug. |
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.
thank you
@@ -165,36 +165,87 @@ private val IDENTIFIER_REGEX = | |||
|
|||
internal val String.isIdentifier get() = IDENTIFIER_REGEX.matches(this) | |||
|
|||
// https://github.com/JetBrains/kotlin/search?q=KeywordStringsGenerated.java | |||
// https://kotlinlang.org/docs/reference/keyword-reference.html |
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.
👍
private val KEYWORDS = setOf( | ||
"package", | ||
// Hard keywords |
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.
@Egorand I was wondering if you could expand on what this does exactly? This seems to have broken one of my clients |
@abakes we used to only escape hard keywords before this change, but the issue this PR fixes described a scenario where that approach was failing, hence the decision to start escaping all Kotlin keywords. Wanna open a new issue and describe what broke in your code? A runnable test case would be ideal. |
Fixes #991
Feels overly restrictive, but the only alternative would be to encode the compiler rules of allowing soft keywords in specific contexts.