-
Notifications
You must be signed in to change notification settings - Fork 453
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
Keyword sanitization for Lens code generation (#2924) #2925
Conversation
Thanks for your contribution, @hrafnthor! May I suggest to use the entire set of keywords instead of a few? You can copy the list from here. |
* Set moved out of function to avoid its creation on each invocation. * Mock test package header now has keywords from each category.
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.
LGTM, just a few style comments
fun String.sanitizeDelimited(delimiter: String = ".", separator: String = delimiter) = | ||
if (isNotBlank() && contains(delimiter)) { | ||
splitToSequence(delimiter).joinToString(separator) { if (kotlinKeywords.contains(it)) "`$it`" else it } | ||
} else this |
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 don't think you need to consider empty and not containing delimiter as special cases, splitToSequence
+ joinToString
should do the right thing
if (isMarkedNullable) "$n?" else n | ||
} | ||
else -> when (val qname = declaration.qualifiedName?.asString()) { | ||
else -> when (val qname = declaration.qualifiedName?.asString()?.sanitizeDelimited()) { |
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.
It might read better if asStringSanitized
was an extension of Name
(but if you prefer this way, it's also fine)
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 agree, it would be more readable as well as limit the scope of the function to relevant parts i.e KSName rather than any String. Will change the extension signature and apply it where applicable.
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 @hrafnthor for being so quick to fix your own bug report 🙏 👏 Really awesome!
And congrats on your first contribution to Arrow 🙌
* Extension function applied to KSName rather than String * Function signature modified to match its function better * Unnecessary function checks removed based on feedback
Kotlin keyword sanitization added to class path fields used during Lens code generation.
Only keywords matching potential TLDs are observed.