From e538e5331eb6838493f16648a358698fda2911fd Mon Sep 17 00:00:00 2001 From: Stanley Shyiko Date: Sun, 23 Jul 2017 23:01:08 -0700 Subject: [PATCH] Fixed node removal --- .../shyiko/ktlint/ruleset/standard/NoSemicolonsRule.kt | 2 +- .../shyiko/ktlint/ruleset/standard/SpacingAroundCurlyRule.kt | 2 +- .../ktlint/ruleset/standard/SpacingAroundKeywordRule.kt | 5 +++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/github/shyiko/ktlint/ruleset/standard/NoSemicolonsRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/github/shyiko/ktlint/ruleset/standard/NoSemicolonsRule.kt index 804b37ce2c..b9cdeabeb9 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/github/shyiko/ktlint/ruleset/standard/NoSemicolonsRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/github/shyiko/ktlint/ruleset/standard/NoSemicolonsRule.kt @@ -21,7 +21,7 @@ class NoSemicolonsRule : Rule("no-semi") { ) { emit(node.startOffset, "Unnecessary semicolon", true) if (autoCorrect) { - node.delete() + node.treeParent.removeChild(node) } } else if (nextLeaf !is PsiWhiteSpace) { // todo: move to a separate rule diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/github/shyiko/ktlint/ruleset/standard/SpacingAroundCurlyRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/github/shyiko/ktlint/ruleset/standard/SpacingAroundCurlyRule.kt index 3a1998e89c..79f8ab6791 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/github/shyiko/ktlint/ruleset/standard/SpacingAroundCurlyRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/github/shyiko/ktlint/ruleset/standard/SpacingAroundCurlyRule.kt @@ -31,7 +31,7 @@ class SpacingAroundCurlyRule : Rule("curly-spacing") { shouldNotToBeSeparatedBySpace(PsiTreeUtil.nextLeaf(nextLeaf, true))) { emit(node.startOffset, "Unexpected space after \"${node.text}\"", true) if (autoCorrect) { - nextLeaf.delete() + nextLeaf.node.treeParent.removeChild(nextLeaf.node) } } } else { diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/github/shyiko/ktlint/ruleset/standard/SpacingAroundKeywordRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/github/shyiko/ktlint/ruleset/standard/SpacingAroundKeywordRule.kt index 560e50d7c0..fc0f7adc51 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/github/shyiko/ktlint/ruleset/standard/SpacingAroundKeywordRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/github/shyiko/ktlint/ruleset/standard/SpacingAroundKeywordRule.kt @@ -40,10 +40,11 @@ class SpacingAroundKeywordRule : Rule("keyword-spacing") { } } else if (keywordsWithoutSpaces.contains(node.elementType) && node.nextLeaf() is PsiWhiteSpace) { val parent = node.parent - if (parent is KtPropertyAccessor && parent.hasBody()) { + val nextLeaf = node.nextLeaf() + if (parent is KtPropertyAccessor && parent.hasBody() && nextLeaf != null) { emit(node.startOffset, "Unexpected spacing after \"${node.text}\"", true) if (autoCorrect) { - node.nextLeaf()?.delete() + nextLeaf.node.treeParent.removeChild(nextLeaf.node) } } }