From 544011fb8c17304067321aab28203b16f50ba0e1 Mon Sep 17 00:00:00 2001 From: Arrgentum Date: Tue, 24 May 2022 18:27:58 +0300 Subject: [PATCH] ### Whats added: * corrected logic fix and warn String Template in Linelength rule * added logic fix and warn long Dot Qualified Expression in LineLength rule * added logic fix and warn Value Arguments List in LineLength rule * added and corrected fix and warn tests in LineLength rule * fix code with diktat:fix@diktat * added comments to classes and functions * correct code with running detect ### Issue (#1243) --- .../cqfn/diktat/ruleset/rules/chapter3/LineLength.kt | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/LineLength.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/LineLength.kt index 304c0c0d6b..8aa237a116 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/LineLength.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/LineLength.kt @@ -123,6 +123,7 @@ class LineLength(configRules: List) : DiktatRule( @Suppress( "TOO_LONG_FUNCTION", + "LongMethod", "ComplexMethod", "GENERIC_VARIABLE_WRONG_DECLARATION", ) @@ -221,7 +222,7 @@ class LineLength(configRules: List) : DiktatRule( ): LongLineFixableCases { funOrPropertyNode?.let { if (it.hasChildOfType(EQ)) { - val positionByOffset = positionByOffset(it.getFirstChildWithType(EQ)!!.startOffset).second + val positionByOffset = positionByOffset(it.getFirstChildWithType(EQ)?.startOffset ?: 0).second if (positionByOffset < configuration.lineLength / 2) { val returnedClass = parserStringAndDot(node, configuration) if (returnedClass !is None) { @@ -374,22 +375,23 @@ class LineLength(configRules: List) : DiktatRule( node.appendNewlineMergingWhiteSpace(dot, dot) } + @Suppress("UnsafeCallOnNullableType") private fun fixArgumentsListFirstArgument(wrongArgumentList: ValueArgumentList): Int { val lineLength = wrongArgumentList.maximumLineLength.lineLength val node = wrongArgumentList.node - var offset = 0 + var startOffset = 0 node.getFirstChildWithType(COMMA)?.let { if (positionByOffset(it.startOffset).second > lineLength) { node.appendNewlineMergingWhiteSpace(node.findChildByType(LPAR)!!.treeNext, node.findChildByType(LPAR)!!.treeNext) node.appendNewlineMergingWhiteSpace(node.findChildByType(RPAR), node.findChildByType(RPAR)) - offset = 50 + startOffset = 50 } } ?: node.getFirstChildWithType(RPAR)?.let { node.appendNewlineMergingWhiteSpace(node.findChildByType(LPAR)!!.treeNext, node.findChildByType(LPAR)!!.treeNext) node.appendNewlineMergingWhiteSpace(node.findChildByType(RPAR), node.findChildByType(RPAR)) - offset = 50 + startOffset = 50 } - return offset + return startOffset } /**