diff --git a/diktat-rules/src/main/kotlin/generated/WarningNames.kt b/diktat-rules/src/main/kotlin/generated/WarningNames.kt index ed08bc2f2e..5332a3e099 100644 --- a/diktat-rules/src/main/kotlin/generated/WarningNames.kt +++ b/diktat-rules/src/main/kotlin/generated/WarningNames.kt @@ -203,8 +203,6 @@ public object WarningNames { public const val RUN_BLOCKING_INSIDE_ASYNC: String = "RUN_BLOCKING_INSIDE_ASYNC" - public const val TOO_MANY_LINES_IN_LAMBDA: String = "TOO_MANY_LINES_IN_LAMBDA" - public const val SINGLE_CONSTRUCTOR_SHOULD_BE_PRIMARY: String = "SINGLE_CONSTRUCTOR_SHOULD_BE_PRIMARY" diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/LambdaLengthRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/LambdaLengthRule.kt index 3ae6b086eb..681b9bd077 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/LambdaLengthRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/LambdaLengthRule.kt @@ -12,7 +12,7 @@ import com.pinterest.ktlint.core.ast.ElementType import org.jetbrains.kotlin.com.intellij.lang.ASTNode /** - * Rule 5.2.4 check lambda length without parameters + * Rule 5.2.5 check lambda length without parameters */ class LambdaLengthRule(private val configRules: List) : Rule("lambda-length") { private val configuration by lazy { @@ -40,12 +40,12 @@ class LambdaLengthRule(private val configRules: List) : Rule("lambd val copyNode = node.clone() as ASTNode val sizeLambda = countCodeLines(copyNode) if (sizeLambda > configuration.maxLambdaLength) { - copyNode.findAllNodesWithCondition({it.elementType == ElementType.LAMBDA_EXPRESSION}).forEachIndexed {index, node -> + copyNode.findAllNodesWithCondition({ it.elementType == ElementType.LAMBDA_EXPRESSION }).forEachIndexed { index, node -> if (index > 0) { node.treeParent.removeChild(node) } } - val isIt: Boolean = copyNode.findAllNodesWithSpecificType(ElementType.REFERENCE_EXPRESSION).map {re -> re.text}.contains("it") + val isIt = copyNode.findAllNodesWithSpecificType(ElementType.REFERENCE_EXPRESSION).map {re -> re.text}.contains("it") val parameters = node.findChildByType(ElementType.FUNCTION_LITERAL)?.findChildByType(ElementType.VALUE_PARAMETER_LIST) if (parameters == null && isIt) { Warnings.TOO_MANY_LINES_IN_LAMBDA.warn(configRules, emitWarn, isFixMode, diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/SmartCastRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/SmartCastRule.kt index 9ade1c4a40..9e5b3c07c0 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/SmartCastRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/SmartCastRule.kt @@ -234,12 +234,12 @@ class SmartCastRule(private val configRules: List) : Rule("smart-ca val identifier = node.getFirstChildWithType(REFERENCE_EXPRESSION)?.text - node.getAllChildrenWithType(WHEN_ENTRY).forEach { node -> - if (node.hasChildOfType(WHEN_CONDITION_IS_PATTERN) && identifier != null) { - val type = node.getFirstChildWithType(WHEN_CONDITION_IS_PATTERN)!! + node.getAllChildrenWithType(WHEN_ENTRY).forEach { entry -> + if (entry.hasChildOfType(WHEN_CONDITION_IS_PATTERN) && identifier != null) { + val type = entry.getFirstChildWithType(WHEN_CONDITION_IS_PATTERN)!! .getFirstChildWithType(TYPE_REFERENCE)?.text - val callExpr = node.findAllNodesWithSpecificType(BINARY_WITH_TYPE).firstOrNull() + val callExpr = entry.findAllNodesWithSpecificType(BINARY_WITH_TYPE).firstOrNull() val blocks = listOf(IsExpressions(identifier, type ?: "")) callExpr?.let { diff --git a/info/guide/guide-TOC.md b/info/guide/guide-TOC.md index 8b99fc6ba8..e8e7a8c9a9 100644 --- a/info/guide/guide-TOC.md +++ b/info/guide/guide-TOC.md @@ -88,7 +88,7 @@ I [Preface](#c0) * [5.2.1 The lambda parameter of the function should be placed at the end of the argument list](#r5.2.1) * [5.2.2 Number of function parameters should be limited to five](#r5.2.2) * [5.2.3 Use default values for function arguments instead of overloading them](#r5.2.3) - * [5.2.4 Long lambdas should have explicit parameters](#r5.2.4) + * [5.2.5 Long lambdas should have explicit parameters](#r5.2.4) [6. Classes, interfaces, and extension functions](#c6) * [6.1 Classes](#c6.1) diff --git a/info/guide/guide-chapter-5.md b/info/guide/guide-chapter-5.md index 81cc0be993..ea27034443 100644 --- a/info/guide/guide-chapter-5.md +++ b/info/guide/guide-chapter-5.md @@ -143,6 +143,6 @@ GlobalScope.async { } } ``` -#### 5.2.4 Long lambdas should have explicit parameters +#### 5.2.5 Long lambdas should have explicit parameters The lambda without parameters shouldn't be too long. If a lambda is too long, it can confuse the user. Lambda without parameters should consist of 10 lines (non-empty and non-comment) in total.