Skip to content

Commit

Permalink
Fixed else handling when used as part of ternary expression
Browse files Browse the repository at this point in the history
  • Loading branch information
shyiko committed May 28, 2017
1 parent 41ec38f commit d7146cb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ class SpacingAroundKeywordRule : Rule("keyword-spacing") {
if (noLFBeforeSet.contains(node.elementType) && node is LeafPsiElement) {
val prevLeaf = PsiTreeUtil.prevLeaf(node)
if (prevLeaf is PsiWhiteSpaceImpl && prevLeaf.textContains('\n') &&
(node.elementType != ELSE_KEYWORD || node.parent !is KtWhenEntry)) {
(node.elementType != ELSE_KEYWORD || node.parent !is KtWhenEntry) &&
(PsiTreeUtil.prevLeaf(prevLeaf)?.textMatches("}") ?: false)) {
emit(node.startOffset, "Unexpected newline before \"${node.text}\"", true)
if (autoCorrect) {
prevLeaf.rawReplaceWithText(" ")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ class SpacingAroundKeywordRuleTest {
if (true) {
} else {}
if (true) {} else {}
if (true)
println()
else
entry.value
try {
"".trim()
Expand Down

0 comments on commit d7146cb

Please sign in to comment.