-
Notifications
You must be signed in to change notification settings - Fork 39
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
Bugfix: proper newlines for return type #1122
Conversation
b6455d4
to
06e8149
Compare
Codecov Report
@@ Coverage Diff @@
## master #1122 +/- ##
============================================
+ Coverage 83.43% 83.53% +0.09%
- Complexity 2465 2472 +7
============================================
Files 102 102
Lines 6153 6170 +17
Branches 1842 1844 +2
============================================
+ Hits 5134 5154 +20
+ Misses 274 270 -4
- Partials 745 746 +1
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
…o bugfix/newline_for_return_type
### What's done: * Code style
3da61b1
to
514442b
Compare
it.elementType == COMMA && | ||
!it.treeNext.run { elementType == WHITE_SPACE && textContains('\n') } | ||
(it.elementType == COMMA && !it.treeNext.isNewLineNode()) || | ||
// Move RPAR to the new line, if there is exist return type == TYPE_REFERENCE |
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 think, return type is not required here. IF function returns Unit, then it still should follow this style:
fun foo(arg1: Foo,
arg2: Foo
) {
// body
}
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 thought about this, and the first version were used such logic: append new line anytime before RPAR
But while I changed the code according this rule over the project, I met, that probably such cases seems appropriate without new line.
Since in this case, we don't need to point out to the reader to something important by adding this extra line, because there are only brackets on it
For example let take less test-based
example, than yours, the following seems to me more prettier
private fun deleteSpaces(node: ASTNode,
rightSide: Boolean) {
Than this:
private fun deleteSpaces(node: ASTNode,
rightSide: Boolean
) {
But, if you are still disagree with me, I can revert logic and add new lines anytime
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, but what about this code:
private fun deleteSpaces(
node: ASTNode,
rightSide: Boolean) {
// method body starts here
}
vs this:
private fun deleteSpaces(
node: ASTNode,
rightSide: Boolean
) {
// method body starts here
}
I think in the latter case parameter list and method body are separated more clearly.
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, don't check for return type for now, add new line after RPAR
always
if (commaOrRpar.elementType == COMMA) { | ||
nextWhiteSpace?.treeNext?.let { | ||
commaOrRpar.appendNewlineMergingWhiteSpace(nextWhiteSpace, nextWhiteSpace.treeNext) | ||
} ?: commaOrRpar.treeNext?.treeParent?.appendNewlineMergingWhiteSpace(nextWhiteSpace, commaOrRpar.treeNext) |
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.
This looks a little tricky (accessing treeParent
, but only if treeNext != null
?). Can you provide some comments here?
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.
Basically, the previous logic is holds: we append new line before nextWhiteSpace
if it exists, otherwise before current commaOrRpar
node.
Previously were the following:
comma.appendNewlineMergingWhiteSpace(nextWhiteSpace, nextWhiteSpace?.treeNext ?: comma.treeNext)
but it was incorrect and lead to the NPE, since when we would like to append node before comma.treeNext
we should call this method on the parent
node, and not on comma
node itself
What's done: