Skip to content

Commit

Permalink
Keep empty brace of companion object (#600)
Browse files Browse the repository at this point in the history
  • Loading branch information
yukukotani authored and Tapchicoma committed Oct 3, 2019
1 parent 7f8b89a commit 3963a77
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.pinterest.ktlint.core.ast.ElementType.CLASS_BODY
import com.pinterest.ktlint.core.ast.ElementType.LBRACE
import com.pinterest.ktlint.core.ast.ElementType.RBRACE
import com.pinterest.ktlint.core.ast.ElementType.WHITE_SPACE
import com.pinterest.ktlint.core.ast.children
import com.pinterest.ktlint.core.ast.isPartOf
import com.pinterest.ktlint.core.ast.nextLeaf
import org.jetbrains.kotlin.com.intellij.lang.ASTNode
Expand All @@ -22,7 +23,8 @@ class NoEmptyClassBodyRule : Rule("no-empty-class-body") {
n.elementType == LBRACE &&
n.nextLeaf { it.elementType != WHITE_SPACE }?.elementType == RBRACE
} == true &&
!node.isPartOf(KtObjectLiteralExpression::class)
!node.isPartOf(KtObjectLiteralExpression::class) &&
node.treeParent.firstChildNode.children().none { it.text == "companion" }
) {
emit(node.startOffset, "Unnecessary block (\"{}\")", true)
if (autoCorrect) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ val o = object : TypeReference<HashMap<String, String>>() {}

fun main() {}

class C3 {
companion object {}
}

// expect
// 1:10:Unnecessary block ("{}")
// 2:28:Unnecessary block ("{}")
Expand Down

0 comments on commit 3963a77

Please sign in to comment.