Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
### What's done:
* Fixes
  • Loading branch information
kgevorkyan committed Nov 15, 2021
1 parent 9d09cef commit 3da61b1
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ class BooleanExpressionsRule(configRules: List<RulesConfig>) : DiktatRule(
private fun checkDistributiveLaw(
expr: Expression<String>,
mapOfExpressionToChar: HashMap<String, Char>,
node: ASTNode): String? {
node: ASTNode
): String? {
// checking that expression can be considered as distributive law
val commonDistributiveOperand = getCommonDistributiveOperand(node, expr.toString(), mapOfExpressionToChar) ?: return null
val correctSymbolsSequence = mapOfExpressionToChar.values.toMutableList()
Expand Down Expand Up @@ -217,7 +218,8 @@ class BooleanExpressionsRule(configRules: List<RulesConfig>) : DiktatRule(
private fun getCommonDistributiveOperand(
node: ASTNode,
expression: String,
mapOfExpressionToChar: HashMap<String, Char>): Char? {
mapOfExpressionToChar: HashMap<String, Char>
): Char? {
val operationSequence = expression.filter { it == '&' || it == '|' }
val numberOfOperationReferences = operationSequence.length
// There should be three operands and three operation references in order to consider the expression
Expand Down Expand Up @@ -251,7 +253,8 @@ class BooleanExpressionsRule(configRules: List<RulesConfig>) : DiktatRule(
private fun getCommonOperand(
expression: String,
firstSplitDelimiter: Char,
secondSplitDelimiter: Char): Char? {
secondSplitDelimiter: Char
): Char? {
val expressions = expression.split(firstSplitDelimiter)
val listOfPairs: MutableList<List<String>> = mutableListOf()
expressions.forEach { expr ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ class LongNumericalValuesSeparatedRule(configRules: List<RulesConfig>) : DiktatR
private fun isValidConstant(
text: String,
configuration: LongNumericalValuesConfiguration,
node: ASTNode): Boolean {
node: ASTNode
): Boolean {
if (text.contains("_")) {
checkBlocks(removePrefixSuffix(text), configuration, node)
return true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,8 @@ class NewlinesRule(configRules: List<RulesConfig>) : DiktatRule(
(it.elementType == RPAR &&
it.treePrev.elementType != COMMA &&
!it.treePrev.isNewLineNode() &&
it.treeParent.treeParent.findChildByType(TYPE_REFERENCE) != null)
it.treeParent.treeParent.children().dropWhile { it.elementType != COLON }.filter { it.elementType == TYPE_REFERENCE }
.toList().isNotEmpty())
}
.toList()
.takeIf { it.isNotEmpty() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,8 @@ class WhiteSpaceRule(configRules: List<RulesConfig>) : DiktatRule(
private fun getDescription(shouldBefore: Boolean,
shouldAfter: Boolean,
before: Int?,
after: Int?): String =
after: Int?
): String =
if (shouldBefore && shouldAfter) {
" $before space(s) before and $after space(s) after"
} else if (shouldBefore && !shouldAfter) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ class SmartCastRule(configRules: List<RulesConfig>) : DiktatRule(
@Suppress("TYPE_ALIAS")
private fun groupIsAndAsExpr(isExpr: List<KtNameReferenceExpression>,
asExpr: List<KtNameReferenceExpression>,
prop: KtProperty): Map<KtNameReferenceExpression, List<KtNameReferenceExpression>> {
prop: KtProperty
): Map<KtNameReferenceExpression, List<KtNameReferenceExpression>> {
if (isExpr.isEmpty() && asExpr.isNotEmpty()) {
handleZeroIsCase(asExpr, prop)
return emptyMap()
Expand Down

0 comments on commit 3da61b1

Please sign in to comment.