Skip to content

Commit

Permalink
Incorrect fix of null-safety rule
Browse files Browse the repository at this point in the history
### What's done:
Fixed according to our code-style
  • Loading branch information
kentr0w committed Apr 30, 2021
1 parent 91cfffb commit 45864c0
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class NullChecksRule(configRules: List<RulesConfig>) : DiktatRule(
if (condition.getBreakNodeFromIf(THEN)) {
"$variableName ?: break"
} else {
"$variableName ?: run {${thenCodeLines?.joinToString(prefix = "\n" , postfix = "\n", separator = "\n")}}"
"$variableName ?: run {${thenCodeLines?.joinToString(prefix = "\n", postfix = "\n", separator = "\n")}}"
}
thenCodeLines!!.singleOrNull() == "null" -> """
|$variableName?.let {
Expand All @@ -150,9 +150,9 @@ class NullChecksRule(configRules: List<RulesConfig>) : DiktatRule(
} else {
when {
elseCodeLines.isNullOrEmpty() || (elseCodeLines.singleOrNull() == "null") ->
"$variableName?.let {${thenCodeLines?.joinToString(prefix = "\n" , postfix = "\n", separator = "\n")}}"
"$variableName?.let {${thenCodeLines?.joinToString(prefix = "\n", postfix = "\n", separator = "\n")}}"
elseCodeLines.singleOrNull() == "break" ->
"$variableName?.let {${thenCodeLines?.joinToString(prefix = "\n" , postfix = "\n", separator = "\n")}} ?: break"
"$variableName?.let {${thenCodeLines?.joinToString(prefix = "\n", postfix = "\n", separator = "\n")}} ?: break"
else -> """
|$variableName?.let {
|${thenCodeLines?.joinToString(separator = "\n")}
Expand Down Expand Up @@ -205,7 +205,7 @@ class NullChecksRule(configRules: List<RulesConfig>) : DiktatRule(
.treeParent
.findChildByType(type)
?.let { it.findChildByType(BLOCK) ?: it }
?.findAllNodesWithCondition({it.elementType == BREAK})?.isNotEmpty()
?.findAllNodesWithCondition({ it.elementType == BREAK })?.isNotEmpty()
?: false

private fun ASTNode.extractLinesFromBlock(type: IElementType): List<String>? =
Expand Down

0 comments on commit 45864c0

Please sign in to comment.