Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/maven/junit.version-5.8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
petertrr authored Sep 14, 2021
2 parents 4588f41 + 6a0d4ec commit abb2f45
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ enum class Warnings(
WRONG_NEWLINES(true, "3.6.2", "incorrect line breaking"),
TRAILING_COMMA(true, "3.6.2", "use trailing comma"),
COMPLEX_EXPRESSION(false, "3.6.3", "complex dot qualified expression should be replaced with variable"),
COMPLEX_BOOLEAN_EXPRESSION(true, "3.6.4", "too complex boolean expression, that can be simplified"),
COMPLEX_BOOLEAN_EXPRESSION(true, "3.6.4", "simplification could be produced for the too complex boolean expression"),

// FixMe: autofixing will be added for this rule
STRING_CONCATENATION(true, "3.15.1", "strings should not be concatenated using plus operator - use string templates instead if the statement fits one line"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,13 @@ class BooleanExpressionsRule(configRules: List<RulesConfig>) : DiktatRule(
.toString()
.replace("&", "&&")
.replace("|", "||")
.drop(1) // dropping first (
.dropLast(1) // dropping last )

if (simplifiedExpr.toString().first() == '(' && simplifiedExpr.toString().last() == ')') {
correctKotlinBooleanExpression = correctKotlinBooleanExpression
.drop(1)
.dropLast(1)
}

mapOfExpressionToChar.forEach { (key, value) ->
correctKotlinBooleanExpression = correctKotlinBooleanExpression.replace(value.toString(), key)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,10 @@ class BooleanExpressionsRuleFixTest : FixTestBase("test/paragraph3/boolean_expre
fun `check distributive law fixing`() {
fixAndCompare("DistributiveLawExpected.kt", "DistributiveLawTest.kt")
}

@Test
@Tag(WarningNames.COMPLEX_BOOLEAN_EXPRESSION)
fun `check same expressions`() {
fixAndCompare("SameExpressionsInConditionExpected.kt", "SameExpressionsInConditionTest.kt")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
fun foo() {
if (a) {}
if (a) {}
if (a) {}

return if (node is TomlKeyValueSimple) {
decodeValue().toString().toLowerCase() != "null"
} else {
true
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
fun foo() {
if (a || a) {}
if (a && a) {}
if ((((a && a)))) {}

return if ((node is TomlKeyValueSimple) || (node is TomlKeyValueSimple)) {
decodeValue().toString().toLowerCase() != "null"
} else {
true
}
}

0 comments on commit abb2f45

Please sign in to comment.