-
Notifications
You must be signed in to change notification settings - Fork 506
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
Fix string-template for dot-expression from which the toString() is removed #1026
Fix string-template for dot-expression from which the toString() is removed #1026
Conversation
…g is removed (pinterest#996) The no-unused-imports rule fails on the existence of the dot-expression node but for which the actual call to the toString method was removed.
This might fix #1019 although this is not sure as the issue could not be reproduced. |
(node.lastChildNode as LeafPsiElement).rawReplaceWithText("") // entry end | ||
val leftCurlyBraceNode = node.findChildByType(LONG_TEMPLATE_ENTRY_START) | ||
val rightCurlyBraceNode = node.findChildByType(LONG_TEMPLATE_ENTRY_END) | ||
if (node.children().count() == 3 && leftCurlyBraceNode != null && rightCurlyBraceNode != null) { |
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.
Could you elaborate on why count
is 3 exactly? I guess I am missing a bit of context :)
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 is a bit of defensive programma. The block above is surrounded by the following if-statement:
if (node.text.startsWith("${'$'}{") &&
node.text.let { it.substring(2, it.length - 1) }.all { it.isPartOfIdentifier() } &&
(entryExpression is KtNameReferenceExpression || entryExpression is KtThisExpression) &&
node.treeNext.let { nextSibling ->
nextSibling.elementType == CLOSING_QUOTE ||
(
nextSibling.elementType == LITERAL_STRING_TEMPLATE_ENTRY &&
!nextSibling.text[0].isPartOfIdentifier()
)
}
) {
I was not 100% sure that this statement really covers the situation of a prefix-node, content-node and a suffix-node. In case that also prefix-node, content-node-1, ..., content-node-n, suffix-node can match this statement then I do think it is not a valid to prefix only the first node with the '$'. So line 74 guards the autocorrect to patterns which can be corrected safely.
…emoved (pinterest#1026) * Fix string-template for dot-expression of which the redundant toString is removed (pinterest#996) The no-unused-imports rule fails on the existence of the dot-expression node but for which the actual call to the toString method was removed. * Update changelog * Fix code style violation Co-authored-by: Paul Dingemans <pdingemans@bol.com> Co-authored-by: Roman Zavarnitsyn <rom4ek93@gmail.com>
Given code example below:
Formatting with autocorrect of this code fails on the no-unused-imports rule as the dot-expression node still exists but the toString invocation was already removed.
Resolves #996