From 7edf13b415df6a0ff950ed647925b81ac973c2c6 Mon Sep 17 00:00:00 2001 From: aktsay6 Date: Thu, 4 Feb 2021 15:11:20 +0300 Subject: [PATCH 01/20] bugfix/newlinesrule(#748) ### What's done: * Fixed bug --- .../rules/chapter3/files/NewlinesRule.kt | 38 ++++++++++++++++++- .../chapter3/files/NewlinesRuleWarnTest.kt | 28 ++++++++++++++ 2 files changed, 64 insertions(+), 2 deletions(-) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/NewlinesRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/NewlinesRule.kt index 60d9d0a211..fcd3865a4b 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/NewlinesRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/NewlinesRule.kt @@ -23,6 +23,7 @@ import com.pinterest.ktlint.core.ast.ElementType.COLON import com.pinterest.ktlint.core.ast.ElementType.COLONCOLON import com.pinterest.ktlint.core.ast.ElementType.COMMA import com.pinterest.ktlint.core.ast.ElementType.CONDITION +import com.pinterest.ktlint.core.ast.ElementType.CONSTRUCTOR_CALLEE import com.pinterest.ktlint.core.ast.ElementType.DIV import com.pinterest.ktlint.core.ast.ElementType.DIVEQ import com.pinterest.ktlint.core.ast.ElementType.DOT @@ -58,6 +59,7 @@ import com.pinterest.ktlint.core.ast.ElementType.SAFE_ACCESS import com.pinterest.ktlint.core.ast.ElementType.SAFE_ACCESS_EXPRESSION import com.pinterest.ktlint.core.ast.ElementType.SECONDARY_CONSTRUCTOR import com.pinterest.ktlint.core.ast.ElementType.SEMICOLON +import com.pinterest.ktlint.core.ast.ElementType.SUPER_TYPE_CALL_ENTRY import com.pinterest.ktlint.core.ast.ElementType.SUPER_TYPE_LIST import com.pinterest.ktlint.core.ast.ElementType.VALUE_ARGUMENT import com.pinterest.ktlint.core.ast.ElementType.VALUE_ARGUMENT_LIST @@ -78,6 +80,7 @@ import org.jetbrains.kotlin.com.intellij.psi.tree.TokenSet import org.jetbrains.kotlin.psi.KtBinaryExpression import org.jetbrains.kotlin.psi.KtParameterList import org.jetbrains.kotlin.psi.KtSuperTypeList +import org.jetbrains.kotlin.psi.KtValueArgumentList import org.jetbrains.kotlin.psi.psiUtil.children import org.jetbrains.kotlin.psi.psiUtil.parents import org.jetbrains.kotlin.psi.psiUtil.siblings @@ -117,7 +120,7 @@ class NewlinesRule(private val configRules: List) : Rule("newlines" COMMA -> handleComma(node) BLOCK -> handleLambdaBody(node) RETURN -> handleReturnStatement(node) - SUPER_TYPE_LIST, VALUE_PARAMETER_LIST -> handleList(node) + SUPER_TYPE_LIST, VALUE_PARAMETER_LIST, VALUE_ARGUMENT_LIST -> handleList(node) else -> { } } @@ -314,9 +317,15 @@ class NewlinesRule(private val configRules: List) : Rule("newlines" return } + if (node.elementType == VALUE_ARGUMENT_LIST && node.treePrev.elementType != CONSTRUCTOR_CALLEE) { + // check that it is not listOf(1,2,3...) + return + } + val (numEntries, entryType) = when (node.elementType) { VALUE_PARAMETER_LIST -> (node.psi as KtParameterList).parameters.size to "value parameters" SUPER_TYPE_LIST -> (node.psi as KtSuperTypeList).entries.size to "supertype list entries" + VALUE_ARGUMENT_LIST -> (node.psi as KtValueArgumentList).arguments.size to "value arguments" else -> { log.warn("Unexpected node element type ${node.elementType}") return @@ -325,6 +334,7 @@ class NewlinesRule(private val configRules: List) : Rule("newlines" if (numEntries > configuration.maxParametersInOneLine) { when (node.elementType) { VALUE_PARAMETER_LIST -> handleFirstValueParameter(node) + VALUE_ARGUMENT_LIST -> handleFirstValueArgument(node) else -> { } } @@ -351,6 +361,25 @@ class NewlinesRule(private val configRules: List) : Rule("newlines" } } + private fun handleFirstValueArgument(node: ASTNode) = node + .children() + .takeWhile { !it.textContains('\n') } + .filter { it.elementType == VALUE_ARGUMENT } + .toList() + .takeIf { it.size > 1 } + ?.let { list -> + WRONG_NEWLINES.warnAndFix(configRules, emitWarn, isFixMode, "first value argument (${list.first().text}) should be placed on the new line " + + "or all other parameters should be aligned with it", + node.startOffset, node) { + node.appendNewlineMergingWhiteSpace( + list.first() + .treePrev + .takeIf { it.elementType == WHITE_SPACE }, + list.first() + ) + } + } + private fun handleValueParameterList(node: ASTNode, entryType: String) = node .children() .filter { @@ -360,8 +389,13 @@ class NewlinesRule(private val configRules: List) : Rule("newlines" .toList() .takeIf { it.isNotEmpty() } ?.let { invalidCommas -> + val warnText = if (node.getParentIdentifier() != null) { + "$entryType should be placed on different lines in declaration of <${node.getParentIdentifier()}>" + } else { + "$entryType should be placed on different lines" + } WRONG_NEWLINES.warnAndFix(configRules, emitWarn, isFixMode, - "$entryType should be placed on different lines in declaration of <${node.getParentIdentifier()}>", node.startOffset, node) { + warnText, node.startOffset, node) { invalidCommas.forEach { comma -> val nextWhiteSpace = comma.treeNext.takeIf { it.elementType == WHITE_SPACE } comma.appendNewlineMergingWhiteSpace(nextWhiteSpace, nextWhiteSpace?.treeNext ?: comma.treeNext) diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/files/NewlinesRuleWarnTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/files/NewlinesRuleWarnTest.kt index 61dc547f73..278719cfa1 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/files/NewlinesRuleWarnTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/files/NewlinesRuleWarnTest.kt @@ -643,6 +643,34 @@ class NewlinesRuleWarnTest : LintTestBase(::NewlinesRule) { ) } + @Test + @Tag(WarningNames.WRONG_NEWLINES) + fun `should not raise warning on value arguments`() { + lintMethod( + """ + |class SomeRule(configRules: List) : Rule("id", + |configRules, + |listOf("foo", "baz")) { + | + |} + """.trimMargin() + ) + } + + @Test + @Tag(WarningNames.WRONG_NEWLINES) + fun `should raise warning on value arguments`() { + lintMethod( + """ + |class SomeRule(configRules: List) : Rule("id", configRules, listOf("foo", "baz")) { + | + |} + """.trimMargin(), + LintError(1, 46, ruleId, "${WRONG_NEWLINES.warnText()} first value argument (\"id\") should be placed on the new line or all other parameters should be aligned with it", true), + LintError(1, 46, ruleId, "${WRONG_NEWLINES.warnText()} value arguments should be placed on different lines", true), + ) + } + @Test @Tag(WarningNames.WRONG_NEWLINES) fun `should suggest newlines in a long supertype list`() { From 8a3811dd3e458cf2c87484d3edd191ab7a645bf0 Mon Sep 17 00:00:00 2001 From: aktsay6 Date: Thu, 4 Feb 2021 15:45:25 +0300 Subject: [PATCH 02/20] bugfix/newlinesrule(#748) ### What's done: * Fixed bug --- .../cqfn/diktat/ruleset/rules/chapter3/files/NewlinesRule.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/NewlinesRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/NewlinesRule.kt index 70f258742b..f95f8cc5ed 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/NewlinesRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/NewlinesRule.kt @@ -308,7 +308,7 @@ class NewlinesRule(configRules: List) : DiktatRule("newlines", conf return } - if (node.elementType == VALUE_ARGUMENT_LIST && node.treePrev.elementType != CONSTRUCTOR_CALLEE) { + if (node.elementType == VALUE_ARGUMENT_LIST && !node.hasParent(SUPER_TYPE_LIST)) { // check that it is not listOf(1,2,3...) return } From d0177e4fff9849ffabebc567092a3b77b5b769f9 Mon Sep 17 00:00:00 2001 From: aktsay6 Date: Tue, 9 Feb 2021 12:37:46 +0300 Subject: [PATCH 03/20] bugfix/newlinesrule(#748) ### What's done: * Fixed bugs --- .../rules/chapter3/files/NewlinesRule.kt | 41 ++++++------------- 1 file changed, 13 insertions(+), 28 deletions(-) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/NewlinesRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/NewlinesRule.kt index f95f8cc5ed..a5aa24a4be 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/NewlinesRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/NewlinesRule.kt @@ -22,7 +22,6 @@ import com.pinterest.ktlint.core.ast.ElementType.COLON import com.pinterest.ktlint.core.ast.ElementType.COLONCOLON import com.pinterest.ktlint.core.ast.ElementType.COMMA import com.pinterest.ktlint.core.ast.ElementType.CONDITION -import com.pinterest.ktlint.core.ast.ElementType.CONSTRUCTOR_CALLEE import com.pinterest.ktlint.core.ast.ElementType.DIV import com.pinterest.ktlint.core.ast.ElementType.DIVEQ import com.pinterest.ktlint.core.ast.ElementType.DOT @@ -58,7 +57,6 @@ import com.pinterest.ktlint.core.ast.ElementType.SAFE_ACCESS import com.pinterest.ktlint.core.ast.ElementType.SAFE_ACCESS_EXPRESSION import com.pinterest.ktlint.core.ast.ElementType.SECONDARY_CONSTRUCTOR import com.pinterest.ktlint.core.ast.ElementType.SEMICOLON -import com.pinterest.ktlint.core.ast.ElementType.SUPER_TYPE_CALL_ENTRY import com.pinterest.ktlint.core.ast.ElementType.SUPER_TYPE_LIST import com.pinterest.ktlint.core.ast.ElementType.VALUE_ARGUMENT import com.pinterest.ktlint.core.ast.ElementType.VALUE_ARGUMENT_LIST @@ -309,7 +307,7 @@ class NewlinesRule(configRules: List) : DiktatRule("newlines", conf } if (node.elementType == VALUE_ARGUMENT_LIST && !node.hasParent(SUPER_TYPE_LIST)) { - // check that it is not listOf(1,2,3...) + // check that it is not function invocation, but only supertype constructor calls return } @@ -324,8 +322,10 @@ class NewlinesRule(configRules: List) : DiktatRule("newlines", conf } if (numEntries > configuration.maxParametersInOneLine) { when (node.elementType) { - VALUE_PARAMETER_LIST -> handleFirstValueParameter(node) - VALUE_ARGUMENT_LIST -> handleFirstValueArgument(node) + VALUE_PARAMETER_LIST -> handleFirstValue(node, VALUE_PARAMETER, "first parameter should be placed on a separate line " + + "or all other parameters should be aligned with it in declaration of <${node.getParentIdentifier()}>") + VALUE_ARGUMENT_LIST -> handleFirstValue(node, VALUE_ARGUMENT, "first value argument (%s) should be placed on the new line " + + "or all other parameters should be aligned with it") else -> { } } @@ -334,15 +334,19 @@ class NewlinesRule(configRules: List) : DiktatRule("newlines", conf } } - private fun handleFirstValueParameter(node: ASTNode) = node + private fun handleFirstValue(node: ASTNode, filterType: IElementType, warnText: String) = node .children() .takeWhile { !it.textContains('\n') } - .filter { it.elementType == VALUE_PARAMETER } + .filter { it.elementType == filterType } .toList() .takeIf { it.size > 1 } ?.let { - WRONG_NEWLINES.warnAndFix(configRules, emitWarn, isFixMode, "first parameter should be placed on a separate line " + - "or all other parameters should be aligned with it in declaration of <${node.getParentIdentifier()}>", node.startOffset, node) { + val freeText = if (filterType == VALUE_ARGUMENT) { + warnText.format(it.first().text) + } else { + warnText + } + WRONG_NEWLINES.warnAndFix(configRules, emitWarn, isFixMode, freeText, node.startOffset, node) { node.appendNewlineMergingWhiteSpace( it.first() .treePrev @@ -352,25 +356,6 @@ class NewlinesRule(configRules: List) : DiktatRule("newlines", conf } } - private fun handleFirstValueArgument(node: ASTNode) = node - .children() - .takeWhile { !it.textContains('\n') } - .filter { it.elementType == VALUE_ARGUMENT } - .toList() - .takeIf { it.size > 1 } - ?.let { list -> - WRONG_NEWLINES.warnAndFix(configRules, emitWarn, isFixMode, "first value argument (${list.first().text}) should be placed on the new line " + - "or all other parameters should be aligned with it", - node.startOffset, node) { - node.appendNewlineMergingWhiteSpace( - list.first() - .treePrev - .takeIf { it.elementType == WHITE_SPACE }, - list.first() - ) - } - } - private fun handleValueParameterList(node: ASTNode, entryType: String) = node .children() .filter { From 93a9bc1808c049a831f3f92e28697def96adbac9 Mon Sep 17 00:00:00 2001 From: aktsay6 Date: Tue, 9 Feb 2021 14:23:01 +0300 Subject: [PATCH 04/20] bugfix/newlinesrule(#748) ### What's done: * Fixed bugs --- .../org/cqfn/diktat/ruleset/rules/chapter1/FileNaming.kt | 4 +++- .../diktat/ruleset/rules/chapter1/IdentifierNaming.kt | 4 +++- .../cqfn/diktat/ruleset/rules/chapter1/PackageNaming.kt | 4 +++- .../ruleset/rules/chapter2/comments/CommentsRule.kt | 4 +++- .../ruleset/rules/chapter2/comments/HeaderCommentRule.kt | 8 +++++--- .../ruleset/rules/chapter2/kdoc/CommentsFormatting.kt | 7 ++++--- .../diktat/ruleset/rules/chapter2/kdoc/KdocComments.kt | 7 ++++--- .../diktat/ruleset/rules/chapter2/kdoc/KdocFormatting.kt | 9 +++++---- .../diktat/ruleset/rules/chapter2/kdoc/KdocMethods.kt | 7 ++++--- .../ruleset/rules/chapter3/AnnotationNewLineRule.kt | 4 +++- .../ruleset/rules/chapter3/BlockStructureBraces.kt | 4 +++- .../rules/chapter3/BracesInConditionalsAndLoopsRule.kt | 4 +++- .../rules/chapter3/ClassLikeStructuresOrderRule.kt | 5 +++-- .../ruleset/rules/chapter3/ConsecutiveSpacesRule.kt | 4 +++- .../org/cqfn/diktat/ruleset/rules/chapter3/EmptyBlock.kt | 4 +++- .../cqfn/diktat/ruleset/rules/chapter3/EnumsSeparated.kt | 4 +++- .../org/cqfn/diktat/ruleset/rules/chapter3/LineLength.kt | 4 +++- .../rules/chapter3/LongNumericalValuesSeparatedRule.kt | 4 +++- .../ruleset/rules/chapter3/MultipleModifiersSequence.kt | 4 +++- .../diktat/ruleset/rules/chapter3/NullableTypeRule.kt | 4 +++- .../ruleset/rules/chapter3/SingleLineStatementsRule.kt | 4 +++- .../org/cqfn/diktat/ruleset/rules/chapter3/SortRule.kt | 4 +++- .../ruleset/rules/chapter3/StringConcatenationRule.kt | 4 +++- .../ruleset/rules/chapter3/StringTemplateFormatRule.kt | 5 +++-- .../diktat/ruleset/rules/chapter3/TrailingCommaRule.kt | 4 +++- .../ruleset/rules/chapter3/WhenMustHaveElseRule.kt | 4 +++- .../ruleset/rules/chapter3/files/BlankLinesRule.kt | 4 +++- .../cqfn/diktat/ruleset/rules/chapter3/files/FileSize.kt | 4 +++- .../ruleset/rules/chapter3/files/FileStructureRule.kt | 4 +++- .../ruleset/rules/chapter3/files/IndentationRule.kt | 4 +++- .../diktat/ruleset/rules/chapter3/files/NewlinesRule.kt | 9 +++++++-- .../ruleset/rules/chapter3/files/WhiteSpaceRule.kt | 4 +++- .../rules/chapter3/identifiers/LocalVariablesRule.kt | 4 +++- .../ruleset/rules/chapter4/ImmutableValNoVarRule.kt | 4 +++- .../cqfn/diktat/ruleset/rules/chapter4/NullChecksRule.kt | 4 +++- .../cqfn/diktat/ruleset/rules/chapter4/SmartCastRule.kt | 4 +++- .../cqfn/diktat/ruleset/rules/chapter4/TypeAliasRule.kt | 4 +++- .../rules/chapter4/VariableGenericTypeDeclarationRule.kt | 5 +++-- .../chapter4/calculations/AccurateCalculationsRule.kt | 4 +++- .../diktat/ruleset/rules/chapter5/AsyncAndSyncRule.kt | 4 +++- .../ruleset/rules/chapter5/AvoidNestedFunctionsRule.kt | 4 +++- .../ruleset/rules/chapter5/CheckInverseMethodRule.kt | 4 +++- .../cqfn/diktat/ruleset/rules/chapter5/CustomLabel.kt | 4 +++- .../ruleset/rules/chapter5/FunctionArgumentsSize.kt | 4 +++- .../cqfn/diktat/ruleset/rules/chapter5/FunctionLength.kt | 4 +++- .../diktat/ruleset/rules/chapter5/LambdaLengthRule.kt | 4 +++- .../ruleset/rules/chapter5/LambdaParameterOrder.kt | 4 +++- .../diktat/ruleset/rules/chapter5/NestedFunctionBlock.kt | 4 +++- .../rules/chapter5/OverloadingArgumentsFunction.kt | 5 +++-- .../rules/chapter6/AvoidEmptyPrimaryConstructor.kt | 4 +++- .../diktat/ruleset/rules/chapter6/AvoidUtilityClass.kt | 4 +++- .../ruleset/rules/chapter6/CustomGetterSetterRule.kt | 4 +++- .../rules/chapter6/ExtensionFunctionsSameNameRule.kt | 5 +++-- .../rules/chapter6/ImplicitBackingPropertyRule.kt | 5 +++-- .../ruleset/rules/chapter6/PropertyAccessorFields.kt | 4 +++- .../ruleset/rules/chapter6/TrivialPropertyAccessors.kt | 5 +++-- .../diktat/ruleset/rules/chapter6/UselessSupertype.kt | 4 +++- .../rules/chapter6/classes/AbstractClassesRule.kt | 4 +++- .../rules/chapter6/classes/CompactInitialization.kt | 4 +++- .../ruleset/rules/chapter6/classes/DataClassesRule.kt | 4 +++- .../ruleset/rules/chapter6/classes/InlineClassesRule.kt | 4 +++- .../rules/chapter6/classes/SingleConstructorRule.kt | 4 +++- .../ruleset/rules/chapter6/classes/SingleInitRule.kt | 4 +++- .../rules/chapter6/classes/StatelessClassesRule.kt | 4 +++- .../ruleset/chapter3/files/NewlinesRuleWarnTest.kt | 3 ++- 65 files changed, 205 insertions(+), 84 deletions(-) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter1/FileNaming.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter1/FileNaming.kt index 26fc069de3..a185220471 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter1/FileNaming.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter1/FileNaming.kt @@ -26,7 +26,9 @@ import java.io.File * Aggressive: In case file contains only one class on upper level - it should be named with the same name */ @Suppress("ForbiddenComment") -class FileNaming(configRules: List) : DiktatRule("file-naming", configRules, listOf(FILE_NAME_INCORRECT, FILE_NAME_MATCH_CLASS)) { +class FileNaming(configRules: List) : DiktatRule("file-naming", + configRules, + listOf(FILE_NAME_INCORRECT, FILE_NAME_MATCH_CLASS)) { private lateinit var filePath: String override fun logic(node: ASTNode) { diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter1/IdentifierNaming.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter1/IdentifierNaming.kt index f80c6a6561..ece3047eca 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter1/IdentifierNaming.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter1/IdentifierNaming.kt @@ -79,7 +79,9 @@ import org.jetbrains.kotlin.psi.psiUtil.parents * // FixMe: because it fixes only declaration without the usages */ @Suppress("ForbiddenComment", "MISSING_KDOC_CLASS_ELEMENTS") -class IdentifierNaming(configRules: List) : DiktatRule("identifier-naming", configRules, +class IdentifierNaming(configRules: List) : DiktatRule( + "identifier-naming", + configRules, listOf(BACKTICKS_PROHIBITED, VARIABLE_NAME_INCORRECT, VARIABLE_NAME_INCORRECT_FORMAT, CONSTANT_UPPERCASE, VARIABLE_HAS_PREFIX, CONFUSING_IDENTIFIER_NAMING, GENERIC_NAME, CLASS_NAME_INCORRECT, ENUM_VALUE, EXCEPTION_SUFFIX, FUNCTION_BOOLEAN_PREFIX, FUNCTION_NAME_INCORRECT_CASE, diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter1/PackageNaming.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter1/PackageNaming.kt index 8756f3d898..3c004c8fd2 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter1/PackageNaming.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter1/PackageNaming.kt @@ -33,7 +33,9 @@ import java.util.concurrent.atomic.AtomicInteger * package a.b.c.D -> then class D should be placed in a/b/c/ directories */ @Suppress("ForbiddenComment", "TOO_MANY_LINES_IN_LAMBDA") -class PackageNaming(configRules: List) : DiktatRule("package-naming", configRules, +class PackageNaming(configRules: List) : DiktatRule( + "package-naming", + configRules, listOf(INCORRECT_PACKAGE_SEPARATOR, PACKAGE_NAME_INCORRECT_CASE, PACKAGE_NAME_MISSING, PACKAGE_NAME_INCORRECT_PATH, PACKAGE_NAME_INCORRECT_PREFIX, PACKAGE_NAME_INCORRECT_SYMBOLS)) { private lateinit var domainName: String diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/comments/CommentsRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/comments/CommentsRule.kt index 38d860bcbd..b14603a9fc 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/comments/CommentsRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/comments/CommentsRule.kt @@ -23,7 +23,9 @@ import org.jetbrains.kotlin.resolve.ImportPath * No commented out code is allowed, including imports. */ @Suppress("ForbiddenComment") -class CommentsRule(configRules: List) : DiktatRule("comments", configRules, listOf(COMMENTED_OUT_CODE)) { +class CommentsRule(configRules: List) : DiktatRule("comments", + configRules, + listOf(COMMENTED_OUT_CODE)) { private lateinit var ktPsiFactory: KtPsiFactory override fun logic(node: ASTNode) { diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/comments/HeaderCommentRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/comments/HeaderCommentRule.kt index 05c5a95469..3750e7ed04 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/comments/HeaderCommentRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/comments/HeaderCommentRule.kt @@ -39,9 +39,11 @@ import java.time.LocalDate * 4) Ensure files with many or zero classes have proper description */ @Suppress("ForbiddenComment") -class HeaderCommentRule(configRules: List) : DiktatRule("header-comment", configRules, - listOf(HEADER_MISSING_IN_NON_SINGLE_CLASS_FILE, HEADER_MISSING_OR_WRONG_COPYRIGHT, HEADER_NOT_BEFORE_PACKAGE, - HEADER_NOT_BEFORE_PACKAGE, HEADER_WRONG_FORMAT, WRONG_COPYRIGHT_YEAR)) { +class HeaderCommentRule(configRules: List) : DiktatRule( + "header-comment", + configRules, + listOf(HEADER_MISSING_IN_NON_SINGLE_CLASS_FILE, HEADER_MISSING_OR_WRONG_COPYRIGHT, HEADER_NOT_BEFORE_PACKAGE, + HEADER_NOT_BEFORE_PACKAGE, HEADER_WRONG_FORMAT, WRONG_COPYRIGHT_YEAR)) { override fun logic(node: ASTNode) { if (node.elementType == FILE) { checkCopyright(node) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/kdoc/CommentsFormatting.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/kdoc/CommentsFormatting.kt index cd085de763..1bdef614fb 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/kdoc/CommentsFormatting.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/kdoc/CommentsFormatting.kt @@ -49,9 +49,10 @@ import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.PsiWhiteSpaceImpl * * Leave one single space between the comment on the right side of the code and the code. * * Comments in if else should be inside code blocks. Exception: General if comment */ -class CommentsFormatting(configRules: List) : DiktatRule("kdoc-comments-codeblocks-formatting", configRules, - listOf(COMMENT_WHITE_SPACE, FIRST_COMMENT_NO_SPACES, - IF_ELSE_COMMENTS, WRONG_NEWLINES_AROUND_KDOC)) { +class CommentsFormatting(configRules: List) : DiktatRule("kdoc-comments-codeblocks-formatting", + configRules, + listOf(COMMENT_WHITE_SPACE, FIRST_COMMENT_NO_SPACES, + IF_ELSE_COMMENTS, WRONG_NEWLINES_AROUND_KDOC)) { /** * @param node * @param autoCorrect diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/kdoc/KdocComments.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/kdoc/KdocComments.kt index 8e16f44d0f..d7b3d49e10 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/kdoc/KdocComments.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/kdoc/KdocComments.kt @@ -44,9 +44,10 @@ import org.jetbrains.kotlin.psi.psiUtil.parents * 2) All internal elements in class like class, property or function should be documented with KDoc * 3) All properties declared in the primary constructor are documented using `@property` tag in class KDoc */ -class KdocComments(configRules: List) : DiktatRule("kdoc-comments", configRules, - listOf(KDOC_EXTRA_PROPERTY, KDOC_NO_CONSTRUCTOR_PROPERTY, - KDOC_NO_CONSTRUCTOR_PROPERTY_WITH_COMMENT, MISSING_KDOC_CLASS_ELEMENTS, MISSING_KDOC_TOP_LEVEL)) { +class KdocComments(configRules: List) : DiktatRule("kdoc-comments", + configRules, + listOf(KDOC_EXTRA_PROPERTY, KDOC_NO_CONSTRUCTOR_PROPERTY, + KDOC_NO_CONSTRUCTOR_PROPERTY_WITH_COMMENT, MISSING_KDOC_CLASS_ELEMENTS, MISSING_KDOC_TOP_LEVEL)) { /** * @param node * @param autoCorrect diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/kdoc/KdocFormatting.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/kdoc/KdocFormatting.kt index 5fd4df686b..958914c37e 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/kdoc/KdocFormatting.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/kdoc/KdocFormatting.kt @@ -59,10 +59,11 @@ import java.time.temporal.ChronoField * 7) ensuring @since tag contains only versions and not dates */ @Suppress("ForbiddenComment") -class KdocFormatting(configRules: List) : DiktatRule("kdoc-formatting", configRules, - listOf(KDOC_CONTAINS_DATE_OR_AUTHOR, KDOC_EMPTY_KDOC, KDOC_NEWLINES_BEFORE_BASIC_TAGS, KDOC_NO_DEPRECATED_TAG, - KDOC_NO_EMPTY_TAGS, KDOC_NO_NEWLINES_BETWEEN_BASIC_TAGS, KDOC_NO_NEWLINE_AFTER_SPECIAL_TAGS, - KDOC_WRONG_SPACES_AFTER_TAG, KDOC_WRONG_TAGS_ORDER)) { +class KdocFormatting(configRules: List) : DiktatRule("kdoc-formatting", + configRules, + listOf(KDOC_CONTAINS_DATE_OR_AUTHOR, KDOC_EMPTY_KDOC, KDOC_NEWLINES_BEFORE_BASIC_TAGS, KDOC_NO_DEPRECATED_TAG, + KDOC_NO_EMPTY_TAGS, KDOC_NO_NEWLINES_BETWEEN_BASIC_TAGS, KDOC_NO_NEWLINE_AFTER_SPECIAL_TAGS, + KDOC_WRONG_SPACES_AFTER_TAG, KDOC_WRONG_TAGS_ORDER)) { private val basicTagsList = listOf(KDocKnownTag.PARAM, KDocKnownTag.RETURN, KDocKnownTag.THROWS) private val specialTagNames = setOf("implSpec", "implNote", "apiNote") private var versionRegex: Regex? = null diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/kdoc/KdocMethods.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/kdoc/KdocMethods.kt index 2e13a98b9f..f86f90d7d7 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/kdoc/KdocMethods.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/kdoc/KdocMethods.kt @@ -65,9 +65,10 @@ import org.jetbrains.kotlin.psi.psiUtil.referenceExpression * Currently only `throw` keyword from this methods body is supported for `@throws` check. */ @Suppress("ForbiddenComment") -class KdocMethods(configRules: List) : DiktatRule("kdoc-methods", configRules, - listOf(KDOC_TRIVIAL_KDOC_ON_FUNCTION, KDOC_WITHOUT_PARAM_TAG, KDOC_WITHOUT_RETURN_TAG, - KDOC_WITHOUT_THROWS_TAG, MISSING_KDOC_ON_FUNCTION)) { +class KdocMethods(configRules: List) : DiktatRule("kdoc-methods", + configRules, + listOf(KDOC_TRIVIAL_KDOC_ON_FUNCTION, KDOC_WITHOUT_PARAM_TAG, KDOC_WITHOUT_RETURN_TAG, + KDOC_WITHOUT_THROWS_TAG, MISSING_KDOC_ON_FUNCTION)) { /** * @param node * @param autoCorrect diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/AnnotationNewLineRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/AnnotationNewLineRule.kt index dbd1f16b1a..5a660d8a0a 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/AnnotationNewLineRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/AnnotationNewLineRule.kt @@ -19,7 +19,9 @@ import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.PsiWhiteSpaceImpl /** * This rule makes each annotation applied to a class, method or constructor is on its own line. Except: if first annotation of constructor, class or method */ -class AnnotationNewLineRule(configRules: List) : DiktatRule("annotation-new-line", configRules, listOf(ANNOTATION_NEW_LINE)) { +class AnnotationNewLineRule(configRules: List) : DiktatRule("annotation-new-line", + configRules, + listOf(ANNOTATION_NEW_LINE)) { override fun logic(node: ASTNode) { when (node.elementType) { CLASS, FUN, PRIMARY_CONSTRUCTOR, SECONDARY_CONSTRUCTOR -> checkAnnotation(node) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/BlockStructureBraces.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/BlockStructureBraces.kt index fd1b254786..5b273933fa 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/BlockStructureBraces.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/BlockStructureBraces.kt @@ -49,7 +49,9 @@ import org.jetbrains.kotlin.psi.KtTryExpression * - opening brace of lambda * - braces around `else`/`catch`/`finally`/`while` (in `do-while` loop) */ -class BlockStructureBraces(configRules: List) : DiktatRule("block-structure", configRules, listOf(BRACES_BLOCK_STRUCTURE_ERROR)) { +class BlockStructureBraces(configRules: List) : DiktatRule("block-structure", + configRules, + listOf(BRACES_BLOCK_STRUCTURE_ERROR)) { override fun logic(node: ASTNode) { val configuration = BlockStructureBracesConfiguration( configRules.getRuleConfig(BRACES_BLOCK_STRUCTURE_ERROR)?.configuration ?: emptyMap() diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/BracesInConditionalsAndLoopsRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/BracesInConditionalsAndLoopsRule.kt index d03b9a7dab..5ad157e94b 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/BracesInConditionalsAndLoopsRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/BracesInConditionalsAndLoopsRule.kt @@ -34,7 +34,9 @@ import org.jetbrains.kotlin.psi.psiUtil.astReplace /** * Rule that checks that all conditionals and loops have braces. */ -class BracesInConditionalsAndLoopsRule(configRules: List) : DiktatRule("braces-rule", configRules, listOf(NO_BRACES_IN_CONDITIONALS_AND_LOOPS)) { +class BracesInConditionalsAndLoopsRule(configRules: List) : DiktatRule("braces-rule", + configRules, + listOf(NO_BRACES_IN_CONDITIONALS_AND_LOOPS)) { override fun logic(node: ASTNode) { when (node.elementType) { IF -> checkIfNode(node) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/ClassLikeStructuresOrderRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/ClassLikeStructuresOrderRule.kt index d3ef6941cc..b713bf3dbe 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/ClassLikeStructuresOrderRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/ClassLikeStructuresOrderRule.kt @@ -41,8 +41,9 @@ import org.jetbrains.kotlin.psi.psiUtil.siblings /** * Rule that checks order of declarations inside classes, interfaces and objects. */ -class ClassLikeStructuresOrderRule(configRules: List) : DiktatRule("class-like-structures", configRules, - listOf(BLANK_LINE_BETWEEN_PROPERTIES, WRONG_ORDER_IN_CLASS_LIKE_STRUCTURES)) { +class ClassLikeStructuresOrderRule(configRules: List) : DiktatRule("class-like-structures", + configRules, + listOf(BLANK_LINE_BETWEEN_PROPERTIES, WRONG_ORDER_IN_CLASS_LIKE_STRUCTURES)) { override fun logic(node: ASTNode) { if (node.elementType == CLASS_BODY) { checkDeclarationsOrderInClass(node) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/ConsecutiveSpacesRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/ConsecutiveSpacesRule.kt index caac371b96..59e52e8fd7 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/ConsecutiveSpacesRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/ConsecutiveSpacesRule.kt @@ -20,7 +20,9 @@ import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.LeafElement * 2) If saveInitialFormattingForEnums is true then white spaces in enums will not be affected * */ -class ConsecutiveSpacesRule(configRules: List) : DiktatRule("too-many-spaces", configRules, listOf(TOO_MANY_CONSECUTIVE_SPACES)) { +class ConsecutiveSpacesRule(configRules: List) : DiktatRule("too-many-spaces", + configRules, + listOf(TOO_MANY_CONSECUTIVE_SPACES)) { override fun logic(node: ASTNode) { val configuration = TooManySpacesRuleConfiguration( configRules.getRuleConfig(TOO_MANY_CONSECUTIVE_SPACES)?.configuration ?: emptyMap()) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/EmptyBlock.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/EmptyBlock.kt index 4525e11ea7..182dcceb6c 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/EmptyBlock.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/EmptyBlock.kt @@ -25,7 +25,9 @@ import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.PsiWhiteSpaceImpl /** * Rule that checks if empty code blocks (`{ }`) are used and checks their formatting. */ -class EmptyBlock(configRules: List) : DiktatRule("empty-block-structure", configRules, listOf(EMPTY_BLOCK_STRUCTURE_ERROR)) { +class EmptyBlock(configRules: List) : DiktatRule("empty-block-structure", + configRules, + listOf(EMPTY_BLOCK_STRUCTURE_ERROR)) { override fun logic(node: ASTNode) { val configuration = EmptyBlockStyleConfiguration( configRules.getRuleConfig(EMPTY_BLOCK_STRUCTURE_ERROR)?.configuration ?: emptyMap() diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/EnumsSeparated.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/EnumsSeparated.kt index cbe6e1c8e9..f9e8c06067 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/EnumsSeparated.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/EnumsSeparated.kt @@ -26,7 +26,9 @@ import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.PsiWhiteSpaceImpl /** * Rule that checks enum classes formatting */ -class EnumsSeparated(configRules: List) : DiktatRule("enum-separated", configRules, listOf(ENUMS_SEPARATED)) { +class EnumsSeparated(configRules: List) : DiktatRule("enum-separated", + configRules, + listOf(ENUMS_SEPARATED)) { override fun logic(node: ASTNode) { if (node.elementType == CLASS && node.hasChildOfType(CLASS_BODY)) { if (node.isClassEnum()) { 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 92612f05be..98bc731251 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 @@ -57,7 +57,9 @@ import java.net.URL * Rule can fix long binary expressions in condition inside `if` and in property declarations and one line functions */ @Suppress("ForbiddenComment") -class LineLength(configRules: List) : DiktatRule("line-length", configRules, listOf(LONG_LINE)) { +class LineLength(configRules: List) : DiktatRule("line-length", + configRules, + listOf(LONG_LINE)) { private lateinit var positionByOffset: (Int) -> Pair override fun logic(node: ASTNode) { diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/LongNumericalValuesSeparatedRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/LongNumericalValuesSeparatedRule.kt index 93da60e617..918ff4e0cd 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/LongNumericalValuesSeparatedRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/LongNumericalValuesSeparatedRule.kt @@ -16,7 +16,9 @@ import java.lang.StringBuilder /** * Rule that checks if numerical separators (`_`) are used for long numerical literals */ -class LongNumericalValuesSeparatedRule(configRules: List) : DiktatRule("long-numerical-values", configRules, listOf(LONG_NUMERICAL_VALUES_SEPARATED)) { +class LongNumericalValuesSeparatedRule(configRules: List) : DiktatRule("long-numerical-values", + configRules, + listOf(LONG_NUMERICAL_VALUES_SEPARATED)) { override fun logic(node: ASTNode) { val configuration = LongNumericalValuesConfiguration( configRules.getRuleConfig(LONG_NUMERICAL_VALUES_SEPARATED)?.configuration ?: emptyMap()) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/MultipleModifiersSequence.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/MultipleModifiersSequence.kt index 113c2b9077..b297151af5 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/MultipleModifiersSequence.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/MultipleModifiersSequence.kt @@ -15,7 +15,9 @@ import org.jetbrains.kotlin.psi.psiUtil.children /** * @property configRules */ -class MultipleModifiersSequence(configRules: List) : DiktatRule("multiple-modifiers", configRules, listOf(WRONG_MULTIPLE_MODIFIERS_ORDER)) { +class MultipleModifiersSequence(configRules: List) : DiktatRule("multiple-modifiers", + configRules, + listOf(WRONG_MULTIPLE_MODIFIERS_ORDER)) { override fun logic(node: ASTNode) { if (node.elementType == MODIFIER_LIST) { checkModifierList(node) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/NullableTypeRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/NullableTypeRule.kt index 8215f3b5a5..9d4d3ee0a5 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/NullableTypeRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/NullableTypeRule.kt @@ -37,7 +37,9 @@ import org.jetbrains.kotlin.com.intellij.psi.tree.IElementType /** * Rule that checks if nullable types are used and suggest to substitute them with non-nullable */ -class NullableTypeRule(configRules: List) : DiktatRule("nullable-type", configRules, listOf(NULLABLE_PROPERTY_TYPE)) { +class NullableTypeRule(configRules: List) : DiktatRule("nullable-type", + configRules, + listOf(NULLABLE_PROPERTY_TYPE)) { override fun logic(node: ASTNode) { if (node.elementType == PROPERTY) { checkProperty(node) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/SingleLineStatementsRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/SingleLineStatementsRule.kt index 806dafa989..68de295e38 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/SingleLineStatementsRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/SingleLineStatementsRule.kt @@ -18,7 +18,9 @@ import org.jetbrains.kotlin.com.intellij.psi.tree.TokenSet /** * Rule that looks for multiple statements on a single line separated with a `;` and splits them in multiple lines. */ -class SingleLineStatementsRule(configRules: List) : DiktatRule("statement", configRules, listOf(MORE_THAN_ONE_STATEMENT_PER_LINE)) { +class SingleLineStatementsRule(configRules: List) : DiktatRule("statement", + configRules, + listOf(MORE_THAN_ONE_STATEMENT_PER_LINE)) { override fun logic(node: ASTNode) { checkSemicolon(node) } diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/SortRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/SortRule.kt index 8f9179558f..79a14e61e0 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/SortRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/SortRule.kt @@ -26,7 +26,9 @@ import org.jetbrains.kotlin.psi.KtObjectDeclaration /** * Rule that sorts class properties and enum members alphabetically */ -class SortRule(configRules: List) : DiktatRule("sort-rule", configRules, listOf(WRONG_DECLARATIONS_ORDER)) { +class SortRule(configRules: List) : DiktatRule("sort-rule", + configRules, + listOf(WRONG_DECLARATIONS_ORDER)) { override fun logic(node: ASTNode) { val configuration = SortRuleConfiguration( configRules.getRuleConfig(WRONG_DECLARATIONS_ORDER)?.configuration ?: emptyMap() diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/StringConcatenationRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/StringConcatenationRule.kt index cdd52d046d..7d4d87c9ab 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/StringConcatenationRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/StringConcatenationRule.kt @@ -19,7 +19,9 @@ import org.jetbrains.kotlin.com.intellij.lang.ASTNode * // FixMe: fixes will be added * // FixMe: .toString() method and functions that return strings are not supported */ -class StringConcatenationRule(configRules: List) : DiktatRule("string-concatenation", configRules, listOf(STRING_CONCATENATION)) { +class StringConcatenationRule(configRules: List) : DiktatRule("string-concatenation", + configRules, + listOf(STRING_CONCATENATION)) { override fun logic(node: ASTNode) { if (node.elementType == BINARY_EXPRESSION) { // searching top-level binary expression to detect any operations with "plus" (+) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/StringTemplateFormatRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/StringTemplateFormatRule.kt index 00563eaf29..0f58ea2596 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/StringTemplateFormatRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/StringTemplateFormatRule.kt @@ -28,8 +28,9 @@ import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.LeafPsiElement * * FixMe: The important caveat here: in "$foo" kotlin compiler adds implicit call to foo.toString() in case foo type is not string. */ -class StringTemplateFormatRule(configRules: List) : DiktatRule("string-template-format", configRules, - listOf(STRING_TEMPLATE_CURLY_BRACES, STRING_TEMPLATE_QUOTES)) { +class StringTemplateFormatRule(configRules: List) : DiktatRule("string-template-format", + configRules, + listOf(STRING_TEMPLATE_CURLY_BRACES, STRING_TEMPLATE_QUOTES)) { override fun logic(node: ASTNode) { when (node.elementType) { LONG_STRING_TEMPLATE_ENTRY -> handleLongStringTemplate(node) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/TrailingCommaRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/TrailingCommaRule.kt index 4d2d29c23a..61655aadbd 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/TrailingCommaRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/TrailingCommaRule.kt @@ -49,7 +49,9 @@ import org.jetbrains.kotlin.psi.psiUtil.siblings * [12] Destructuring declarations */ @Suppress("TOO_LONG_FUNCTION") -class TrailingCommaRule(configRules: List) : DiktatRule("trailing-comma", configRules, listOf(TRAILING_COMMA)) { +class TrailingCommaRule(configRules: List) : DiktatRule("trailing-comma", + configRules, + listOf(TRAILING_COMMA)) { private val commonConfig by configRules.getCommonConfiguration() private val trailingConfig = this.configRules.getRuleConfig(TRAILING_COMMA)?.configuration ?: emptyMap() private val configuration by lazy { diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/WhenMustHaveElseRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/WhenMustHaveElseRule.kt index f40c874d7f..fc1f4eac6b 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/WhenMustHaveElseRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/WhenMustHaveElseRule.kt @@ -36,7 +36,9 @@ import org.jetbrains.kotlin.psi.KtWhenExpression * The compiler can issue a warning when it is missing. */ @Suppress("ForbiddenComment") -class WhenMustHaveElseRule(configRules: List) : DiktatRule("no-else-in-when", configRules, listOf(WHEN_WITHOUT_ELSE)) { +class WhenMustHaveElseRule(configRules: List) : DiktatRule("no-else-in-when", + configRules, + listOf(WHEN_WITHOUT_ELSE)) { override fun logic(node: ASTNode) { if (node.elementType == ElementType.WHEN && isStatement(node)) { checkEntries(node) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/BlankLinesRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/BlankLinesRule.kt index 2cd8be0c2e..fb8d84cd91 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/BlankLinesRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/BlankLinesRule.kt @@ -23,7 +23,9 @@ import org.jetbrains.kotlin.com.intellij.lang.ASTNode * 1. Checks that no more than two consecutive blank lines are used in a row * 2. Checks that blank lines are not put in the beginning or at the end of code blocks with curly braces */ -class BlankLinesRule(configRules: List) : DiktatRule("blank-lines", configRules, listOf(TOO_MANY_BLANK_LINES)) { +class BlankLinesRule(configRules: List) : DiktatRule("blank-lines", + configRules, + listOf(TOO_MANY_BLANK_LINES)) { override fun logic(node: ASTNode) { if (node.elementType == WHITE_SPACE) { // note that no blank lines counts as one newline diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/FileSize.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/FileSize.kt index e9d8086b2b..64cc8b4279 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/FileSize.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/FileSize.kt @@ -15,7 +15,9 @@ import org.slf4j.LoggerFactory /** * Rule that checks number of lines in a file */ -class FileSize(configRules: List) : DiktatRule("file-size", configRules, listOf(FILE_IS_TOO_LONG)) { +class FileSize(configRules: List) : DiktatRule("file-size", + configRules, + listOf(FILE_IS_TOO_LONG)) { private val configuration by lazy { FileSizeConfiguration( this.configRules.getRuleConfig(FILE_IS_TOO_LONG)?.configuration ?: emptyMap() diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/FileStructureRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/FileStructureRule.kt index 76ec154d8f..bbd4fc95d0 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/FileStructureRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/FileStructureRule.kt @@ -55,7 +55,9 @@ import org.jetbrains.kotlin.psi.psiUtil.siblings * 4. Ensures imports are ordered alphabetically without blank lines * 5. Ensures there are no wildcard imports */ -class FileStructureRule(configRules: List) : DiktatRule("file-structure", configRules, +class FileStructureRule(configRules: List) : DiktatRule( + "file-structure", + configRules, listOf(FILE_CONTAINS_ONLY_COMMENTS, FILE_INCORRECT_BLOCKS_ORDER, FILE_NO_BLANK_LINE_BETWEEN_BLOCKS, FILE_UNORDERED_IMPORTS, FILE_WILDCARD_IMPORTS, UNUSED_IMPORT)) { private val domainName by lazy { diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/IndentationRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/IndentationRule.kt index 79a3aac6cc..a8a4e65baf 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/IndentationRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/IndentationRule.kt @@ -64,7 +64,9 @@ import org.jetbrains.kotlin.utils.addToStdlib.firstNotNullResult * Additionally, a set of CustomIndentationChecker objects checks all WHITE_SPACE node if they are exceptions from general rules. * @see CustomIndentationChecker */ -class IndentationRule(configRules: List) : DiktatRule("indentation", configRules, listOf(WRONG_INDENTATION)) { +class IndentationRule(configRules: List) : DiktatRule("indentation", + configRules, + listOf(WRONG_INDENTATION)) { private val configuration: IndentationConfig by lazy { IndentationConfig(configRules.getRuleConfig(WRONG_INDENTATION)?.configuration ?: emptyMap()) } diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/NewlinesRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/NewlinesRule.kt index a5aa24a4be..0061c69f30 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/NewlinesRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/NewlinesRule.kt @@ -96,7 +96,9 @@ import org.jetbrains.kotlin.psi.psiUtil.siblings * 10. Complex expression inside condition replaced with new variable */ @Suppress("ForbiddenComment") -class NewlinesRule(configRules: List) : DiktatRule("newlines", configRules, listOf(COMPLEX_EXPRESSION, REDUNDANT_SEMICOLON, WRONG_NEWLINES)) { +class NewlinesRule(configRules: List) : DiktatRule("newlines", + configRules, + listOf(COMPLEX_EXPRESSION, REDUNDANT_SEMICOLON, WRONG_NEWLINES)) { private val configuration by lazy { NewlinesRuleConfiguration(configRules.getRuleConfig(WRONG_NEWLINES)?.configuration ?: emptyMap()) } @@ -300,6 +302,7 @@ class NewlinesRule(configRules: List) : DiktatRule("newlines", conf * Checks that members of [VALUE_PARAMETER_LIST] (list of function parameters at declaration site) are separated with newlines. * Also checks that entries of [SUPER_TYPE_LIST] are separated by newlines. */ + @Suppress("ComplexMethod") private fun handleList(node: ASTNode) { if (node.elementType == VALUE_PARAMETER_LIST && node.treeParent.elementType.let { it == FUNCTION_TYPE || it == FUNCTION_TYPE_RECEIVER }) { // do not check other value lists @@ -334,7 +337,9 @@ class NewlinesRule(configRules: List) : DiktatRule("newlines", conf } } - private fun handleFirstValue(node: ASTNode, filterType: IElementType, warnText: String) = node + private fun handleFirstValue(node: ASTNode, + filterType: IElementType, + warnText: String) = node .children() .takeWhile { !it.textContains('\n') } .filter { it.elementType == filterType } diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/WhiteSpaceRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/WhiteSpaceRule.kt index b05694f620..20b5d819ed 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/WhiteSpaceRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/WhiteSpaceRule.kt @@ -92,7 +92,9 @@ import org.jetbrains.kotlin.psi.psiUtil.parentsWithSelf * 10. There should be no spaces between prefix/postfix operator (like `!!` or `++`) and it's operand */ @Suppress("ForbiddenComment") -class WhiteSpaceRule(configRules: List) : DiktatRule("horizontal-whitespace", configRules, listOf(WRONG_WHITESPACE)) { +class WhiteSpaceRule(configRules: List) : DiktatRule("horizontal-whitespace", + configRules, + listOf(WRONG_WHITESPACE)) { @Suppress("ComplexMethod") override fun logic(node: ASTNode) { when (node.elementType) { diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/identifiers/LocalVariablesRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/identifiers/LocalVariablesRule.kt index 6f5c2880c9..a7614e0d2a 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/identifiers/LocalVariablesRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/identifiers/LocalVariablesRule.kt @@ -37,7 +37,9 @@ import org.jetbrains.kotlin.psi.psiUtil.startOffset * * Only properties without initialization or initialized with expressions based on constants are supported. * * Properties initialized with constructor calls cannot be distinguished from method call and are no supported. */ -class LocalVariablesRule(configRules: List) : DiktatRule("local-variables", configRules, listOf(LOCAL_VARIABLE_EARLY_DECLARATION)) { +class LocalVariablesRule(configRules: List) : DiktatRule("local-variables", + configRules, + listOf(LOCAL_VARIABLE_EARLY_DECLARATION)) { override fun logic(node: ASTNode) { if (node.elementType == FILE) { // collect all local properties and associate with corresponding references diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/ImmutableValNoVarRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/ImmutableValNoVarRule.kt index 1c1c41889b..9f4224e027 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/ImmutableValNoVarRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/ImmutableValNoVarRule.kt @@ -19,7 +19,9 @@ import org.jetbrains.kotlin.psi.psiUtil.getParentOfType * because `var` variables can be reassigned several times in the business logic. Of course, in some scenarios with loops or accumulators only `var`s can be used and are allowed. * FixMe: here we should also raise warnings for a reassignment of a var (if var has no assignments except in declaration - it can be final) */ -class ImmutableValNoVarRule(configRules: List) : DiktatRule("no-var-rule", configRules, listOf(SAY_NO_TO_VAR)) { +class ImmutableValNoVarRule(configRules: List) : DiktatRule("no-var-rule", + configRules, + listOf(SAY_NO_TO_VAR)) { override fun logic(node: ASTNode) { if (node.elementType == ElementType.FILE) { // we will raise warning for cases when var property has no assignments diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/NullChecksRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/NullChecksRule.kt index 366cff96d0..7ec37c0081 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/NullChecksRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/NullChecksRule.kt @@ -26,7 +26,9 @@ import org.jetbrains.kotlin.psi.KtIfExpression * This rule check and fixes explicit null checks (explicit comparison with `null`) * There are several code-structures that can be used in Kotlin to avoid null-checks. For example: `?:`, `.let {}`, `.also {}`, e.t.c */ -class NullChecksRule(configRules: List) : DiktatRule("null-checks", configRules, listOf(AVOID_NULL_CHECKS)) { +class NullChecksRule(configRules: List) : DiktatRule("null-checks", + configRules, + listOf(AVOID_NULL_CHECKS)) { override fun logic(node: ASTNode) { if (node.elementType == CONDITION) { node.parent(IF)?.let { diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/SmartCastRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/SmartCastRule.kt index 45bbe16327..0ac6f37297 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/SmartCastRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/SmartCastRule.kt @@ -39,7 +39,9 @@ import org.jetbrains.kotlin.psi.psiUtil.parents /** * Rule that detects redundant explicit casts */ -class SmartCastRule(configRules: List) : DiktatRule("smart-cast-rule", configRules, listOf(SMART_CAST_NEEDED)) { +class SmartCastRule(configRules: List) : DiktatRule("smart-cast-rule", + configRules, + listOf(SMART_CAST_NEEDED)) { override fun logic(node: ASTNode) { if (node.elementType == FILE) { val usages = collectLocalPropertiesWithUsages(node) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/TypeAliasRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/TypeAliasRule.kt index 41e46615b6..b78345199b 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/TypeAliasRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/TypeAliasRule.kt @@ -19,7 +19,9 @@ import org.jetbrains.kotlin.psi.psiUtil.parents * This rule checks if variable has long type reference and two or more nested generics. * Length type reference can be configured */ -class TypeAliasRule(configRules: List) : DiktatRule("type-alias", configRules, listOf(TYPE_ALIAS)) { +class TypeAliasRule(configRules: List) : DiktatRule("type-alias", + configRules, + listOf(TYPE_ALIAS)) { override fun logic(node: ASTNode) { if (node.elementType == TYPE_REFERENCE && node .parents() diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/VariableGenericTypeDeclarationRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/VariableGenericTypeDeclarationRule.kt index 07a24644c7..ffe64a981d 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/VariableGenericTypeDeclarationRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/VariableGenericTypeDeclarationRule.kt @@ -21,8 +21,9 @@ import org.jetbrains.kotlin.psi.KtProperty * Recommended: val myVariable: Map = emptyMap() */ // FIXME: we now don't have access to return types, so we can perform this check only if explicit type is present, but should be able also if it's not. -class VariableGenericTypeDeclarationRule(configRules: List) : DiktatRule("variable-generic-type", configRules, - listOf(GENERIC_VARIABLE_WRONG_DECLARATION)) { +class VariableGenericTypeDeclarationRule(configRules: List) : DiktatRule("variable-generic-type", + configRules, + listOf(GENERIC_VARIABLE_WRONG_DECLARATION)) { override fun logic(node: ASTNode) { when (node.elementType) { PROPERTY, VALUE_PARAMETER -> handleProperty(node) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/calculations/AccurateCalculationsRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/calculations/AccurateCalculationsRule.kt index cb40295a68..419a1352d2 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/calculations/AccurateCalculationsRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/calculations/AccurateCalculationsRule.kt @@ -24,7 +24,9 @@ import org.jetbrains.kotlin.psi.psiUtil.startOffset * Exception: allows arithmetic operations only when absolute value of result is immediately used in comparison * Fixme: detect variables by type, not only floating-point literals */ -class AccurateCalculationsRule(configRules: List) : DiktatRule("accurate-calculations", configRules, listOf(FLOAT_IN_ACCURATE_CALCULATIONS)) { +class AccurateCalculationsRule(configRules: List) : DiktatRule("accurate-calculations", + configRules, + listOf(FLOAT_IN_ACCURATE_CALCULATIONS)) { private fun KtCallExpression?.isAbsOfFloat() = this ?.run { (calleeExpression as? KtNameReferenceExpression) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/AsyncAndSyncRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/AsyncAndSyncRule.kt index 927b6fb637..5f26d774d3 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/AsyncAndSyncRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/AsyncAndSyncRule.kt @@ -17,7 +17,9 @@ import org.jetbrains.kotlin.psi.psiUtil.hasSuspendModifier /** * This rule finds if using runBlocking in asynchronous code */ -class AsyncAndSyncRule(configRules: List) : DiktatRule("sync-in-async", configRules, listOf(RUN_BLOCKING_INSIDE_ASYNC)) { +class AsyncAndSyncRule(configRules: List) : DiktatRule("sync-in-async", + configRules, + listOf(RUN_BLOCKING_INSIDE_ASYNC)) { private val asyncList = listOf("async", "launch") override fun logic(node: ASTNode) { diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/AvoidNestedFunctionsRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/AvoidNestedFunctionsRule.kt index e597764640..4faf8c6052 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/AvoidNestedFunctionsRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/AvoidNestedFunctionsRule.kt @@ -24,7 +24,9 @@ import org.jetbrains.kotlin.psi.psiUtil.parents /** * This rule checks for nested functions and warns if it finds any. */ -class AvoidNestedFunctionsRule(configRules: List) : DiktatRule("avoid-nested-functions", configRules, listOf(AVOID_NESTED_FUNCTIONS)) { +class AvoidNestedFunctionsRule(configRules: List) : DiktatRule("avoid-nested-functions", + configRules, + listOf(AVOID_NESTED_FUNCTIONS)) { override fun logic(node: ASTNode) { if (node.elementType == FUN) { handleNestedFunctions(node) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/CheckInverseMethodRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/CheckInverseMethodRule.kt index 8c92f48a18..7837f7f803 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/CheckInverseMethodRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/CheckInverseMethodRule.kt @@ -22,7 +22,9 @@ import org.jetbrains.kotlin.psi.psiUtil.siblings * This rule checks if inverse method can be used. * For example if there is !isEmpty() on collection call that it changes it to isNotEmpty() */ -class CheckInverseMethodRule(configRules: List) : DiktatRule("inverse-method", configRules, listOf(INVERSE_FUNCTION_PREFERRED)) { +class CheckInverseMethodRule(configRules: List) : DiktatRule("inverse-method", + configRules, + listOf(INVERSE_FUNCTION_PREFERRED)) { override fun logic(node: ASTNode) { if (node.elementType == CALL_EXPRESSION && node.text in methodMap.keys) { checkCallExpressionName(node) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/CustomLabel.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/CustomLabel.kt index 518040b1b3..b802b872f2 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/CustomLabel.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/CustomLabel.kt @@ -17,7 +17,9 @@ import org.jetbrains.kotlin.psi.psiUtil.parents /** * Rule that checks using custom label */ -class CustomLabel(configRules: List) : DiktatRule("custom-label", configRules, listOf(CUSTOM_LABEL)) { +class CustomLabel(configRules: List) : DiktatRule("custom-label", + configRules, + listOf(CUSTOM_LABEL)) { private val forEachReference = listOf("forEach", "forEachIndexed") private val labels = listOf("@loop", "@forEach", "@forEachIndexed") private val stopWords = listOf(RETURN, BREAK, CONTINUE) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/FunctionArgumentsSize.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/FunctionArgumentsSize.kt index 5f07f8a9f2..1f664a2e8b 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/FunctionArgumentsSize.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/FunctionArgumentsSize.kt @@ -14,7 +14,9 @@ import org.jetbrains.kotlin.psi.KtFunction /** * Rule that checks that function doesn't contains too many parameters */ -class FunctionArgumentsSize(configRules: List) : DiktatRule("argument-size", configRules, listOf(TOO_MANY_PARAMETERS)) { +class FunctionArgumentsSize(configRules: List) : DiktatRule("argument-size", + configRules, + listOf(TOO_MANY_PARAMETERS)) { private val configuration: FunctionArgumentsSizeConfiguration by lazy { FunctionArgumentsSizeConfiguration(configRules.getRuleConfig(TOO_MANY_PARAMETERS)?.configuration ?: emptyMap()) } diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/FunctionLength.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/FunctionLength.kt index 670fef2377..82b818776f 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/FunctionLength.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/FunctionLength.kt @@ -14,7 +14,9 @@ import org.jetbrains.kotlin.psi.KtFunction /** * Rule 5.1.1 check function length */ -class FunctionLength(configRules: List) : DiktatRule("function-length", configRules, listOf(TOO_LONG_FUNCTION)) { +class FunctionLength(configRules: List) : DiktatRule("function-length", + configRules, + listOf(TOO_LONG_FUNCTION)) { override fun logic(node: ASTNode) { val configuration = FunctionLengthConfiguration( configRules.getRuleConfig(TOO_LONG_FUNCTION)?.configuration ?: emptyMap() diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/LambdaLengthRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/LambdaLengthRule.kt index f231535a74..e7f69655b6 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/LambdaLengthRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/LambdaLengthRule.kt @@ -13,7 +13,9 @@ import org.jetbrains.kotlin.com.intellij.lang.ASTNode /** * Rule 5.2.5 check lambda length without parameters */ -class LambdaLengthRule(configRules: List) : DiktatRule("lambda-length", configRules, listOf(TOO_MANY_LINES_IN_LAMBDA)) { +class LambdaLengthRule(configRules: List) : DiktatRule("lambda-length", + configRules, + listOf(TOO_MANY_LINES_IN_LAMBDA)) { private val configuration by lazy { LambdaLengthConfiguration( this.configRules.getRuleConfig(TOO_MANY_LINES_IN_LAMBDA)?.configuration ?: emptyMap() diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/LambdaParameterOrder.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/LambdaParameterOrder.kt index 28bf1a9082..e1b9da0c49 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/LambdaParameterOrder.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/LambdaParameterOrder.kt @@ -15,7 +15,9 @@ import org.jetbrains.kotlin.utils.addToStdlib.ifNotEmpty /** * Rule that checks if parameter with function type is the last in parameter list */ -class LambdaParameterOrder(configRules: List) : DiktatRule("lambda-parameter-order", configRules, listOf(LAMBDA_IS_NOT_LAST_PARAMETER)) { +class LambdaParameterOrder(configRules: List) : DiktatRule("lambda-parameter-order", + configRules, + listOf(LAMBDA_IS_NOT_LAST_PARAMETER)) { override fun logic(node: ASTNode) { if (node.elementType == ElementType.FUN) { checkArguments(node) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/NestedFunctionBlock.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/NestedFunctionBlock.kt index dc537c668a..dcdd5d127b 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/NestedFunctionBlock.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/NestedFunctionBlock.kt @@ -20,7 +20,9 @@ import org.jetbrains.kotlin.psi.psiUtil.parents /** * Rule 5.1.2 Nested blokcs */ -class NestedFunctionBlock(configRules: List) : DiktatRule("nested-block", configRules, listOf(NESTED_BLOCK)) { +class NestedFunctionBlock(configRules: List) : DiktatRule("nested-block", + configRules, + listOf(NESTED_BLOCK)) { private val configuration: NestedBlockConfiguration by lazy { NestedBlockConfiguration(configRules.getRuleConfig(NESTED_BLOCK)?.configuration ?: emptyMap()) } diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/OverloadingArgumentsFunction.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/OverloadingArgumentsFunction.kt index 632db0609e..b4de0ca7d2 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/OverloadingArgumentsFunction.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/OverloadingArgumentsFunction.kt @@ -17,8 +17,9 @@ import org.jetbrains.kotlin.psi.psiUtil.startOffset /** * Rule that suggests to use functions with default parameters instead of multiple overloads */ -class OverloadingArgumentsFunction(configRules: List) : DiktatRule("overloading-default-values", configRules, - listOf(WRONG_OVERLOADING_FUNCTION_ARGUMENTS)) { +class OverloadingArgumentsFunction(configRules: List) : DiktatRule("overloading-default-values", + configRules, + listOf(WRONG_OVERLOADING_FUNCTION_ARGUMENTS)) { override fun logic(node: ASTNode) { if (node.elementType == FUN) { checkFun(node.psi as KtFunction) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/AvoidEmptyPrimaryConstructor.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/AvoidEmptyPrimaryConstructor.kt index d90f3ae304..5556325d7d 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/AvoidEmptyPrimaryConstructor.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/AvoidEmptyPrimaryConstructor.kt @@ -11,7 +11,9 @@ import org.jetbrains.kotlin.psi.KtClass /** * This rule checks if a class has an empty primary constructor. */ -class AvoidEmptyPrimaryConstructor(configRules: List) : DiktatRule("avoid-empty-primary-constructor", configRules, listOf(EMPTY_PRIMARY_CONSTRUCTOR)) { +class AvoidEmptyPrimaryConstructor(configRules: List) : DiktatRule("avoid-empty-primary-constructor", + configRules, + listOf(EMPTY_PRIMARY_CONSTRUCTOR)) { override fun logic(node: ASTNode) { if (node.elementType == CLASS) { checkClass(node.psi as KtClass) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/AvoidUtilityClass.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/AvoidUtilityClass.kt index 79635772ae..373f091610 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/AvoidUtilityClass.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/AvoidUtilityClass.kt @@ -24,7 +24,9 @@ import org.jetbrains.kotlin.psi.psiUtil.children /** * Rule 6.4.1 checks that class/object, with a word "util" in its name, has only functions. */ -class AvoidUtilityClass(configRules: List) : DiktatRule("avoid-utility-class", configRules, listOf(AVOID_USING_UTILITY_CLASS)) { +class AvoidUtilityClass(configRules: List) : DiktatRule("avoid-utility-class", + configRules, + listOf(AVOID_USING_UTILITY_CLASS)) { override fun logic(node: ASTNode) { val config by configRules.getCommonConfiguration() val filePath = node.getRootNode().getFilePath() diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/CustomGetterSetterRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/CustomGetterSetterRule.kt index 9002f51737..915bb4e923 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/CustomGetterSetterRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/CustomGetterSetterRule.kt @@ -15,7 +15,9 @@ import org.jetbrains.kotlin.com.intellij.lang.ASTNode /** * Inspection that checks that no custom getters and setters are used for properties. */ -class CustomGetterSetterRule(configRules: List) : DiktatRule("custom-getter-setter", configRules, listOf(CUSTOM_GETTERS_SETTERS)) { +class CustomGetterSetterRule(configRules: List) : DiktatRule("custom-getter-setter", + configRules, + listOf(CUSTOM_GETTERS_SETTERS)) { override fun logic(node: ASTNode) { if (node.elementType == PROPERTY_ACCESSOR) { checkForCustomGetersSetters(node) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/ExtensionFunctionsSameNameRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/ExtensionFunctionsSameNameRule.kt index 58e4ea2f72..fb58dffbf1 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/ExtensionFunctionsSameNameRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/ExtensionFunctionsSameNameRule.kt @@ -32,8 +32,9 @@ internal typealias SimilarSignatures = List) : DiktatRule("extension-functions-same-name", configRules, - listOf(EXTENSION_FUNCTION_SAME_SIGNATURE)) { +class ExtensionFunctionsSameNameRule(configRules: List) : DiktatRule("extension-functions-same-name", + configRules, + listOf(EXTENSION_FUNCTION_SAME_SIGNATURE)) { override fun logic(node: ASTNode) { /** * 1) Collect all classes that extend other classes (collect related classes) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/ImplicitBackingPropertyRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/ImplicitBackingPropertyRule.kt index be46671279..aad40ca892 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/ImplicitBackingPropertyRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/ImplicitBackingPropertyRule.kt @@ -24,8 +24,9 @@ import org.jetbrains.kotlin.psi.KtProperty /** * This rule checks if there is a backing property for field with property accessors, in case they don't use field keyword */ -class ImplicitBackingPropertyRule(configRules: List) : DiktatRule("implicit-backing-property", configRules, - listOf(NO_CORRESPONDING_PROPERTY)) { +class ImplicitBackingPropertyRule(configRules: List) : DiktatRule("implicit-backing-property", + configRules, + listOf(NO_CORRESPONDING_PROPERTY)) { override fun logic(node: ASTNode) { if (node.elementType == CLASS_BODY) { findAllProperties(node) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/PropertyAccessorFields.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/PropertyAccessorFields.kt index cdd75f4376..d50b49f1c8 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/PropertyAccessorFields.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/PropertyAccessorFields.kt @@ -20,7 +20,9 @@ import org.jetbrains.kotlin.psi.KtProperty /** * Rule check that never use the name of a variable in the custom getter or setter */ -class PropertyAccessorFields(configRules: List) : DiktatRule("getter-setter-fields", configRules, listOf(WRONG_NAME_OF_VARIABLE_INSIDE_ACCESSOR)) { +class PropertyAccessorFields(configRules: List) : DiktatRule("getter-setter-fields", + configRules, + listOf(WRONG_NAME_OF_VARIABLE_INSIDE_ACCESSOR)) { override fun logic(node: ASTNode) { if (node.elementType == PROPERTY_ACCESSOR) { checkPropertyAccessor(node) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/TrivialPropertyAccessors.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/TrivialPropertyAccessors.kt index c2c821a9c1..0734c192ef 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/TrivialPropertyAccessors.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/TrivialPropertyAccessors.kt @@ -26,8 +26,9 @@ import org.jetbrains.kotlin.psi.KtPropertyAccessor /** * This rule checks if there are any trivial getters and setters and, if so, deletes them */ -class TrivialPropertyAccessors(configRules: List) : DiktatRule("trivial-property-accessors", configRules, - listOf(TRIVIAL_ACCESSORS_ARE_NOT_RECOMMENDED)) { +class TrivialPropertyAccessors(configRules: List) : DiktatRule("trivial-property-accessors", + configRules, + listOf(TRIVIAL_ACCESSORS_ARE_NOT_RECOMMENDED)) { override fun logic(node: ASTNode) { if (node.elementType == PROPERTY_ACCESSOR) { handlePropertyAccessors(node) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/UselessSupertype.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/UselessSupertype.kt index c740b623aa..27ec53d0bc 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/UselessSupertype.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/UselessSupertype.kt @@ -31,7 +31,9 @@ import java.util.HashMap * Explicit supertype qualification should not be used if there is not clash between called methods * fixme can't fix supertypes that are defined in other files. */ -class UselessSupertype(configRules: List) : DiktatRule("useless-override", configRules, listOf(USELESS_SUPERTYPE)) { +class UselessSupertype(configRules: List) : DiktatRule("useless-override", + configRules, + listOf(USELESS_SUPERTYPE)) { override fun logic(node: ASTNode) { if (node.elementType == CLASS) { checkClass(node) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/AbstractClassesRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/AbstractClassesRule.kt index 4755f42b55..256f4b6cf4 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/AbstractClassesRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/AbstractClassesRule.kt @@ -19,7 +19,9 @@ import org.jetbrains.kotlin.com.intellij.lang.ASTNode /** * Checks if abstract class has any abstract method. If not, warns that class should not be abstract */ -class AbstractClassesRule(configRules: List) : DiktatRule("abstract-classes", configRules, listOf(CLASS_SHOULD_NOT_BE_ABSTRACT)) { +class AbstractClassesRule(configRules: List) : DiktatRule("abstract-classes", + configRules, + listOf(CLASS_SHOULD_NOT_BE_ABSTRACT)) { override fun logic(node: ASTNode) { if (node.elementType == CLASS) { val classBody = node.getFirstChildWithType(CLASS_BODY) ?: return diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/CompactInitialization.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/CompactInitialization.kt index 807459f103..9e1a70dd6f 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/CompactInitialization.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/CompactInitialization.kt @@ -27,7 +27,9 @@ import org.jetbrains.kotlin.psi.psiUtil.startOffset * FixMe: When assigned variable's name is also a `this@apply`'s property, it should be changed to qualified name, * e.g `this@Foo`. But for this we need a mechanism to determine declaration scope and it's label. */ -class CompactInitialization(configRules: List) : DiktatRule("class-compact-initialization", configRules, listOf(COMPACT_OBJECT_INITIALIZATION)) { +class CompactInitialization(configRules: List) : DiktatRule("class-compact-initialization", + configRules, + listOf(COMPACT_OBJECT_INITIALIZATION)) { private val kotlinParser by lazy { KotlinParser() } override fun logic(node: ASTNode) { diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/DataClassesRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/DataClassesRule.kt index f89eb1239b..3215b5a025 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/DataClassesRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/DataClassesRule.kt @@ -31,7 +31,9 @@ import org.jetbrains.kotlin.psi.KtPrimaryConstructor /** * This rule checks if class can be made as data class */ -class DataClassesRule(configRules: List) : DiktatRule("data-classes", configRules, listOf(USE_DATA_CLASS)) { +class DataClassesRule(configRules: List) : DiktatRule("data-classes", + configRules, + listOf(USE_DATA_CLASS)) { override fun logic(node: ASTNode) { if (node.elementType == CLASS) { handleClass(node) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/InlineClassesRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/InlineClassesRule.kt index 1665c8481e..4ef24b9215 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/InlineClassesRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/InlineClassesRule.kt @@ -25,7 +25,9 @@ import org.jetbrains.kotlin.psi.psiUtil.visibilityModifierType /** * This rule checks if inline class can be used. */ -class InlineClassesRule(configRules: List) : DiktatRule("inline-classes", configRules, listOf(INLINE_CLASS_CAN_BE_USED)) { +class InlineClassesRule(configRules: List) : DiktatRule("inline-classes", + configRules, + listOf(INLINE_CLASS_CAN_BE_USED)) { override fun logic(node: ASTNode) { val configuration by configRules.getCommonConfiguration() if (node.elementType == CLASS && configuration.kotlinVersion >= ktVersion) { diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/SingleConstructorRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/SingleConstructorRule.kt index 802c2fde9c..0c308d6c0c 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/SingleConstructorRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/SingleConstructorRule.kt @@ -33,7 +33,9 @@ import org.jetbrains.kotlin.psi.psiUtil.collectDescendantsOfType * This rule ensures that if a class has a single constructor, this constructor is primary. * Secondary constructor is converted into primary, statements that are not assignments are moved into an `init` block. */ -class SingleConstructorRule(configRules: List) : DiktatRule("single-constructor", configRules, listOf(SINGLE_CONSTRUCTOR_SHOULD_BE_PRIMARY)) { +class SingleConstructorRule(configRules: List) : DiktatRule("single-constructor", + configRules, + listOf(SINGLE_CONSTRUCTOR_SHOULD_BE_PRIMARY)) { private val kotlinParser by lazy { KotlinParser() } override fun logic(node: ASTNode) { diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/SingleInitRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/SingleInitRule.kt index eaa56a3620..843250bce7 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/SingleInitRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/SingleInitRule.kt @@ -25,7 +25,9 @@ import org.jetbrains.kotlin.psi.psiUtil.children /** * The rule that checks whether a class has a single `init` block or multiple. Having multiple `init` blocks is a bad practice. */ -class SingleInitRule(configRules: List) : DiktatRule("multiple-init-block", configRules, listOf(MULTIPLE_INIT_BLOCKS)) { +class SingleInitRule(configRules: List) : DiktatRule("multiple-init-block", + configRules, + listOf(MULTIPLE_INIT_BLOCKS)) { override fun logic(node: ASTNode) { when (node.elementType) { CLASS_BODY -> handleInitBlocks(node) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/StatelessClassesRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/StatelessClassesRule.kt index 7ed2903736..daded79ffd 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/StatelessClassesRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/StatelessClassesRule.kt @@ -27,7 +27,9 @@ import org.jetbrains.kotlin.psi.KtClass /** * This rule checks if class is stateless and if so changes it to object. */ -class StatelessClassesRule(configRules: List) : DiktatRule("stateless-class", configRules, listOf(OBJECT_IS_PREFERRED)) { +class StatelessClassesRule(configRules: List) : DiktatRule("stateless-class", + configRules, + listOf(OBJECT_IS_PREFERRED)) { override fun logic(node: ASTNode) { // Fixme: We should find interfaces in all project and then check them if (node.elementType == FILE) { diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/files/NewlinesRuleWarnTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/files/NewlinesRuleWarnTest.kt index 278719cfa1..153b55c392 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/files/NewlinesRuleWarnTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/files/NewlinesRuleWarnTest.kt @@ -666,7 +666,8 @@ class NewlinesRuleWarnTest : LintTestBase(::NewlinesRule) { | |} """.trimMargin(), - LintError(1, 46, ruleId, "${WRONG_NEWLINES.warnText()} first value argument (\"id\") should be placed on the new line or all other parameters should be aligned with it", true), + LintError(1, 46, ruleId, "${WRONG_NEWLINES.warnText()} first value argument (\"id\") should be placed on the new line or " + + "all other parameters should be aligned with it", true), LintError(1, 46, ruleId, "${WRONG_NEWLINES.warnText()} value arguments should be placed on different lines", true), ) } From 7e84d8351671a40d9caccf78fa74de4c34c65e6f Mon Sep 17 00:00:00 2001 From: aktsay6 Date: Tue, 9 Feb 2021 14:40:32 +0300 Subject: [PATCH 05/20] bugfix/newlinesrule(#748) ### What's done: * Fixed bugs --- .../cqfn/diktat/ruleset/rules/chapter1/FileNaming.kt | 7 ++++--- .../ruleset/rules/chapter2/comments/CommentsRule.kt | 7 ++++--- .../rules/chapter2/comments/HeaderCommentRule.kt | 4 ++-- .../ruleset/rules/chapter2/kdoc/CommentsFormatting.kt | 4 +++- .../ruleset/rules/chapter2/kdoc/KdocComments.kt | 9 +++++---- .../ruleset/rules/chapter2/kdoc/KdocFormatting.kt | 11 ++++++----- .../diktat/ruleset/rules/chapter2/kdoc/KdocMethods.kt | 9 +++++---- .../ruleset/rules/chapter3/AnnotationNewLineRule.kt | 7 ++++--- .../ruleset/rules/chapter3/BlockStructureBraces.kt | 7 ++++--- .../chapter3/BracesInConditionalsAndLoopsRule.kt | 7 ++++--- .../rules/chapter3/ClassLikeStructuresOrderRule.kt | 7 ++++--- .../ruleset/rules/chapter3/ConsecutiveSpacesRule.kt | 7 ++++--- .../cqfn/diktat/ruleset/rules/chapter3/EmptyBlock.kt | 7 ++++--- .../diktat/ruleset/rules/chapter3/EnumsSeparated.kt | 7 ++++--- .../cqfn/diktat/ruleset/rules/chapter3/LineLength.kt | 7 ++++--- .../chapter3/LongNumericalValuesSeparatedRule.kt | 7 ++++--- .../rules/chapter3/MultipleModifiersSequence.kt | 7 ++++--- .../diktat/ruleset/rules/chapter3/NullableTypeRule.kt | 7 ++++--- .../rules/chapter3/SingleLineStatementsRule.kt | 7 ++++--- .../cqfn/diktat/ruleset/rules/chapter3/SortRule.kt | 7 ++++--- .../ruleset/rules/chapter3/StringConcatenationRule.kt | 7 ++++--- .../rules/chapter3/StringTemplateFormatRule.kt | 7 ++++--- .../ruleset/rules/chapter3/TrailingCommaRule.kt | 7 ++++--- .../ruleset/rules/chapter3/WhenMustHaveElseRule.kt | 7 ++++--- .../ruleset/rules/chapter3/files/BlankLinesRule.kt | 7 ++++--- .../diktat/ruleset/rules/chapter3/files/FileSize.kt | 7 ++++--- .../ruleset/rules/chapter3/files/IndentationRule.kt | 7 ++++--- .../ruleset/rules/chapter3/files/NewlinesRule.kt | 7 ++++--- .../ruleset/rules/chapter3/files/TopLevelOrderRule.kt | 5 ++++- .../ruleset/rules/chapter3/files/WhiteSpaceRule.kt | 7 ++++--- .../rules/chapter3/identifiers/LocalVariablesRule.kt | 7 ++++--- .../ruleset/rules/chapter4/ImmutableValNoVarRule.kt | 7 ++++--- .../diktat/ruleset/rules/chapter4/NullChecksRule.kt | 7 ++++--- .../diktat/ruleset/rules/chapter4/SmartCastRule.kt | 7 ++++--- .../diktat/ruleset/rules/chapter4/TypeAliasRule.kt | 7 ++++--- .../chapter4/VariableGenericTypeDeclarationRule.kt | 7 ++++--- .../chapter4/calculations/AccurateCalculationsRule.kt | 7 ++++--- .../diktat/ruleset/rules/chapter5/AsyncAndSyncRule.kt | 7 ++++--- .../rules/chapter5/AvoidNestedFunctionsRule.kt | 7 ++++--- .../ruleset/rules/chapter5/CheckInverseMethodRule.kt | 7 ++++--- .../cqfn/diktat/ruleset/rules/chapter5/CustomLabel.kt | 7 ++++--- .../ruleset/rules/chapter5/FunctionArgumentsSize.kt | 7 ++++--- .../diktat/ruleset/rules/chapter5/FunctionLength.kt | 7 ++++--- .../diktat/ruleset/rules/chapter5/LambdaLengthRule.kt | 7 ++++--- .../ruleset/rules/chapter5/LambdaParameterOrder.kt | 7 ++++--- .../ruleset/rules/chapter5/NestedFunctionBlock.kt | 7 ++++--- .../rules/chapter5/OverloadingArgumentsFunction.kt | 7 ++++--- .../rules/chapter6/AvoidEmptyPrimaryConstructor.kt | 7 ++++--- .../ruleset/rules/chapter6/AvoidUtilityClass.kt | 7 ++++--- .../ruleset/rules/chapter6/CustomGetterSetterRule.kt | 7 ++++--- .../rules/chapter6/ExtensionFunctionsInFileRule.kt | 4 +++- .../rules/chapter6/ExtensionFunctionsSameNameRule.kt | 7 ++++--- .../rules/chapter6/ImplicitBackingPropertyRule.kt | 7 ++++--- .../ruleset/rules/chapter6/PropertyAccessorFields.kt | 7 ++++--- .../rules/chapter6/TrivialPropertyAccessors.kt | 7 ++++--- .../diktat/ruleset/rules/chapter6/UselessSupertype.kt | 7 ++++--- .../rules/chapter6/classes/AbstractClassesRule.kt | 7 ++++--- .../rules/chapter6/classes/CompactInitialization.kt | 7 ++++--- .../ruleset/rules/chapter6/classes/DataClassesRule.kt | 7 ++++--- .../rules/chapter6/classes/InlineClassesRule.kt | 7 ++++--- .../rules/chapter6/classes/SingleConstructorRule.kt | 7 ++++--- .../ruleset/rules/chapter6/classes/SingleInitRule.kt | 7 ++++--- .../rules/chapter6/classes/StatelessClassesRule.kt | 7 ++++--- 63 files changed, 252 insertions(+), 186 deletions(-) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter1/FileNaming.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter1/FileNaming.kt index a185220471..b9efe14a6e 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter1/FileNaming.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter1/FileNaming.kt @@ -26,9 +26,10 @@ import java.io.File * Aggressive: In case file contains only one class on upper level - it should be named with the same name */ @Suppress("ForbiddenComment") -class FileNaming(configRules: List) : DiktatRule("file-naming", - configRules, - listOf(FILE_NAME_INCORRECT, FILE_NAME_MATCH_CLASS)) { +class FileNaming(configRules: List) : DiktatRule( + "file-naming", + configRules, + listOf(FILE_NAME_INCORRECT, FILE_NAME_MATCH_CLASS)) { private lateinit var filePath: String override fun logic(node: ASTNode) { diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/comments/CommentsRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/comments/CommentsRule.kt index b14603a9fc..f59ba81fc4 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/comments/CommentsRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/comments/CommentsRule.kt @@ -23,9 +23,10 @@ import org.jetbrains.kotlin.resolve.ImportPath * No commented out code is allowed, including imports. */ @Suppress("ForbiddenComment") -class CommentsRule(configRules: List) : DiktatRule("comments", - configRules, - listOf(COMMENTED_OUT_CODE)) { +class CommentsRule(configRules: List) : DiktatRule( + "comments", + configRules, + listOf(COMMENTED_OUT_CODE)) { private lateinit var ktPsiFactory: KtPsiFactory override fun logic(node: ASTNode) { diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/comments/HeaderCommentRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/comments/HeaderCommentRule.kt index 3750e7ed04..eadda8a774 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/comments/HeaderCommentRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/comments/HeaderCommentRule.kt @@ -41,8 +41,8 @@ import java.time.LocalDate @Suppress("ForbiddenComment") class HeaderCommentRule(configRules: List) : DiktatRule( "header-comment", - configRules, - listOf(HEADER_MISSING_IN_NON_SINGLE_CLASS_FILE, HEADER_MISSING_OR_WRONG_COPYRIGHT, HEADER_NOT_BEFORE_PACKAGE, + configRules, + listOf(HEADER_MISSING_IN_NON_SINGLE_CLASS_FILE, HEADER_MISSING_OR_WRONG_COPYRIGHT, HEADER_NOT_BEFORE_PACKAGE, HEADER_NOT_BEFORE_PACKAGE, HEADER_WRONG_FORMAT, WRONG_COPYRIGHT_YEAR)) { override fun logic(node: ASTNode) { if (node.elementType == FILE) { diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/kdoc/CommentsFormatting.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/kdoc/CommentsFormatting.kt index 97599a127e..d617286972 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/kdoc/CommentsFormatting.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/kdoc/CommentsFormatting.kt @@ -49,7 +49,9 @@ import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.PsiWhiteSpaceImpl * * Leave one single space between the comment on the right side of the code and the code. * * Comments in if else should be inside code blocks. Exception: General if comment */ -class CommentsFormatting(configRules: List) : DiktatRule("kdoc-comments-codeblocks-formatting", configRules, +class CommentsFormatting(configRules: List) : DiktatRule( + "kdoc-comments-codeblocks-formatting", + configRules, listOf(COMMENT_WHITE_SPACE, FIRST_COMMENT_NO_BLANK_LINE, IF_ELSE_COMMENTS, WRONG_NEWLINES_AROUND_KDOC)) { /** diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/kdoc/KdocComments.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/kdoc/KdocComments.kt index d7b3d49e10..c667931d4b 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/kdoc/KdocComments.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/kdoc/KdocComments.kt @@ -44,10 +44,11 @@ import org.jetbrains.kotlin.psi.psiUtil.parents * 2) All internal elements in class like class, property or function should be documented with KDoc * 3) All properties declared in the primary constructor are documented using `@property` tag in class KDoc */ -class KdocComments(configRules: List) : DiktatRule("kdoc-comments", - configRules, - listOf(KDOC_EXTRA_PROPERTY, KDOC_NO_CONSTRUCTOR_PROPERTY, - KDOC_NO_CONSTRUCTOR_PROPERTY_WITH_COMMENT, MISSING_KDOC_CLASS_ELEMENTS, MISSING_KDOC_TOP_LEVEL)) { +class KdocComments(configRules: List) : DiktatRule( + "kdoc-comments", + configRules, + listOf(KDOC_EXTRA_PROPERTY, KDOC_NO_CONSTRUCTOR_PROPERTY, + KDOC_NO_CONSTRUCTOR_PROPERTY_WITH_COMMENT, MISSING_KDOC_CLASS_ELEMENTS, MISSING_KDOC_TOP_LEVEL)) { /** * @param node * @param autoCorrect diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/kdoc/KdocFormatting.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/kdoc/KdocFormatting.kt index 958914c37e..d1321bee02 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/kdoc/KdocFormatting.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/kdoc/KdocFormatting.kt @@ -59,11 +59,12 @@ import java.time.temporal.ChronoField * 7) ensuring @since tag contains only versions and not dates */ @Suppress("ForbiddenComment") -class KdocFormatting(configRules: List) : DiktatRule("kdoc-formatting", - configRules, - listOf(KDOC_CONTAINS_DATE_OR_AUTHOR, KDOC_EMPTY_KDOC, KDOC_NEWLINES_BEFORE_BASIC_TAGS, KDOC_NO_DEPRECATED_TAG, - KDOC_NO_EMPTY_TAGS, KDOC_NO_NEWLINES_BETWEEN_BASIC_TAGS, KDOC_NO_NEWLINE_AFTER_SPECIAL_TAGS, - KDOC_WRONG_SPACES_AFTER_TAG, KDOC_WRONG_TAGS_ORDER)) { +class KdocFormatting(configRules: List) : DiktatRule( + "kdoc-formatting", + configRules, + listOf(KDOC_CONTAINS_DATE_OR_AUTHOR, KDOC_EMPTY_KDOC, KDOC_NEWLINES_BEFORE_BASIC_TAGS, KDOC_NO_DEPRECATED_TAG, + KDOC_NO_EMPTY_TAGS, KDOC_NO_NEWLINES_BETWEEN_BASIC_TAGS, KDOC_NO_NEWLINE_AFTER_SPECIAL_TAGS, + KDOC_WRONG_SPACES_AFTER_TAG, KDOC_WRONG_TAGS_ORDER)) { private val basicTagsList = listOf(KDocKnownTag.PARAM, KDocKnownTag.RETURN, KDocKnownTag.THROWS) private val specialTagNames = setOf("implSpec", "implNote", "apiNote") private var versionRegex: Regex? = null diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/kdoc/KdocMethods.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/kdoc/KdocMethods.kt index f86f90d7d7..f3d4bbdf7f 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/kdoc/KdocMethods.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/kdoc/KdocMethods.kt @@ -65,10 +65,11 @@ import org.jetbrains.kotlin.psi.psiUtil.referenceExpression * Currently only `throw` keyword from this methods body is supported for `@throws` check. */ @Suppress("ForbiddenComment") -class KdocMethods(configRules: List) : DiktatRule("kdoc-methods", - configRules, - listOf(KDOC_TRIVIAL_KDOC_ON_FUNCTION, KDOC_WITHOUT_PARAM_TAG, KDOC_WITHOUT_RETURN_TAG, - KDOC_WITHOUT_THROWS_TAG, MISSING_KDOC_ON_FUNCTION)) { +class KdocMethods(configRules: List) : DiktatRule( + "kdoc-methods", + configRules, + listOf(KDOC_TRIVIAL_KDOC_ON_FUNCTION, KDOC_WITHOUT_PARAM_TAG, KDOC_WITHOUT_RETURN_TAG, + KDOC_WITHOUT_THROWS_TAG, MISSING_KDOC_ON_FUNCTION)) { /** * @param node * @param autoCorrect diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/AnnotationNewLineRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/AnnotationNewLineRule.kt index 5a660d8a0a..394eb9e7c8 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/AnnotationNewLineRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/AnnotationNewLineRule.kt @@ -19,9 +19,10 @@ import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.PsiWhiteSpaceImpl /** * This rule makes each annotation applied to a class, method or constructor is on its own line. Except: if first annotation of constructor, class or method */ -class AnnotationNewLineRule(configRules: List) : DiktatRule("annotation-new-line", - configRules, - listOf(ANNOTATION_NEW_LINE)) { +class AnnotationNewLineRule(configRules: List) : DiktatRule( + "annotation-new-line", + configRules, + listOf(ANNOTATION_NEW_LINE)) { override fun logic(node: ASTNode) { when (node.elementType) { CLASS, FUN, PRIMARY_CONSTRUCTOR, SECONDARY_CONSTRUCTOR -> checkAnnotation(node) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/BlockStructureBraces.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/BlockStructureBraces.kt index 5b273933fa..8b4aec3074 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/BlockStructureBraces.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/BlockStructureBraces.kt @@ -49,9 +49,10 @@ import org.jetbrains.kotlin.psi.KtTryExpression * - opening brace of lambda * - braces around `else`/`catch`/`finally`/`while` (in `do-while` loop) */ -class BlockStructureBraces(configRules: List) : DiktatRule("block-structure", - configRules, - listOf(BRACES_BLOCK_STRUCTURE_ERROR)) { +class BlockStructureBraces(configRules: List) : DiktatRule( + "block-structure", + configRules, + listOf(BRACES_BLOCK_STRUCTURE_ERROR)) { override fun logic(node: ASTNode) { val configuration = BlockStructureBracesConfiguration( configRules.getRuleConfig(BRACES_BLOCK_STRUCTURE_ERROR)?.configuration ?: emptyMap() diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/BracesInConditionalsAndLoopsRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/BracesInConditionalsAndLoopsRule.kt index 5ad157e94b..afacad5b96 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/BracesInConditionalsAndLoopsRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/BracesInConditionalsAndLoopsRule.kt @@ -34,9 +34,10 @@ import org.jetbrains.kotlin.psi.psiUtil.astReplace /** * Rule that checks that all conditionals and loops have braces. */ -class BracesInConditionalsAndLoopsRule(configRules: List) : DiktatRule("braces-rule", - configRules, - listOf(NO_BRACES_IN_CONDITIONALS_AND_LOOPS)) { +class BracesInConditionalsAndLoopsRule(configRules: List) : DiktatRule( + "braces-rule", + configRules, + listOf(NO_BRACES_IN_CONDITIONALS_AND_LOOPS)) { override fun logic(node: ASTNode) { when (node.elementType) { IF -> checkIfNode(node) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/ClassLikeStructuresOrderRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/ClassLikeStructuresOrderRule.kt index b713bf3dbe..2583ee2efe 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/ClassLikeStructuresOrderRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/ClassLikeStructuresOrderRule.kt @@ -41,9 +41,10 @@ import org.jetbrains.kotlin.psi.psiUtil.siblings /** * Rule that checks order of declarations inside classes, interfaces and objects. */ -class ClassLikeStructuresOrderRule(configRules: List) : DiktatRule("class-like-structures", - configRules, - listOf(BLANK_LINE_BETWEEN_PROPERTIES, WRONG_ORDER_IN_CLASS_LIKE_STRUCTURES)) { +class ClassLikeStructuresOrderRule(configRules: List) : DiktatRule( + "class-like-structures", + configRules, + listOf(BLANK_LINE_BETWEEN_PROPERTIES, WRONG_ORDER_IN_CLASS_LIKE_STRUCTURES)) { override fun logic(node: ASTNode) { if (node.elementType == CLASS_BODY) { checkDeclarationsOrderInClass(node) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/ConsecutiveSpacesRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/ConsecutiveSpacesRule.kt index 59e52e8fd7..8cf144fb9b 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/ConsecutiveSpacesRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/ConsecutiveSpacesRule.kt @@ -20,9 +20,10 @@ import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.LeafElement * 2) If saveInitialFormattingForEnums is true then white spaces in enums will not be affected * */ -class ConsecutiveSpacesRule(configRules: List) : DiktatRule("too-many-spaces", - configRules, - listOf(TOO_MANY_CONSECUTIVE_SPACES)) { +class ConsecutiveSpacesRule(configRules: List) : DiktatRule( + "too-many-spaces", + configRules, + listOf(TOO_MANY_CONSECUTIVE_SPACES)) { override fun logic(node: ASTNode) { val configuration = TooManySpacesRuleConfiguration( configRules.getRuleConfig(TOO_MANY_CONSECUTIVE_SPACES)?.configuration ?: emptyMap()) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/EmptyBlock.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/EmptyBlock.kt index 182dcceb6c..fc487dc039 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/EmptyBlock.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/EmptyBlock.kt @@ -25,9 +25,10 @@ import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.PsiWhiteSpaceImpl /** * Rule that checks if empty code blocks (`{ }`) are used and checks their formatting. */ -class EmptyBlock(configRules: List) : DiktatRule("empty-block-structure", - configRules, - listOf(EMPTY_BLOCK_STRUCTURE_ERROR)) { +class EmptyBlock(configRules: List) : DiktatRule( + "empty-block-structure", + configRules, + listOf(EMPTY_BLOCK_STRUCTURE_ERROR)) { override fun logic(node: ASTNode) { val configuration = EmptyBlockStyleConfiguration( configRules.getRuleConfig(EMPTY_BLOCK_STRUCTURE_ERROR)?.configuration ?: emptyMap() diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/EnumsSeparated.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/EnumsSeparated.kt index f9e8c06067..3091b9cb6e 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/EnumsSeparated.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/EnumsSeparated.kt @@ -26,9 +26,10 @@ import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.PsiWhiteSpaceImpl /** * Rule that checks enum classes formatting */ -class EnumsSeparated(configRules: List) : DiktatRule("enum-separated", - configRules, - listOf(ENUMS_SEPARATED)) { +class EnumsSeparated(configRules: List) : DiktatRule( + "enum-separated", + configRules, + listOf(ENUMS_SEPARATED)) { override fun logic(node: ASTNode) { if (node.elementType == CLASS && node.hasChildOfType(CLASS_BODY)) { if (node.isClassEnum()) { 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 98bc731251..161d63dbd0 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 @@ -57,9 +57,10 @@ import java.net.URL * Rule can fix long binary expressions in condition inside `if` and in property declarations and one line functions */ @Suppress("ForbiddenComment") -class LineLength(configRules: List) : DiktatRule("line-length", - configRules, - listOf(LONG_LINE)) { +class LineLength(configRules: List) : DiktatRule( + "line-length", + configRules, + listOf(LONG_LINE)) { private lateinit var positionByOffset: (Int) -> Pair override fun logic(node: ASTNode) { diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/LongNumericalValuesSeparatedRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/LongNumericalValuesSeparatedRule.kt index 918ff4e0cd..e0616f9e19 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/LongNumericalValuesSeparatedRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/LongNumericalValuesSeparatedRule.kt @@ -16,9 +16,10 @@ import java.lang.StringBuilder /** * Rule that checks if numerical separators (`_`) are used for long numerical literals */ -class LongNumericalValuesSeparatedRule(configRules: List) : DiktatRule("long-numerical-values", - configRules, - listOf(LONG_NUMERICAL_VALUES_SEPARATED)) { +class LongNumericalValuesSeparatedRule(configRules: List) : DiktatRule( + "long-numerical-values", + configRules, + listOf(LONG_NUMERICAL_VALUES_SEPARATED)) { override fun logic(node: ASTNode) { val configuration = LongNumericalValuesConfiguration( configRules.getRuleConfig(LONG_NUMERICAL_VALUES_SEPARATED)?.configuration ?: emptyMap()) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/MultipleModifiersSequence.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/MultipleModifiersSequence.kt index b297151af5..a33feb127e 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/MultipleModifiersSequence.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/MultipleModifiersSequence.kt @@ -15,9 +15,10 @@ import org.jetbrains.kotlin.psi.psiUtil.children /** * @property configRules */ -class MultipleModifiersSequence(configRules: List) : DiktatRule("multiple-modifiers", - configRules, - listOf(WRONG_MULTIPLE_MODIFIERS_ORDER)) { +class MultipleModifiersSequence(configRules: List) : DiktatRule( + "multiple-modifiers", + configRules, + listOf(WRONG_MULTIPLE_MODIFIERS_ORDER)) { override fun logic(node: ASTNode) { if (node.elementType == MODIFIER_LIST) { checkModifierList(node) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/NullableTypeRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/NullableTypeRule.kt index 9d4d3ee0a5..4c7ece779a 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/NullableTypeRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/NullableTypeRule.kt @@ -37,9 +37,10 @@ import org.jetbrains.kotlin.com.intellij.psi.tree.IElementType /** * Rule that checks if nullable types are used and suggest to substitute them with non-nullable */ -class NullableTypeRule(configRules: List) : DiktatRule("nullable-type", - configRules, - listOf(NULLABLE_PROPERTY_TYPE)) { +class NullableTypeRule(configRules: List) : DiktatRule( + "nullable-type", + configRules, + listOf(NULLABLE_PROPERTY_TYPE)) { override fun logic(node: ASTNode) { if (node.elementType == PROPERTY) { checkProperty(node) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/SingleLineStatementsRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/SingleLineStatementsRule.kt index 68de295e38..b72b53b108 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/SingleLineStatementsRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/SingleLineStatementsRule.kt @@ -18,9 +18,10 @@ import org.jetbrains.kotlin.com.intellij.psi.tree.TokenSet /** * Rule that looks for multiple statements on a single line separated with a `;` and splits them in multiple lines. */ -class SingleLineStatementsRule(configRules: List) : DiktatRule("statement", - configRules, - listOf(MORE_THAN_ONE_STATEMENT_PER_LINE)) { +class SingleLineStatementsRule(configRules: List) : DiktatRule( + "statement", + configRules, + listOf(MORE_THAN_ONE_STATEMENT_PER_LINE)) { override fun logic(node: ASTNode) { checkSemicolon(node) } diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/SortRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/SortRule.kt index 79a14e61e0..52d553e2c1 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/SortRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/SortRule.kt @@ -26,9 +26,10 @@ import org.jetbrains.kotlin.psi.KtObjectDeclaration /** * Rule that sorts class properties and enum members alphabetically */ -class SortRule(configRules: List) : DiktatRule("sort-rule", - configRules, - listOf(WRONG_DECLARATIONS_ORDER)) { +class SortRule(configRules: List) : DiktatRule( + "sort-rule", + configRules, + listOf(WRONG_DECLARATIONS_ORDER)) { override fun logic(node: ASTNode) { val configuration = SortRuleConfiguration( configRules.getRuleConfig(WRONG_DECLARATIONS_ORDER)?.configuration ?: emptyMap() diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/StringConcatenationRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/StringConcatenationRule.kt index 7d4d87c9ab..1ac972c458 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/StringConcatenationRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/StringConcatenationRule.kt @@ -19,9 +19,10 @@ import org.jetbrains.kotlin.com.intellij.lang.ASTNode * // FixMe: fixes will be added * // FixMe: .toString() method and functions that return strings are not supported */ -class StringConcatenationRule(configRules: List) : DiktatRule("string-concatenation", - configRules, - listOf(STRING_CONCATENATION)) { +class StringConcatenationRule(configRules: List) : DiktatRule( + "string-concatenation", + configRules, + listOf(STRING_CONCATENATION)) { override fun logic(node: ASTNode) { if (node.elementType == BINARY_EXPRESSION) { // searching top-level binary expression to detect any operations with "plus" (+) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/StringTemplateFormatRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/StringTemplateFormatRule.kt index 0f58ea2596..27be97a66d 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/StringTemplateFormatRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/StringTemplateFormatRule.kt @@ -28,9 +28,10 @@ import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.LeafPsiElement * * FixMe: The important caveat here: in "$foo" kotlin compiler adds implicit call to foo.toString() in case foo type is not string. */ -class StringTemplateFormatRule(configRules: List) : DiktatRule("string-template-format", - configRules, - listOf(STRING_TEMPLATE_CURLY_BRACES, STRING_TEMPLATE_QUOTES)) { +class StringTemplateFormatRule(configRules: List) : DiktatRule( + "string-template-format", + configRules, + listOf(STRING_TEMPLATE_CURLY_BRACES, STRING_TEMPLATE_QUOTES)) { override fun logic(node: ASTNode) { when (node.elementType) { LONG_STRING_TEMPLATE_ENTRY -> handleLongStringTemplate(node) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/TrailingCommaRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/TrailingCommaRule.kt index 61655aadbd..f8b136ee6c 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/TrailingCommaRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/TrailingCommaRule.kt @@ -49,9 +49,10 @@ import org.jetbrains.kotlin.psi.psiUtil.siblings * [12] Destructuring declarations */ @Suppress("TOO_LONG_FUNCTION") -class TrailingCommaRule(configRules: List) : DiktatRule("trailing-comma", - configRules, - listOf(TRAILING_COMMA)) { +class TrailingCommaRule(configRules: List) : DiktatRule( + "trailing-comma", + configRules, + listOf(TRAILING_COMMA)) { private val commonConfig by configRules.getCommonConfiguration() private val trailingConfig = this.configRules.getRuleConfig(TRAILING_COMMA)?.configuration ?: emptyMap() private val configuration by lazy { diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/WhenMustHaveElseRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/WhenMustHaveElseRule.kt index fc1f4eac6b..8e5102a585 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/WhenMustHaveElseRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/WhenMustHaveElseRule.kt @@ -36,9 +36,10 @@ import org.jetbrains.kotlin.psi.KtWhenExpression * The compiler can issue a warning when it is missing. */ @Suppress("ForbiddenComment") -class WhenMustHaveElseRule(configRules: List) : DiktatRule("no-else-in-when", - configRules, - listOf(WHEN_WITHOUT_ELSE)) { +class WhenMustHaveElseRule(configRules: List) : DiktatRule( + "no-else-in-when", + configRules, + listOf(WHEN_WITHOUT_ELSE)) { override fun logic(node: ASTNode) { if (node.elementType == ElementType.WHEN && isStatement(node)) { checkEntries(node) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/BlankLinesRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/BlankLinesRule.kt index fb8d84cd91..4a4ec205c1 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/BlankLinesRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/BlankLinesRule.kt @@ -23,9 +23,10 @@ import org.jetbrains.kotlin.com.intellij.lang.ASTNode * 1. Checks that no more than two consecutive blank lines are used in a row * 2. Checks that blank lines are not put in the beginning or at the end of code blocks with curly braces */ -class BlankLinesRule(configRules: List) : DiktatRule("blank-lines", - configRules, - listOf(TOO_MANY_BLANK_LINES)) { +class BlankLinesRule(configRules: List) : DiktatRule( + "blank-lines", + configRules, + listOf(TOO_MANY_BLANK_LINES)) { override fun logic(node: ASTNode) { if (node.elementType == WHITE_SPACE) { // note that no blank lines counts as one newline diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/FileSize.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/FileSize.kt index 64cc8b4279..0fcc3a08eb 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/FileSize.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/FileSize.kt @@ -15,9 +15,10 @@ import org.slf4j.LoggerFactory /** * Rule that checks number of lines in a file */ -class FileSize(configRules: List) : DiktatRule("file-size", - configRules, - listOf(FILE_IS_TOO_LONG)) { +class FileSize(configRules: List) : DiktatRule( + "file-size", + configRules, + listOf(FILE_IS_TOO_LONG)) { private val configuration by lazy { FileSizeConfiguration( this.configRules.getRuleConfig(FILE_IS_TOO_LONG)?.configuration ?: emptyMap() diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/IndentationRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/IndentationRule.kt index a8a4e65baf..fc8f6bd8bd 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/IndentationRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/IndentationRule.kt @@ -64,9 +64,10 @@ import org.jetbrains.kotlin.utils.addToStdlib.firstNotNullResult * Additionally, a set of CustomIndentationChecker objects checks all WHITE_SPACE node if they are exceptions from general rules. * @see CustomIndentationChecker */ -class IndentationRule(configRules: List) : DiktatRule("indentation", - configRules, - listOf(WRONG_INDENTATION)) { +class IndentationRule(configRules: List) : DiktatRule( + "indentation", + configRules, + listOf(WRONG_INDENTATION)) { private val configuration: IndentationConfig by lazy { IndentationConfig(configRules.getRuleConfig(WRONG_INDENTATION)?.configuration ?: emptyMap()) } diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/NewlinesRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/NewlinesRule.kt index 0061c69f30..1d92498a97 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/NewlinesRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/NewlinesRule.kt @@ -96,9 +96,10 @@ import org.jetbrains.kotlin.psi.psiUtil.siblings * 10. Complex expression inside condition replaced with new variable */ @Suppress("ForbiddenComment") -class NewlinesRule(configRules: List) : DiktatRule("newlines", - configRules, - listOf(COMPLEX_EXPRESSION, REDUNDANT_SEMICOLON, WRONG_NEWLINES)) { +class NewlinesRule(configRules: List) : DiktatRule( + "newlines", + configRules, + listOf(COMPLEX_EXPRESSION, REDUNDANT_SEMICOLON, WRONG_NEWLINES)) { private val configuration by lazy { NewlinesRuleConfiguration(configRules.getRuleConfig(WRONG_NEWLINES)?.configuration ?: emptyMap()) } diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/TopLevelOrderRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/TopLevelOrderRule.kt index ac967e1e46..1fb5e219c6 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/TopLevelOrderRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/TopLevelOrderRule.kt @@ -25,7 +25,10 @@ import org.jetbrains.kotlin.psi.psiUtil.siblings /** * Rule that checks order in top level */ -class TopLevelOrderRule(configRules: List) : DiktatRule("top-level-order", configRules, listOf(TOP_LEVEL_ORDER)) { +class TopLevelOrderRule(configRules: List) : DiktatRule( + "top-level-order", + configRules, + listOf(TOP_LEVEL_ORDER)) { override fun logic(node: ASTNode) { if (node.elementType == FILE) { checkNode(node) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/WhiteSpaceRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/WhiteSpaceRule.kt index 20b5d819ed..4064509b51 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/WhiteSpaceRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/WhiteSpaceRule.kt @@ -92,9 +92,10 @@ import org.jetbrains.kotlin.psi.psiUtil.parentsWithSelf * 10. There should be no spaces between prefix/postfix operator (like `!!` or `++`) and it's operand */ @Suppress("ForbiddenComment") -class WhiteSpaceRule(configRules: List) : DiktatRule("horizontal-whitespace", - configRules, - listOf(WRONG_WHITESPACE)) { +class WhiteSpaceRule(configRules: List) : DiktatRule( + "horizontal-whitespace", + configRules, + listOf(WRONG_WHITESPACE)) { @Suppress("ComplexMethod") override fun logic(node: ASTNode) { when (node.elementType) { diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/identifiers/LocalVariablesRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/identifiers/LocalVariablesRule.kt index a7614e0d2a..2866bd5dae 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/identifiers/LocalVariablesRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/identifiers/LocalVariablesRule.kt @@ -37,9 +37,10 @@ import org.jetbrains.kotlin.psi.psiUtil.startOffset * * Only properties without initialization or initialized with expressions based on constants are supported. * * Properties initialized with constructor calls cannot be distinguished from method call and are no supported. */ -class LocalVariablesRule(configRules: List) : DiktatRule("local-variables", - configRules, - listOf(LOCAL_VARIABLE_EARLY_DECLARATION)) { +class LocalVariablesRule(configRules: List) : DiktatRule( + "local-variables", + configRules, + listOf(LOCAL_VARIABLE_EARLY_DECLARATION)) { override fun logic(node: ASTNode) { if (node.elementType == FILE) { // collect all local properties and associate with corresponding references diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/ImmutableValNoVarRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/ImmutableValNoVarRule.kt index 9f4224e027..ee2153df4c 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/ImmutableValNoVarRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/ImmutableValNoVarRule.kt @@ -19,9 +19,10 @@ import org.jetbrains.kotlin.psi.psiUtil.getParentOfType * because `var` variables can be reassigned several times in the business logic. Of course, in some scenarios with loops or accumulators only `var`s can be used and are allowed. * FixMe: here we should also raise warnings for a reassignment of a var (if var has no assignments except in declaration - it can be final) */ -class ImmutableValNoVarRule(configRules: List) : DiktatRule("no-var-rule", - configRules, - listOf(SAY_NO_TO_VAR)) { +class ImmutableValNoVarRule(configRules: List) : DiktatRule( + "no-var-rule", + configRules, + listOf(SAY_NO_TO_VAR)) { override fun logic(node: ASTNode) { if (node.elementType == ElementType.FILE) { // we will raise warning for cases when var property has no assignments diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/NullChecksRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/NullChecksRule.kt index 7ec37c0081..86dfef5c5f 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/NullChecksRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/NullChecksRule.kt @@ -26,9 +26,10 @@ import org.jetbrains.kotlin.psi.KtIfExpression * This rule check and fixes explicit null checks (explicit comparison with `null`) * There are several code-structures that can be used in Kotlin to avoid null-checks. For example: `?:`, `.let {}`, `.also {}`, e.t.c */ -class NullChecksRule(configRules: List) : DiktatRule("null-checks", - configRules, - listOf(AVOID_NULL_CHECKS)) { +class NullChecksRule(configRules: List) : DiktatRule( + "null-checks", + configRules, + listOf(AVOID_NULL_CHECKS)) { override fun logic(node: ASTNode) { if (node.elementType == CONDITION) { node.parent(IF)?.let { diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/SmartCastRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/SmartCastRule.kt index 0ac6f37297..f1bfef6011 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/SmartCastRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/SmartCastRule.kt @@ -39,9 +39,10 @@ import org.jetbrains.kotlin.psi.psiUtil.parents /** * Rule that detects redundant explicit casts */ -class SmartCastRule(configRules: List) : DiktatRule("smart-cast-rule", - configRules, - listOf(SMART_CAST_NEEDED)) { +class SmartCastRule(configRules: List) : DiktatRule( + "smart-cast-rule", + configRules, + listOf(SMART_CAST_NEEDED)) { override fun logic(node: ASTNode) { if (node.elementType == FILE) { val usages = collectLocalPropertiesWithUsages(node) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/TypeAliasRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/TypeAliasRule.kt index b78345199b..a4267630cb 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/TypeAliasRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/TypeAliasRule.kt @@ -19,9 +19,10 @@ import org.jetbrains.kotlin.psi.psiUtil.parents * This rule checks if variable has long type reference and two or more nested generics. * Length type reference can be configured */ -class TypeAliasRule(configRules: List) : DiktatRule("type-alias", - configRules, - listOf(TYPE_ALIAS)) { +class TypeAliasRule(configRules: List) : DiktatRule( + "type-alias", + configRules, + listOf(TYPE_ALIAS)) { override fun logic(node: ASTNode) { if (node.elementType == TYPE_REFERENCE && node .parents() diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/VariableGenericTypeDeclarationRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/VariableGenericTypeDeclarationRule.kt index ffe64a981d..a005a45c32 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/VariableGenericTypeDeclarationRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/VariableGenericTypeDeclarationRule.kt @@ -21,9 +21,10 @@ import org.jetbrains.kotlin.psi.KtProperty * Recommended: val myVariable: Map = emptyMap() */ // FIXME: we now don't have access to return types, so we can perform this check only if explicit type is present, but should be able also if it's not. -class VariableGenericTypeDeclarationRule(configRules: List) : DiktatRule("variable-generic-type", - configRules, - listOf(GENERIC_VARIABLE_WRONG_DECLARATION)) { +class VariableGenericTypeDeclarationRule(configRules: List) : DiktatRule( + "variable-generic-type", + configRules, + listOf(GENERIC_VARIABLE_WRONG_DECLARATION)) { override fun logic(node: ASTNode) { when (node.elementType) { PROPERTY, VALUE_PARAMETER -> handleProperty(node) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/calculations/AccurateCalculationsRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/calculations/AccurateCalculationsRule.kt index 419a1352d2..6784425855 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/calculations/AccurateCalculationsRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/calculations/AccurateCalculationsRule.kt @@ -24,9 +24,10 @@ import org.jetbrains.kotlin.psi.psiUtil.startOffset * Exception: allows arithmetic operations only when absolute value of result is immediately used in comparison * Fixme: detect variables by type, not only floating-point literals */ -class AccurateCalculationsRule(configRules: List) : DiktatRule("accurate-calculations", - configRules, - listOf(FLOAT_IN_ACCURATE_CALCULATIONS)) { +class AccurateCalculationsRule(configRules: List) : DiktatRule( + "accurate-calculations", + configRules, + listOf(FLOAT_IN_ACCURATE_CALCULATIONS)) { private fun KtCallExpression?.isAbsOfFloat() = this ?.run { (calleeExpression as? KtNameReferenceExpression) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/AsyncAndSyncRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/AsyncAndSyncRule.kt index 5f26d774d3..16724ba670 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/AsyncAndSyncRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/AsyncAndSyncRule.kt @@ -17,9 +17,10 @@ import org.jetbrains.kotlin.psi.psiUtil.hasSuspendModifier /** * This rule finds if using runBlocking in asynchronous code */ -class AsyncAndSyncRule(configRules: List) : DiktatRule("sync-in-async", - configRules, - listOf(RUN_BLOCKING_INSIDE_ASYNC)) { +class AsyncAndSyncRule(configRules: List) : DiktatRule( + "sync-in-async", + configRules, + listOf(RUN_BLOCKING_INSIDE_ASYNC)) { private val asyncList = listOf("async", "launch") override fun logic(node: ASTNode) { diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/AvoidNestedFunctionsRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/AvoidNestedFunctionsRule.kt index 4faf8c6052..d3d99d5af3 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/AvoidNestedFunctionsRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/AvoidNestedFunctionsRule.kt @@ -24,9 +24,10 @@ import org.jetbrains.kotlin.psi.psiUtil.parents /** * This rule checks for nested functions and warns if it finds any. */ -class AvoidNestedFunctionsRule(configRules: List) : DiktatRule("avoid-nested-functions", - configRules, - listOf(AVOID_NESTED_FUNCTIONS)) { +class AvoidNestedFunctionsRule(configRules: List) : DiktatRule( + "avoid-nested-functions", + configRules, + listOf(AVOID_NESTED_FUNCTIONS)) { override fun logic(node: ASTNode) { if (node.elementType == FUN) { handleNestedFunctions(node) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/CheckInverseMethodRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/CheckInverseMethodRule.kt index 7837f7f803..77a098ac2e 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/CheckInverseMethodRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/CheckInverseMethodRule.kt @@ -22,9 +22,10 @@ import org.jetbrains.kotlin.psi.psiUtil.siblings * This rule checks if inverse method can be used. * For example if there is !isEmpty() on collection call that it changes it to isNotEmpty() */ -class CheckInverseMethodRule(configRules: List) : DiktatRule("inverse-method", - configRules, - listOf(INVERSE_FUNCTION_PREFERRED)) { +class CheckInverseMethodRule(configRules: List) : DiktatRule( + "inverse-method", + configRules, + listOf(INVERSE_FUNCTION_PREFERRED)) { override fun logic(node: ASTNode) { if (node.elementType == CALL_EXPRESSION && node.text in methodMap.keys) { checkCallExpressionName(node) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/CustomLabel.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/CustomLabel.kt index b802b872f2..2dcd4420ba 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/CustomLabel.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/CustomLabel.kt @@ -17,9 +17,10 @@ import org.jetbrains.kotlin.psi.psiUtil.parents /** * Rule that checks using custom label */ -class CustomLabel(configRules: List) : DiktatRule("custom-label", - configRules, - listOf(CUSTOM_LABEL)) { +class CustomLabel(configRules: List) : DiktatRule( + "custom-label", + configRules, + listOf(CUSTOM_LABEL)) { private val forEachReference = listOf("forEach", "forEachIndexed") private val labels = listOf("@loop", "@forEach", "@forEachIndexed") private val stopWords = listOf(RETURN, BREAK, CONTINUE) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/FunctionArgumentsSize.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/FunctionArgumentsSize.kt index 1f664a2e8b..d563382a3c 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/FunctionArgumentsSize.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/FunctionArgumentsSize.kt @@ -14,9 +14,10 @@ import org.jetbrains.kotlin.psi.KtFunction /** * Rule that checks that function doesn't contains too many parameters */ -class FunctionArgumentsSize(configRules: List) : DiktatRule("argument-size", - configRules, - listOf(TOO_MANY_PARAMETERS)) { +class FunctionArgumentsSize(configRules: List) : DiktatRule( + "argument-size", + configRules, + listOf(TOO_MANY_PARAMETERS)) { private val configuration: FunctionArgumentsSizeConfiguration by lazy { FunctionArgumentsSizeConfiguration(configRules.getRuleConfig(TOO_MANY_PARAMETERS)?.configuration ?: emptyMap()) } diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/FunctionLength.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/FunctionLength.kt index 82b818776f..79b05c9a2f 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/FunctionLength.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/FunctionLength.kt @@ -14,9 +14,10 @@ import org.jetbrains.kotlin.psi.KtFunction /** * Rule 5.1.1 check function length */ -class FunctionLength(configRules: List) : DiktatRule("function-length", - configRules, - listOf(TOO_LONG_FUNCTION)) { +class FunctionLength(configRules: List) : DiktatRule( + "function-length", + configRules, + listOf(TOO_LONG_FUNCTION)) { override fun logic(node: ASTNode) { val configuration = FunctionLengthConfiguration( configRules.getRuleConfig(TOO_LONG_FUNCTION)?.configuration ?: emptyMap() diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/LambdaLengthRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/LambdaLengthRule.kt index e7f69655b6..279ac70ae1 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/LambdaLengthRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/LambdaLengthRule.kt @@ -13,9 +13,10 @@ import org.jetbrains.kotlin.com.intellij.lang.ASTNode /** * Rule 5.2.5 check lambda length without parameters */ -class LambdaLengthRule(configRules: List) : DiktatRule("lambda-length", - configRules, - listOf(TOO_MANY_LINES_IN_LAMBDA)) { +class LambdaLengthRule(configRules: List) : DiktatRule( + "lambda-length", + configRules, + listOf(TOO_MANY_LINES_IN_LAMBDA)) { private val configuration by lazy { LambdaLengthConfiguration( this.configRules.getRuleConfig(TOO_MANY_LINES_IN_LAMBDA)?.configuration ?: emptyMap() diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/LambdaParameterOrder.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/LambdaParameterOrder.kt index e1b9da0c49..97b8a596e8 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/LambdaParameterOrder.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/LambdaParameterOrder.kt @@ -15,9 +15,10 @@ import org.jetbrains.kotlin.utils.addToStdlib.ifNotEmpty /** * Rule that checks if parameter with function type is the last in parameter list */ -class LambdaParameterOrder(configRules: List) : DiktatRule("lambda-parameter-order", - configRules, - listOf(LAMBDA_IS_NOT_LAST_PARAMETER)) { +class LambdaParameterOrder(configRules: List) : DiktatRule( + "lambda-parameter-order", + configRules, + listOf(LAMBDA_IS_NOT_LAST_PARAMETER)) { override fun logic(node: ASTNode) { if (node.elementType == ElementType.FUN) { checkArguments(node) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/NestedFunctionBlock.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/NestedFunctionBlock.kt index dcdd5d127b..78cf11b481 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/NestedFunctionBlock.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/NestedFunctionBlock.kt @@ -20,9 +20,10 @@ import org.jetbrains.kotlin.psi.psiUtil.parents /** * Rule 5.1.2 Nested blokcs */ -class NestedFunctionBlock(configRules: List) : DiktatRule("nested-block", - configRules, - listOf(NESTED_BLOCK)) { +class NestedFunctionBlock(configRules: List) : DiktatRule( + "nested-block", + configRules, + listOf(NESTED_BLOCK)) { private val configuration: NestedBlockConfiguration by lazy { NestedBlockConfiguration(configRules.getRuleConfig(NESTED_BLOCK)?.configuration ?: emptyMap()) } diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/OverloadingArgumentsFunction.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/OverloadingArgumentsFunction.kt index b4de0ca7d2..29278b6d29 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/OverloadingArgumentsFunction.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/OverloadingArgumentsFunction.kt @@ -17,9 +17,10 @@ import org.jetbrains.kotlin.psi.psiUtil.startOffset /** * Rule that suggests to use functions with default parameters instead of multiple overloads */ -class OverloadingArgumentsFunction(configRules: List) : DiktatRule("overloading-default-values", - configRules, - listOf(WRONG_OVERLOADING_FUNCTION_ARGUMENTS)) { +class OverloadingArgumentsFunction(configRules: List) : DiktatRule( + "overloading-default-values", + configRules, + listOf(WRONG_OVERLOADING_FUNCTION_ARGUMENTS)) { override fun logic(node: ASTNode) { if (node.elementType == FUN) { checkFun(node.psi as KtFunction) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/AvoidEmptyPrimaryConstructor.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/AvoidEmptyPrimaryConstructor.kt index 5556325d7d..26ac868793 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/AvoidEmptyPrimaryConstructor.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/AvoidEmptyPrimaryConstructor.kt @@ -11,9 +11,10 @@ import org.jetbrains.kotlin.psi.KtClass /** * This rule checks if a class has an empty primary constructor. */ -class AvoidEmptyPrimaryConstructor(configRules: List) : DiktatRule("avoid-empty-primary-constructor", - configRules, - listOf(EMPTY_PRIMARY_CONSTRUCTOR)) { +class AvoidEmptyPrimaryConstructor(configRules: List) : DiktatRule( + "avoid-empty-primary-constructor", + configRules, + listOf(EMPTY_PRIMARY_CONSTRUCTOR)) { override fun logic(node: ASTNode) { if (node.elementType == CLASS) { checkClass(node.psi as KtClass) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/AvoidUtilityClass.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/AvoidUtilityClass.kt index 373f091610..35f8f3c6e3 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/AvoidUtilityClass.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/AvoidUtilityClass.kt @@ -24,9 +24,10 @@ import org.jetbrains.kotlin.psi.psiUtil.children /** * Rule 6.4.1 checks that class/object, with a word "util" in its name, has only functions. */ -class AvoidUtilityClass(configRules: List) : DiktatRule("avoid-utility-class", - configRules, - listOf(AVOID_USING_UTILITY_CLASS)) { +class AvoidUtilityClass(configRules: List) : DiktatRule( + "avoid-utility-class", + configRules, + listOf(AVOID_USING_UTILITY_CLASS)) { override fun logic(node: ASTNode) { val config by configRules.getCommonConfiguration() val filePath = node.getRootNode().getFilePath() diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/CustomGetterSetterRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/CustomGetterSetterRule.kt index 915bb4e923..56782e1dbc 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/CustomGetterSetterRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/CustomGetterSetterRule.kt @@ -15,9 +15,10 @@ import org.jetbrains.kotlin.com.intellij.lang.ASTNode /** * Inspection that checks that no custom getters and setters are used for properties. */ -class CustomGetterSetterRule(configRules: List) : DiktatRule("custom-getter-setter", - configRules, - listOf(CUSTOM_GETTERS_SETTERS)) { +class CustomGetterSetterRule(configRules: List) : DiktatRule( + "custom-getter-setter", + configRules, + listOf(CUSTOM_GETTERS_SETTERS)) { override fun logic(node: ASTNode) { if (node.elementType == PROPERTY_ACCESSOR) { checkForCustomGetersSetters(node) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/ExtensionFunctionsInFileRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/ExtensionFunctionsInFileRule.kt index e3a66b4389..09cae45047 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/ExtensionFunctionsInFileRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/ExtensionFunctionsInFileRule.kt @@ -20,7 +20,9 @@ import org.jetbrains.kotlin.psi.KtFunction /** * This rule checks if there are any extension functions for the class in the same file, where it is defined */ -class ExtensionFunctionsInFileRule(configRules: List) : DiktatRule("extension-functions-class-file", configRules, +class ExtensionFunctionsInFileRule(configRules: List) : DiktatRule( + "extension-functions-class-file", + configRules, listOf(EXTENSION_FUNCTION_WITH_CLASS)) { override fun logic(node: ASTNode) { if (node.elementType == ElementType.FILE) { diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/ExtensionFunctionsSameNameRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/ExtensionFunctionsSameNameRule.kt index fb58dffbf1..68978e1394 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/ExtensionFunctionsSameNameRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/ExtensionFunctionsSameNameRule.kt @@ -32,9 +32,10 @@ internal typealias SimilarSignatures = List) : DiktatRule("extension-functions-same-name", - configRules, - listOf(EXTENSION_FUNCTION_SAME_SIGNATURE)) { +class ExtensionFunctionsSameNameRule(configRules: List) : DiktatRule( + "extension-functions-same-name", + configRules, + listOf(EXTENSION_FUNCTION_SAME_SIGNATURE)) { override fun logic(node: ASTNode) { /** * 1) Collect all classes that extend other classes (collect related classes) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/ImplicitBackingPropertyRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/ImplicitBackingPropertyRule.kt index aad40ca892..b25001c91f 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/ImplicitBackingPropertyRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/ImplicitBackingPropertyRule.kt @@ -24,9 +24,10 @@ import org.jetbrains.kotlin.psi.KtProperty /** * This rule checks if there is a backing property for field with property accessors, in case they don't use field keyword */ -class ImplicitBackingPropertyRule(configRules: List) : DiktatRule("implicit-backing-property", - configRules, - listOf(NO_CORRESPONDING_PROPERTY)) { +class ImplicitBackingPropertyRule(configRules: List) : DiktatRule( + "implicit-backing-property", + configRules, + listOf(NO_CORRESPONDING_PROPERTY)) { override fun logic(node: ASTNode) { if (node.elementType == CLASS_BODY) { findAllProperties(node) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/PropertyAccessorFields.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/PropertyAccessorFields.kt index d50b49f1c8..5562494b97 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/PropertyAccessorFields.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/PropertyAccessorFields.kt @@ -20,9 +20,10 @@ import org.jetbrains.kotlin.psi.KtProperty /** * Rule check that never use the name of a variable in the custom getter or setter */ -class PropertyAccessorFields(configRules: List) : DiktatRule("getter-setter-fields", - configRules, - listOf(WRONG_NAME_OF_VARIABLE_INSIDE_ACCESSOR)) { +class PropertyAccessorFields(configRules: List) : DiktatRule( + "getter-setter-fields", + configRules, + listOf(WRONG_NAME_OF_VARIABLE_INSIDE_ACCESSOR)) { override fun logic(node: ASTNode) { if (node.elementType == PROPERTY_ACCESSOR) { checkPropertyAccessor(node) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/TrivialPropertyAccessors.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/TrivialPropertyAccessors.kt index 0734c192ef..5436c98257 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/TrivialPropertyAccessors.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/TrivialPropertyAccessors.kt @@ -26,9 +26,10 @@ import org.jetbrains.kotlin.psi.KtPropertyAccessor /** * This rule checks if there are any trivial getters and setters and, if so, deletes them */ -class TrivialPropertyAccessors(configRules: List) : DiktatRule("trivial-property-accessors", - configRules, - listOf(TRIVIAL_ACCESSORS_ARE_NOT_RECOMMENDED)) { +class TrivialPropertyAccessors(configRules: List) : DiktatRule( + "trivial-property-accessors", + configRules, + listOf(TRIVIAL_ACCESSORS_ARE_NOT_RECOMMENDED)) { override fun logic(node: ASTNode) { if (node.elementType == PROPERTY_ACCESSOR) { handlePropertyAccessors(node) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/UselessSupertype.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/UselessSupertype.kt index 27ec53d0bc..2047f0b88d 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/UselessSupertype.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/UselessSupertype.kt @@ -31,9 +31,10 @@ import java.util.HashMap * Explicit supertype qualification should not be used if there is not clash between called methods * fixme can't fix supertypes that are defined in other files. */ -class UselessSupertype(configRules: List) : DiktatRule("useless-override", - configRules, - listOf(USELESS_SUPERTYPE)) { +class UselessSupertype(configRules: List) : DiktatRule( + "useless-override", + configRules, + listOf(USELESS_SUPERTYPE)) { override fun logic(node: ASTNode) { if (node.elementType == CLASS) { checkClass(node) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/AbstractClassesRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/AbstractClassesRule.kt index 256f4b6cf4..8a864f43b7 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/AbstractClassesRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/AbstractClassesRule.kt @@ -19,9 +19,10 @@ import org.jetbrains.kotlin.com.intellij.lang.ASTNode /** * Checks if abstract class has any abstract method. If not, warns that class should not be abstract */ -class AbstractClassesRule(configRules: List) : DiktatRule("abstract-classes", - configRules, - listOf(CLASS_SHOULD_NOT_BE_ABSTRACT)) { +class AbstractClassesRule(configRules: List) : DiktatRule( + "abstract-classes", + configRules, + listOf(CLASS_SHOULD_NOT_BE_ABSTRACT)) { override fun logic(node: ASTNode) { if (node.elementType == CLASS) { val classBody = node.getFirstChildWithType(CLASS_BODY) ?: return diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/CompactInitialization.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/CompactInitialization.kt index 9e1a70dd6f..5b17102eb3 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/CompactInitialization.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/CompactInitialization.kt @@ -27,9 +27,10 @@ import org.jetbrains.kotlin.psi.psiUtil.startOffset * FixMe: When assigned variable's name is also a `this@apply`'s property, it should be changed to qualified name, * e.g `this@Foo`. But for this we need a mechanism to determine declaration scope and it's label. */ -class CompactInitialization(configRules: List) : DiktatRule("class-compact-initialization", - configRules, - listOf(COMPACT_OBJECT_INITIALIZATION)) { +class CompactInitialization(configRules: List) : DiktatRule( + "class-compact-initialization", + configRules, + listOf(COMPACT_OBJECT_INITIALIZATION)) { private val kotlinParser by lazy { KotlinParser() } override fun logic(node: ASTNode) { diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/DataClassesRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/DataClassesRule.kt index 3215b5a025..2c205907aa 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/DataClassesRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/DataClassesRule.kt @@ -31,9 +31,10 @@ import org.jetbrains.kotlin.psi.KtPrimaryConstructor /** * This rule checks if class can be made as data class */ -class DataClassesRule(configRules: List) : DiktatRule("data-classes", - configRules, - listOf(USE_DATA_CLASS)) { +class DataClassesRule(configRules: List) : DiktatRule( + "data-classes", + configRules, + listOf(USE_DATA_CLASS)) { override fun logic(node: ASTNode) { if (node.elementType == CLASS) { handleClass(node) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/InlineClassesRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/InlineClassesRule.kt index 4ef24b9215..a2edfc58f8 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/InlineClassesRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/InlineClassesRule.kt @@ -25,9 +25,10 @@ import org.jetbrains.kotlin.psi.psiUtil.visibilityModifierType /** * This rule checks if inline class can be used. */ -class InlineClassesRule(configRules: List) : DiktatRule("inline-classes", - configRules, - listOf(INLINE_CLASS_CAN_BE_USED)) { +class InlineClassesRule(configRules: List) : DiktatRule( + "inline-classes", + configRules, + listOf(INLINE_CLASS_CAN_BE_USED)) { override fun logic(node: ASTNode) { val configuration by configRules.getCommonConfiguration() if (node.elementType == CLASS && configuration.kotlinVersion >= ktVersion) { diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/SingleConstructorRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/SingleConstructorRule.kt index 0c308d6c0c..b75538529f 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/SingleConstructorRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/SingleConstructorRule.kt @@ -33,9 +33,10 @@ import org.jetbrains.kotlin.psi.psiUtil.collectDescendantsOfType * This rule ensures that if a class has a single constructor, this constructor is primary. * Secondary constructor is converted into primary, statements that are not assignments are moved into an `init` block. */ -class SingleConstructorRule(configRules: List) : DiktatRule("single-constructor", - configRules, - listOf(SINGLE_CONSTRUCTOR_SHOULD_BE_PRIMARY)) { +class SingleConstructorRule(configRules: List) : DiktatRule( + "single-constructor", + configRules, + listOf(SINGLE_CONSTRUCTOR_SHOULD_BE_PRIMARY)) { private val kotlinParser by lazy { KotlinParser() } override fun logic(node: ASTNode) { diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/SingleInitRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/SingleInitRule.kt index 843250bce7..a8ac3cc5a2 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/SingleInitRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/SingleInitRule.kt @@ -25,9 +25,10 @@ import org.jetbrains.kotlin.psi.psiUtil.children /** * The rule that checks whether a class has a single `init` block or multiple. Having multiple `init` blocks is a bad practice. */ -class SingleInitRule(configRules: List) : DiktatRule("multiple-init-block", - configRules, - listOf(MULTIPLE_INIT_BLOCKS)) { +class SingleInitRule(configRules: List) : DiktatRule( + "multiple-init-block", + configRules, + listOf(MULTIPLE_INIT_BLOCKS)) { override fun logic(node: ASTNode) { when (node.elementType) { CLASS_BODY -> handleInitBlocks(node) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/StatelessClassesRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/StatelessClassesRule.kt index daded79ffd..70778ddc5d 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/StatelessClassesRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/StatelessClassesRule.kt @@ -27,9 +27,10 @@ import org.jetbrains.kotlin.psi.KtClass /** * This rule checks if class is stateless and if so changes it to object. */ -class StatelessClassesRule(configRules: List) : DiktatRule("stateless-class", - configRules, - listOf(OBJECT_IS_PREFERRED)) { +class StatelessClassesRule(configRules: List) : DiktatRule( + "stateless-class", + configRules, + listOf(OBJECT_IS_PREFERRED)) { override fun logic(node: ASTNode) { // Fixme: We should find interfaces in all project and then check them if (node.elementType == FILE) { From c4d5b74cefc697ced8a5051d206e90ce26130423 Mon Sep 17 00:00:00 2001 From: aktsay6 Date: Tue, 9 Feb 2021 14:50:37 +0300 Subject: [PATCH 06/20] bugfix/newlinesrule(#748) ### What's done: * Fixed bugs --- .../cqfn/diktat/ruleset/rules/chapter1/FileNaming.kt | 6 +++--- .../ruleset/rules/chapter2/comments/CommentsRule.kt | 6 +++--- .../ruleset/rules/chapter2/kdoc/KdocComments.kt | 8 ++++---- .../ruleset/rules/chapter2/kdoc/KdocFormatting.kt | 10 +++++----- .../ruleset/rules/chapter2/kdoc/KdocMethods.kt | 8 ++++---- .../ruleset/rules/chapter3/AnnotationNewLineRule.kt | 6 +++--- .../ruleset/rules/chapter3/BlockStructureBraces.kt | 6 +++--- .../chapter3/BracesInConditionalsAndLoopsRule.kt | 6 +++--- .../rules/chapter3/ClassLikeStructuresOrderRule.kt | 6 +++--- .../ruleset/rules/chapter3/ConsecutiveSpacesRule.kt | 6 +++--- .../cqfn/diktat/ruleset/rules/chapter3/EmptyBlock.kt | 6 +++--- .../diktat/ruleset/rules/chapter3/EnumsSeparated.kt | 6 +++--- .../cqfn/diktat/ruleset/rules/chapter3/LineLength.kt | 6 +++--- .../chapter3/LongNumericalValuesSeparatedRule.kt | 6 +++--- .../rules/chapter3/MultipleModifiersSequence.kt | 6 +++--- .../ruleset/rules/chapter3/NullableTypeRule.kt | 6 +++--- .../rules/chapter3/SingleLineStatementsRule.kt | 6 +++--- .../cqfn/diktat/ruleset/rules/chapter3/SortRule.kt | 6 +++--- .../rules/chapter3/StringConcatenationRule.kt | 6 +++--- .../rules/chapter3/StringTemplateFormatRule.kt | 6 +++--- .../ruleset/rules/chapter3/TrailingCommaRule.kt | 6 +++--- .../ruleset/rules/chapter3/WhenMustHaveElseRule.kt | 6 +++--- .../ruleset/rules/chapter3/files/BlankLinesRule.kt | 6 +++--- .../diktat/ruleset/rules/chapter3/files/FileSize.kt | 6 +++--- .../ruleset/rules/chapter3/files/IndentationRule.kt | 6 +++--- .../ruleset/rules/chapter3/files/NewlinesRule.kt | 12 ++++++------ .../rules/chapter3/files/TopLevelOrderRule.kt | 6 +++--- .../ruleset/rules/chapter3/files/WhiteSpaceRule.kt | 6 +++--- .../rules/chapter3/identifiers/LocalVariablesRule.kt | 6 +++--- .../ruleset/rules/chapter4/ImmutableValNoVarRule.kt | 6 +++--- .../diktat/ruleset/rules/chapter4/NullChecksRule.kt | 6 +++--- .../diktat/ruleset/rules/chapter4/SmartCastRule.kt | 6 +++--- .../diktat/ruleset/rules/chapter4/TypeAliasRule.kt | 6 +++--- .../chapter4/VariableGenericTypeDeclarationRule.kt | 6 +++--- .../calculations/AccurateCalculationsRule.kt | 6 +++--- .../ruleset/rules/chapter5/AsyncAndSyncRule.kt | 6 +++--- .../rules/chapter5/AvoidNestedFunctionsRule.kt | 6 +++--- .../ruleset/rules/chapter5/CheckInverseMethodRule.kt | 6 +++--- .../diktat/ruleset/rules/chapter5/CustomLabel.kt | 6 +++--- .../ruleset/rules/chapter5/FunctionArgumentsSize.kt | 6 +++--- .../diktat/ruleset/rules/chapter5/FunctionLength.kt | 6 +++--- .../ruleset/rules/chapter5/LambdaLengthRule.kt | 6 +++--- .../ruleset/rules/chapter5/LambdaParameterOrder.kt | 6 +++--- .../ruleset/rules/chapter5/NestedFunctionBlock.kt | 6 +++--- .../rules/chapter5/OverloadingArgumentsFunction.kt | 6 +++--- .../rules/chapter6/AvoidEmptyPrimaryConstructor.kt | 6 +++--- .../ruleset/rules/chapter6/AvoidUtilityClass.kt | 6 +++--- .../ruleset/rules/chapter6/CustomGetterSetterRule.kt | 6 +++--- .../rules/chapter6/ExtensionFunctionsSameNameRule.kt | 6 +++--- .../rules/chapter6/ImplicitBackingPropertyRule.kt | 6 +++--- .../ruleset/rules/chapter6/PropertyAccessorFields.kt | 6 +++--- .../rules/chapter6/TrivialPropertyAccessors.kt | 6 +++--- .../ruleset/rules/chapter6/UselessSupertype.kt | 6 +++--- .../rules/chapter6/classes/AbstractClassesRule.kt | 6 +++--- .../rules/chapter6/classes/CompactInitialization.kt | 6 +++--- .../rules/chapter6/classes/DataClassesRule.kt | 6 +++--- .../rules/chapter6/classes/InlineClassesRule.kt | 6 +++--- .../rules/chapter6/classes/SingleConstructorRule.kt | 6 +++--- .../ruleset/rules/chapter6/classes/SingleInitRule.kt | 6 +++--- .../rules/chapter6/classes/StatelessClassesRule.kt | 6 +++--- 60 files changed, 187 insertions(+), 187 deletions(-) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter1/FileNaming.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter1/FileNaming.kt index b9efe14a6e..8c89d666d8 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter1/FileNaming.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter1/FileNaming.kt @@ -27,9 +27,9 @@ import java.io.File */ @Suppress("ForbiddenComment") class FileNaming(configRules: List) : DiktatRule( - "file-naming", - configRules, - listOf(FILE_NAME_INCORRECT, FILE_NAME_MATCH_CLASS)) { + "file-naming", + configRules, + listOf(FILE_NAME_INCORRECT, FILE_NAME_MATCH_CLASS)) { private lateinit var filePath: String override fun logic(node: ASTNode) { diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/comments/CommentsRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/comments/CommentsRule.kt index f59ba81fc4..4b60e373ed 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/comments/CommentsRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/comments/CommentsRule.kt @@ -24,9 +24,9 @@ import org.jetbrains.kotlin.resolve.ImportPath */ @Suppress("ForbiddenComment") class CommentsRule(configRules: List) : DiktatRule( - "comments", - configRules, - listOf(COMMENTED_OUT_CODE)) { + "comments", + configRules, + listOf(COMMENTED_OUT_CODE)) { private lateinit var ktPsiFactory: KtPsiFactory override fun logic(node: ASTNode) { diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/kdoc/KdocComments.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/kdoc/KdocComments.kt index c667931d4b..0808ee0c34 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/kdoc/KdocComments.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/kdoc/KdocComments.kt @@ -45,10 +45,10 @@ import org.jetbrains.kotlin.psi.psiUtil.parents * 3) All properties declared in the primary constructor are documented using `@property` tag in class KDoc */ class KdocComments(configRules: List) : DiktatRule( - "kdoc-comments", - configRules, - listOf(KDOC_EXTRA_PROPERTY, KDOC_NO_CONSTRUCTOR_PROPERTY, - KDOC_NO_CONSTRUCTOR_PROPERTY_WITH_COMMENT, MISSING_KDOC_CLASS_ELEMENTS, MISSING_KDOC_TOP_LEVEL)) { + "kdoc-comments", + configRules, + listOf(KDOC_EXTRA_PROPERTY, KDOC_NO_CONSTRUCTOR_PROPERTY, + KDOC_NO_CONSTRUCTOR_PROPERTY_WITH_COMMENT, MISSING_KDOC_CLASS_ELEMENTS, MISSING_KDOC_TOP_LEVEL)) { /** * @param node * @param autoCorrect diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/kdoc/KdocFormatting.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/kdoc/KdocFormatting.kt index d1321bee02..e958a8a0fb 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/kdoc/KdocFormatting.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/kdoc/KdocFormatting.kt @@ -60,11 +60,11 @@ import java.time.temporal.ChronoField */ @Suppress("ForbiddenComment") class KdocFormatting(configRules: List) : DiktatRule( - "kdoc-formatting", - configRules, - listOf(KDOC_CONTAINS_DATE_OR_AUTHOR, KDOC_EMPTY_KDOC, KDOC_NEWLINES_BEFORE_BASIC_TAGS, KDOC_NO_DEPRECATED_TAG, - KDOC_NO_EMPTY_TAGS, KDOC_NO_NEWLINES_BETWEEN_BASIC_TAGS, KDOC_NO_NEWLINE_AFTER_SPECIAL_TAGS, - KDOC_WRONG_SPACES_AFTER_TAG, KDOC_WRONG_TAGS_ORDER)) { + "kdoc-formatting", + configRules, + listOf(KDOC_CONTAINS_DATE_OR_AUTHOR, KDOC_EMPTY_KDOC, KDOC_NEWLINES_BEFORE_BASIC_TAGS, KDOC_NO_DEPRECATED_TAG, + KDOC_NO_EMPTY_TAGS, KDOC_NO_NEWLINES_BETWEEN_BASIC_TAGS, KDOC_NO_NEWLINE_AFTER_SPECIAL_TAGS, + KDOC_WRONG_SPACES_AFTER_TAG, KDOC_WRONG_TAGS_ORDER)) { private val basicTagsList = listOf(KDocKnownTag.PARAM, KDocKnownTag.RETURN, KDocKnownTag.THROWS) private val specialTagNames = setOf("implSpec", "implNote", "apiNote") private var versionRegex: Regex? = null diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/kdoc/KdocMethods.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/kdoc/KdocMethods.kt index f3d4bbdf7f..3989b9b9e6 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/kdoc/KdocMethods.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/kdoc/KdocMethods.kt @@ -66,10 +66,10 @@ import org.jetbrains.kotlin.psi.psiUtil.referenceExpression */ @Suppress("ForbiddenComment") class KdocMethods(configRules: List) : DiktatRule( - "kdoc-methods", - configRules, - listOf(KDOC_TRIVIAL_KDOC_ON_FUNCTION, KDOC_WITHOUT_PARAM_TAG, KDOC_WITHOUT_RETURN_TAG, - KDOC_WITHOUT_THROWS_TAG, MISSING_KDOC_ON_FUNCTION)) { + "kdoc-methods", + configRules, + listOf(KDOC_TRIVIAL_KDOC_ON_FUNCTION, KDOC_WITHOUT_PARAM_TAG, KDOC_WITHOUT_RETURN_TAG, + KDOC_WITHOUT_THROWS_TAG, MISSING_KDOC_ON_FUNCTION)) { /** * @param node * @param autoCorrect diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/AnnotationNewLineRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/AnnotationNewLineRule.kt index 394eb9e7c8..ec025d6f15 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/AnnotationNewLineRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/AnnotationNewLineRule.kt @@ -20,9 +20,9 @@ import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.PsiWhiteSpaceImpl * This rule makes each annotation applied to a class, method or constructor is on its own line. Except: if first annotation of constructor, class or method */ class AnnotationNewLineRule(configRules: List) : DiktatRule( - "annotation-new-line", - configRules, - listOf(ANNOTATION_NEW_LINE)) { + "annotation-new-line", + configRules, + listOf(ANNOTATION_NEW_LINE)) { override fun logic(node: ASTNode) { when (node.elementType) { CLASS, FUN, PRIMARY_CONSTRUCTOR, SECONDARY_CONSTRUCTOR -> checkAnnotation(node) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/BlockStructureBraces.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/BlockStructureBraces.kt index 8b4aec3074..49a15eab5c 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/BlockStructureBraces.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/BlockStructureBraces.kt @@ -50,9 +50,9 @@ import org.jetbrains.kotlin.psi.KtTryExpression * - braces around `else`/`catch`/`finally`/`while` (in `do-while` loop) */ class BlockStructureBraces(configRules: List) : DiktatRule( - "block-structure", - configRules, - listOf(BRACES_BLOCK_STRUCTURE_ERROR)) { + "block-structure", + configRules, + listOf(BRACES_BLOCK_STRUCTURE_ERROR)) { override fun logic(node: ASTNode) { val configuration = BlockStructureBracesConfiguration( configRules.getRuleConfig(BRACES_BLOCK_STRUCTURE_ERROR)?.configuration ?: emptyMap() diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/BracesInConditionalsAndLoopsRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/BracesInConditionalsAndLoopsRule.kt index afacad5b96..4b72d25e09 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/BracesInConditionalsAndLoopsRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/BracesInConditionalsAndLoopsRule.kt @@ -35,9 +35,9 @@ import org.jetbrains.kotlin.psi.psiUtil.astReplace * Rule that checks that all conditionals and loops have braces. */ class BracesInConditionalsAndLoopsRule(configRules: List) : DiktatRule( - "braces-rule", - configRules, - listOf(NO_BRACES_IN_CONDITIONALS_AND_LOOPS)) { + "braces-rule", + configRules, + listOf(NO_BRACES_IN_CONDITIONALS_AND_LOOPS)) { override fun logic(node: ASTNode) { when (node.elementType) { IF -> checkIfNode(node) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/ClassLikeStructuresOrderRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/ClassLikeStructuresOrderRule.kt index 2583ee2efe..49a1f37e52 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/ClassLikeStructuresOrderRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/ClassLikeStructuresOrderRule.kt @@ -42,9 +42,9 @@ import org.jetbrains.kotlin.psi.psiUtil.siblings * Rule that checks order of declarations inside classes, interfaces and objects. */ class ClassLikeStructuresOrderRule(configRules: List) : DiktatRule( - "class-like-structures", - configRules, - listOf(BLANK_LINE_BETWEEN_PROPERTIES, WRONG_ORDER_IN_CLASS_LIKE_STRUCTURES)) { + "class-like-structures", + configRules, + listOf(BLANK_LINE_BETWEEN_PROPERTIES, WRONG_ORDER_IN_CLASS_LIKE_STRUCTURES)) { override fun logic(node: ASTNode) { if (node.elementType == CLASS_BODY) { checkDeclarationsOrderInClass(node) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/ConsecutiveSpacesRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/ConsecutiveSpacesRule.kt index 8cf144fb9b..73411dc604 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/ConsecutiveSpacesRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/ConsecutiveSpacesRule.kt @@ -21,9 +21,9 @@ import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.LeafElement * */ class ConsecutiveSpacesRule(configRules: List) : DiktatRule( - "too-many-spaces", - configRules, - listOf(TOO_MANY_CONSECUTIVE_SPACES)) { + "too-many-spaces", + configRules, + listOf(TOO_MANY_CONSECUTIVE_SPACES)) { override fun logic(node: ASTNode) { val configuration = TooManySpacesRuleConfiguration( configRules.getRuleConfig(TOO_MANY_CONSECUTIVE_SPACES)?.configuration ?: emptyMap()) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/EmptyBlock.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/EmptyBlock.kt index fc487dc039..1034ed1063 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/EmptyBlock.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/EmptyBlock.kt @@ -26,9 +26,9 @@ import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.PsiWhiteSpaceImpl * Rule that checks if empty code blocks (`{ }`) are used and checks their formatting. */ class EmptyBlock(configRules: List) : DiktatRule( - "empty-block-structure", - configRules, - listOf(EMPTY_BLOCK_STRUCTURE_ERROR)) { + "empty-block-structure", + configRules, + listOf(EMPTY_BLOCK_STRUCTURE_ERROR)) { override fun logic(node: ASTNode) { val configuration = EmptyBlockStyleConfiguration( configRules.getRuleConfig(EMPTY_BLOCK_STRUCTURE_ERROR)?.configuration ?: emptyMap() diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/EnumsSeparated.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/EnumsSeparated.kt index 3091b9cb6e..fe607214c4 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/EnumsSeparated.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/EnumsSeparated.kt @@ -27,9 +27,9 @@ import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.PsiWhiteSpaceImpl * Rule that checks enum classes formatting */ class EnumsSeparated(configRules: List) : DiktatRule( - "enum-separated", - configRules, - listOf(ENUMS_SEPARATED)) { + "enum-separated", + configRules, + listOf(ENUMS_SEPARATED)) { override fun logic(node: ASTNode) { if (node.elementType == CLASS && node.hasChildOfType(CLASS_BODY)) { if (node.isClassEnum()) { 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 161d63dbd0..a259e7c3f4 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 @@ -58,9 +58,9 @@ import java.net.URL */ @Suppress("ForbiddenComment") class LineLength(configRules: List) : DiktatRule( - "line-length", - configRules, - listOf(LONG_LINE)) { + "line-length", + configRules, + listOf(LONG_LINE)) { private lateinit var positionByOffset: (Int) -> Pair override fun logic(node: ASTNode) { diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/LongNumericalValuesSeparatedRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/LongNumericalValuesSeparatedRule.kt index e0616f9e19..556b79cff2 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/LongNumericalValuesSeparatedRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/LongNumericalValuesSeparatedRule.kt @@ -17,9 +17,9 @@ import java.lang.StringBuilder * Rule that checks if numerical separators (`_`) are used for long numerical literals */ class LongNumericalValuesSeparatedRule(configRules: List) : DiktatRule( - "long-numerical-values", - configRules, - listOf(LONG_NUMERICAL_VALUES_SEPARATED)) { + "long-numerical-values", + configRules, + listOf(LONG_NUMERICAL_VALUES_SEPARATED)) { override fun logic(node: ASTNode) { val configuration = LongNumericalValuesConfiguration( configRules.getRuleConfig(LONG_NUMERICAL_VALUES_SEPARATED)?.configuration ?: emptyMap()) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/MultipleModifiersSequence.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/MultipleModifiersSequence.kt index a33feb127e..a326996341 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/MultipleModifiersSequence.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/MultipleModifiersSequence.kt @@ -16,9 +16,9 @@ import org.jetbrains.kotlin.psi.psiUtil.children * @property configRules */ class MultipleModifiersSequence(configRules: List) : DiktatRule( - "multiple-modifiers", - configRules, - listOf(WRONG_MULTIPLE_MODIFIERS_ORDER)) { + "multiple-modifiers", + configRules, + listOf(WRONG_MULTIPLE_MODIFIERS_ORDER)) { override fun logic(node: ASTNode) { if (node.elementType == MODIFIER_LIST) { checkModifierList(node) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/NullableTypeRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/NullableTypeRule.kt index 4c7ece779a..6ef6d78631 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/NullableTypeRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/NullableTypeRule.kt @@ -38,9 +38,9 @@ import org.jetbrains.kotlin.com.intellij.psi.tree.IElementType * Rule that checks if nullable types are used and suggest to substitute them with non-nullable */ class NullableTypeRule(configRules: List) : DiktatRule( - "nullable-type", - configRules, - listOf(NULLABLE_PROPERTY_TYPE)) { + "nullable-type", + configRules, + listOf(NULLABLE_PROPERTY_TYPE)) { override fun logic(node: ASTNode) { if (node.elementType == PROPERTY) { checkProperty(node) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/SingleLineStatementsRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/SingleLineStatementsRule.kt index b72b53b108..a4fc8ec5e4 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/SingleLineStatementsRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/SingleLineStatementsRule.kt @@ -19,9 +19,9 @@ import org.jetbrains.kotlin.com.intellij.psi.tree.TokenSet * Rule that looks for multiple statements on a single line separated with a `;` and splits them in multiple lines. */ class SingleLineStatementsRule(configRules: List) : DiktatRule( - "statement", - configRules, - listOf(MORE_THAN_ONE_STATEMENT_PER_LINE)) { + "statement", + configRules, + listOf(MORE_THAN_ONE_STATEMENT_PER_LINE)) { override fun logic(node: ASTNode) { checkSemicolon(node) } diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/SortRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/SortRule.kt index 52d553e2c1..e9d2726fc8 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/SortRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/SortRule.kt @@ -27,9 +27,9 @@ import org.jetbrains.kotlin.psi.KtObjectDeclaration * Rule that sorts class properties and enum members alphabetically */ class SortRule(configRules: List) : DiktatRule( - "sort-rule", - configRules, - listOf(WRONG_DECLARATIONS_ORDER)) { + "sort-rule", + configRules, + listOf(WRONG_DECLARATIONS_ORDER)) { override fun logic(node: ASTNode) { val configuration = SortRuleConfiguration( configRules.getRuleConfig(WRONG_DECLARATIONS_ORDER)?.configuration ?: emptyMap() diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/StringConcatenationRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/StringConcatenationRule.kt index 1ac972c458..9b2be11948 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/StringConcatenationRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/StringConcatenationRule.kt @@ -20,9 +20,9 @@ import org.jetbrains.kotlin.com.intellij.lang.ASTNode * // FixMe: .toString() method and functions that return strings are not supported */ class StringConcatenationRule(configRules: List) : DiktatRule( - "string-concatenation", - configRules, - listOf(STRING_CONCATENATION)) { + "string-concatenation", + configRules, + listOf(STRING_CONCATENATION)) { override fun logic(node: ASTNode) { if (node.elementType == BINARY_EXPRESSION) { // searching top-level binary expression to detect any operations with "plus" (+) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/StringTemplateFormatRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/StringTemplateFormatRule.kt index 27be97a66d..40d5b607cf 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/StringTemplateFormatRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/StringTemplateFormatRule.kt @@ -29,9 +29,9 @@ import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.LeafPsiElement * FixMe: The important caveat here: in "$foo" kotlin compiler adds implicit call to foo.toString() in case foo type is not string. */ class StringTemplateFormatRule(configRules: List) : DiktatRule( - "string-template-format", - configRules, - listOf(STRING_TEMPLATE_CURLY_BRACES, STRING_TEMPLATE_QUOTES)) { + "string-template-format", + configRules, + listOf(STRING_TEMPLATE_CURLY_BRACES, STRING_TEMPLATE_QUOTES)) { override fun logic(node: ASTNode) { when (node.elementType) { LONG_STRING_TEMPLATE_ENTRY -> handleLongStringTemplate(node) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/TrailingCommaRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/TrailingCommaRule.kt index f8b136ee6c..6e288e23af 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/TrailingCommaRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/TrailingCommaRule.kt @@ -50,9 +50,9 @@ import org.jetbrains.kotlin.psi.psiUtil.siblings */ @Suppress("TOO_LONG_FUNCTION") class TrailingCommaRule(configRules: List) : DiktatRule( - "trailing-comma", - configRules, - listOf(TRAILING_COMMA)) { + "trailing-comma", + configRules, + listOf(TRAILING_COMMA)) { private val commonConfig by configRules.getCommonConfiguration() private val trailingConfig = this.configRules.getRuleConfig(TRAILING_COMMA)?.configuration ?: emptyMap() private val configuration by lazy { diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/WhenMustHaveElseRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/WhenMustHaveElseRule.kt index 8e5102a585..98f289431a 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/WhenMustHaveElseRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/WhenMustHaveElseRule.kt @@ -37,9 +37,9 @@ import org.jetbrains.kotlin.psi.KtWhenExpression */ @Suppress("ForbiddenComment") class WhenMustHaveElseRule(configRules: List) : DiktatRule( - "no-else-in-when", - configRules, - listOf(WHEN_WITHOUT_ELSE)) { + "no-else-in-when", + configRules, + listOf(WHEN_WITHOUT_ELSE)) { override fun logic(node: ASTNode) { if (node.elementType == ElementType.WHEN && isStatement(node)) { checkEntries(node) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/BlankLinesRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/BlankLinesRule.kt index 4a4ec205c1..d055ffbf7f 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/BlankLinesRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/BlankLinesRule.kt @@ -24,9 +24,9 @@ import org.jetbrains.kotlin.com.intellij.lang.ASTNode * 2. Checks that blank lines are not put in the beginning or at the end of code blocks with curly braces */ class BlankLinesRule(configRules: List) : DiktatRule( - "blank-lines", - configRules, - listOf(TOO_MANY_BLANK_LINES)) { + "blank-lines", + configRules, + listOf(TOO_MANY_BLANK_LINES)) { override fun logic(node: ASTNode) { if (node.elementType == WHITE_SPACE) { // note that no blank lines counts as one newline diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/FileSize.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/FileSize.kt index 0fcc3a08eb..461c9ec925 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/FileSize.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/FileSize.kt @@ -16,9 +16,9 @@ import org.slf4j.LoggerFactory * Rule that checks number of lines in a file */ class FileSize(configRules: List) : DiktatRule( - "file-size", - configRules, - listOf(FILE_IS_TOO_LONG)) { + "file-size", + configRules, + listOf(FILE_IS_TOO_LONG)) { private val configuration by lazy { FileSizeConfiguration( this.configRules.getRuleConfig(FILE_IS_TOO_LONG)?.configuration ?: emptyMap() diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/IndentationRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/IndentationRule.kt index fc8f6bd8bd..1e8218d90b 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/IndentationRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/IndentationRule.kt @@ -65,9 +65,9 @@ import org.jetbrains.kotlin.utils.addToStdlib.firstNotNullResult * @see CustomIndentationChecker */ class IndentationRule(configRules: List) : DiktatRule( - "indentation", - configRules, - listOf(WRONG_INDENTATION)) { + "indentation", + configRules, + listOf(WRONG_INDENTATION)) { private val configuration: IndentationConfig by lazy { IndentationConfig(configRules.getRuleConfig(WRONG_INDENTATION)?.configuration ?: emptyMap()) } diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/NewlinesRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/NewlinesRule.kt index 1d92498a97..6fd0653518 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/NewlinesRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/NewlinesRule.kt @@ -97,9 +97,9 @@ import org.jetbrains.kotlin.psi.psiUtil.siblings */ @Suppress("ForbiddenComment") class NewlinesRule(configRules: List) : DiktatRule( - "newlines", - configRules, - listOf(COMPLEX_EXPRESSION, REDUNDANT_SEMICOLON, WRONG_NEWLINES)) { + "newlines", + configRules, + listOf(COMPLEX_EXPRESSION, REDUNDANT_SEMICOLON, WRONG_NEWLINES)) { private val configuration by lazy { NewlinesRuleConfiguration(configRules.getRuleConfig(WRONG_NEWLINES)?.configuration ?: emptyMap()) } @@ -346,9 +346,9 @@ class NewlinesRule(configRules: List) : DiktatRule( .filter { it.elementType == filterType } .toList() .takeIf { it.size > 1 } - ?.let { + ?.let { list -> val freeText = if (filterType == VALUE_ARGUMENT) { - warnText.format(it.first().text) + warnText.format(list.first().text) } else { warnText } @@ -371,7 +371,7 @@ class NewlinesRule(configRules: List) : DiktatRule( .toList() .takeIf { it.isNotEmpty() } ?.let { invalidCommas -> - val warnText = if (node.getParentIdentifier() != null) { + val warnText = if (node.getParentIdentifier() ?: false) { "$entryType should be placed on different lines in declaration of <${node.getParentIdentifier()}>" } else { "$entryType should be placed on different lines" diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/TopLevelOrderRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/TopLevelOrderRule.kt index 1fb5e219c6..473d3b3627 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/TopLevelOrderRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/TopLevelOrderRule.kt @@ -26,9 +26,9 @@ import org.jetbrains.kotlin.psi.psiUtil.siblings * Rule that checks order in top level */ class TopLevelOrderRule(configRules: List) : DiktatRule( - "top-level-order", - configRules, - listOf(TOP_LEVEL_ORDER)) { + "top-level-order", + configRules, + listOf(TOP_LEVEL_ORDER)) { override fun logic(node: ASTNode) { if (node.elementType == FILE) { checkNode(node) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/WhiteSpaceRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/WhiteSpaceRule.kt index 4064509b51..254de14f43 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/WhiteSpaceRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/WhiteSpaceRule.kt @@ -93,9 +93,9 @@ import org.jetbrains.kotlin.psi.psiUtil.parentsWithSelf */ @Suppress("ForbiddenComment") class WhiteSpaceRule(configRules: List) : DiktatRule( - "horizontal-whitespace", - configRules, - listOf(WRONG_WHITESPACE)) { + "horizontal-whitespace", + configRules, + listOf(WRONG_WHITESPACE)) { @Suppress("ComplexMethod") override fun logic(node: ASTNode) { when (node.elementType) { diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/identifiers/LocalVariablesRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/identifiers/LocalVariablesRule.kt index 2866bd5dae..8170e552c3 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/identifiers/LocalVariablesRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/identifiers/LocalVariablesRule.kt @@ -38,9 +38,9 @@ import org.jetbrains.kotlin.psi.psiUtil.startOffset * * Properties initialized with constructor calls cannot be distinguished from method call and are no supported. */ class LocalVariablesRule(configRules: List) : DiktatRule( - "local-variables", - configRules, - listOf(LOCAL_VARIABLE_EARLY_DECLARATION)) { + "local-variables", + configRules, + listOf(LOCAL_VARIABLE_EARLY_DECLARATION)) { override fun logic(node: ASTNode) { if (node.elementType == FILE) { // collect all local properties and associate with corresponding references diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/ImmutableValNoVarRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/ImmutableValNoVarRule.kt index ee2153df4c..520772ed87 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/ImmutableValNoVarRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/ImmutableValNoVarRule.kt @@ -20,9 +20,9 @@ import org.jetbrains.kotlin.psi.psiUtil.getParentOfType * FixMe: here we should also raise warnings for a reassignment of a var (if var has no assignments except in declaration - it can be final) */ class ImmutableValNoVarRule(configRules: List) : DiktatRule( - "no-var-rule", - configRules, - listOf(SAY_NO_TO_VAR)) { + "no-var-rule", + configRules, + listOf(SAY_NO_TO_VAR)) { override fun logic(node: ASTNode) { if (node.elementType == ElementType.FILE) { // we will raise warning for cases when var property has no assignments diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/NullChecksRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/NullChecksRule.kt index 86dfef5c5f..51ce63c06d 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/NullChecksRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/NullChecksRule.kt @@ -27,9 +27,9 @@ import org.jetbrains.kotlin.psi.KtIfExpression * There are several code-structures that can be used in Kotlin to avoid null-checks. For example: `?:`, `.let {}`, `.also {}`, e.t.c */ class NullChecksRule(configRules: List) : DiktatRule( - "null-checks", - configRules, - listOf(AVOID_NULL_CHECKS)) { + "null-checks", + configRules, + listOf(AVOID_NULL_CHECKS)) { override fun logic(node: ASTNode) { if (node.elementType == CONDITION) { node.parent(IF)?.let { diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/SmartCastRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/SmartCastRule.kt index f1bfef6011..e34ceb96cb 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/SmartCastRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/SmartCastRule.kt @@ -40,9 +40,9 @@ import org.jetbrains.kotlin.psi.psiUtil.parents * Rule that detects redundant explicit casts */ class SmartCastRule(configRules: List) : DiktatRule( - "smart-cast-rule", - configRules, - listOf(SMART_CAST_NEEDED)) { + "smart-cast-rule", + configRules, + listOf(SMART_CAST_NEEDED)) { override fun logic(node: ASTNode) { if (node.elementType == FILE) { val usages = collectLocalPropertiesWithUsages(node) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/TypeAliasRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/TypeAliasRule.kt index a4267630cb..1804b09aa1 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/TypeAliasRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/TypeAliasRule.kt @@ -20,9 +20,9 @@ import org.jetbrains.kotlin.psi.psiUtil.parents * Length type reference can be configured */ class TypeAliasRule(configRules: List) : DiktatRule( - "type-alias", - configRules, - listOf(TYPE_ALIAS)) { + "type-alias", + configRules, + listOf(TYPE_ALIAS)) { override fun logic(node: ASTNode) { if (node.elementType == TYPE_REFERENCE && node .parents() diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/VariableGenericTypeDeclarationRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/VariableGenericTypeDeclarationRule.kt index a005a45c32..b2027af05c 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/VariableGenericTypeDeclarationRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/VariableGenericTypeDeclarationRule.kt @@ -22,9 +22,9 @@ import org.jetbrains.kotlin.psi.KtProperty */ // FIXME: we now don't have access to return types, so we can perform this check only if explicit type is present, but should be able also if it's not. class VariableGenericTypeDeclarationRule(configRules: List) : DiktatRule( - "variable-generic-type", - configRules, - listOf(GENERIC_VARIABLE_WRONG_DECLARATION)) { + "variable-generic-type", + configRules, + listOf(GENERIC_VARIABLE_WRONG_DECLARATION)) { override fun logic(node: ASTNode) { when (node.elementType) { PROPERTY, VALUE_PARAMETER -> handleProperty(node) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/calculations/AccurateCalculationsRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/calculations/AccurateCalculationsRule.kt index 6784425855..fb32b85809 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/calculations/AccurateCalculationsRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter4/calculations/AccurateCalculationsRule.kt @@ -25,9 +25,9 @@ import org.jetbrains.kotlin.psi.psiUtil.startOffset * Fixme: detect variables by type, not only floating-point literals */ class AccurateCalculationsRule(configRules: List) : DiktatRule( - "accurate-calculations", - configRules, - listOf(FLOAT_IN_ACCURATE_CALCULATIONS)) { + "accurate-calculations", + configRules, + listOf(FLOAT_IN_ACCURATE_CALCULATIONS)) { private fun KtCallExpression?.isAbsOfFloat() = this ?.run { (calleeExpression as? KtNameReferenceExpression) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/AsyncAndSyncRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/AsyncAndSyncRule.kt index 16724ba670..e79140b160 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/AsyncAndSyncRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/AsyncAndSyncRule.kt @@ -18,9 +18,9 @@ import org.jetbrains.kotlin.psi.psiUtil.hasSuspendModifier * This rule finds if using runBlocking in asynchronous code */ class AsyncAndSyncRule(configRules: List) : DiktatRule( - "sync-in-async", - configRules, - listOf(RUN_BLOCKING_INSIDE_ASYNC)) { + "sync-in-async", + configRules, + listOf(RUN_BLOCKING_INSIDE_ASYNC)) { private val asyncList = listOf("async", "launch") override fun logic(node: ASTNode) { diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/AvoidNestedFunctionsRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/AvoidNestedFunctionsRule.kt index d3d99d5af3..17eff7b2e9 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/AvoidNestedFunctionsRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/AvoidNestedFunctionsRule.kt @@ -25,9 +25,9 @@ import org.jetbrains.kotlin.psi.psiUtil.parents * This rule checks for nested functions and warns if it finds any. */ class AvoidNestedFunctionsRule(configRules: List) : DiktatRule( - "avoid-nested-functions", - configRules, - listOf(AVOID_NESTED_FUNCTIONS)) { + "avoid-nested-functions", + configRules, + listOf(AVOID_NESTED_FUNCTIONS)) { override fun logic(node: ASTNode) { if (node.elementType == FUN) { handleNestedFunctions(node) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/CheckInverseMethodRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/CheckInverseMethodRule.kt index 77a098ac2e..c5504798d7 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/CheckInverseMethodRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/CheckInverseMethodRule.kt @@ -23,9 +23,9 @@ import org.jetbrains.kotlin.psi.psiUtil.siblings * For example if there is !isEmpty() on collection call that it changes it to isNotEmpty() */ class CheckInverseMethodRule(configRules: List) : DiktatRule( - "inverse-method", - configRules, - listOf(INVERSE_FUNCTION_PREFERRED)) { + "inverse-method", + configRules, + listOf(INVERSE_FUNCTION_PREFERRED)) { override fun logic(node: ASTNode) { if (node.elementType == CALL_EXPRESSION && node.text in methodMap.keys) { checkCallExpressionName(node) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/CustomLabel.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/CustomLabel.kt index 2dcd4420ba..2359b3a8aa 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/CustomLabel.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/CustomLabel.kt @@ -18,9 +18,9 @@ import org.jetbrains.kotlin.psi.psiUtil.parents * Rule that checks using custom label */ class CustomLabel(configRules: List) : DiktatRule( - "custom-label", - configRules, - listOf(CUSTOM_LABEL)) { + "custom-label", + configRules, + listOf(CUSTOM_LABEL)) { private val forEachReference = listOf("forEach", "forEachIndexed") private val labels = listOf("@loop", "@forEach", "@forEachIndexed") private val stopWords = listOf(RETURN, BREAK, CONTINUE) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/FunctionArgumentsSize.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/FunctionArgumentsSize.kt index d563382a3c..a5ee1f9045 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/FunctionArgumentsSize.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/FunctionArgumentsSize.kt @@ -15,9 +15,9 @@ import org.jetbrains.kotlin.psi.KtFunction * Rule that checks that function doesn't contains too many parameters */ class FunctionArgumentsSize(configRules: List) : DiktatRule( - "argument-size", - configRules, - listOf(TOO_MANY_PARAMETERS)) { + "argument-size", + configRules, + listOf(TOO_MANY_PARAMETERS)) { private val configuration: FunctionArgumentsSizeConfiguration by lazy { FunctionArgumentsSizeConfiguration(configRules.getRuleConfig(TOO_MANY_PARAMETERS)?.configuration ?: emptyMap()) } diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/FunctionLength.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/FunctionLength.kt index 79b05c9a2f..22de1d88a6 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/FunctionLength.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/FunctionLength.kt @@ -15,9 +15,9 @@ import org.jetbrains.kotlin.psi.KtFunction * Rule 5.1.1 check function length */ class FunctionLength(configRules: List) : DiktatRule( - "function-length", - configRules, - listOf(TOO_LONG_FUNCTION)) { + "function-length", + configRules, + listOf(TOO_LONG_FUNCTION)) { override fun logic(node: ASTNode) { val configuration = FunctionLengthConfiguration( configRules.getRuleConfig(TOO_LONG_FUNCTION)?.configuration ?: emptyMap() diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/LambdaLengthRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/LambdaLengthRule.kt index 279ac70ae1..77fe03e357 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/LambdaLengthRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/LambdaLengthRule.kt @@ -14,9 +14,9 @@ import org.jetbrains.kotlin.com.intellij.lang.ASTNode * Rule 5.2.5 check lambda length without parameters */ class LambdaLengthRule(configRules: List) : DiktatRule( - "lambda-length", - configRules, - listOf(TOO_MANY_LINES_IN_LAMBDA)) { + "lambda-length", + configRules, + listOf(TOO_MANY_LINES_IN_LAMBDA)) { private val configuration by lazy { LambdaLengthConfiguration( this.configRules.getRuleConfig(TOO_MANY_LINES_IN_LAMBDA)?.configuration ?: emptyMap() diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/LambdaParameterOrder.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/LambdaParameterOrder.kt index 97b8a596e8..efa7d4fae2 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/LambdaParameterOrder.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/LambdaParameterOrder.kt @@ -16,9 +16,9 @@ import org.jetbrains.kotlin.utils.addToStdlib.ifNotEmpty * Rule that checks if parameter with function type is the last in parameter list */ class LambdaParameterOrder(configRules: List) : DiktatRule( - "lambda-parameter-order", - configRules, - listOf(LAMBDA_IS_NOT_LAST_PARAMETER)) { + "lambda-parameter-order", + configRules, + listOf(LAMBDA_IS_NOT_LAST_PARAMETER)) { override fun logic(node: ASTNode) { if (node.elementType == ElementType.FUN) { checkArguments(node) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/NestedFunctionBlock.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/NestedFunctionBlock.kt index 78cf11b481..66cbf9bd5a 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/NestedFunctionBlock.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/NestedFunctionBlock.kt @@ -21,9 +21,9 @@ import org.jetbrains.kotlin.psi.psiUtil.parents * Rule 5.1.2 Nested blokcs */ class NestedFunctionBlock(configRules: List) : DiktatRule( - "nested-block", - configRules, - listOf(NESTED_BLOCK)) { + "nested-block", + configRules, + listOf(NESTED_BLOCK)) { private val configuration: NestedBlockConfiguration by lazy { NestedBlockConfiguration(configRules.getRuleConfig(NESTED_BLOCK)?.configuration ?: emptyMap()) } diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/OverloadingArgumentsFunction.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/OverloadingArgumentsFunction.kt index 29278b6d29..9c67a1b7fe 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/OverloadingArgumentsFunction.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter5/OverloadingArgumentsFunction.kt @@ -18,9 +18,9 @@ import org.jetbrains.kotlin.psi.psiUtil.startOffset * Rule that suggests to use functions with default parameters instead of multiple overloads */ class OverloadingArgumentsFunction(configRules: List) : DiktatRule( - "overloading-default-values", - configRules, - listOf(WRONG_OVERLOADING_FUNCTION_ARGUMENTS)) { + "overloading-default-values", + configRules, + listOf(WRONG_OVERLOADING_FUNCTION_ARGUMENTS)) { override fun logic(node: ASTNode) { if (node.elementType == FUN) { checkFun(node.psi as KtFunction) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/AvoidEmptyPrimaryConstructor.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/AvoidEmptyPrimaryConstructor.kt index 26ac868793..d5a500660f 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/AvoidEmptyPrimaryConstructor.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/AvoidEmptyPrimaryConstructor.kt @@ -12,9 +12,9 @@ import org.jetbrains.kotlin.psi.KtClass * This rule checks if a class has an empty primary constructor. */ class AvoidEmptyPrimaryConstructor(configRules: List) : DiktatRule( - "avoid-empty-primary-constructor", - configRules, - listOf(EMPTY_PRIMARY_CONSTRUCTOR)) { + "avoid-empty-primary-constructor", + configRules, + listOf(EMPTY_PRIMARY_CONSTRUCTOR)) { override fun logic(node: ASTNode) { if (node.elementType == CLASS) { checkClass(node.psi as KtClass) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/AvoidUtilityClass.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/AvoidUtilityClass.kt index 35f8f3c6e3..6362053617 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/AvoidUtilityClass.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/AvoidUtilityClass.kt @@ -25,9 +25,9 @@ import org.jetbrains.kotlin.psi.psiUtil.children * Rule 6.4.1 checks that class/object, with a word "util" in its name, has only functions. */ class AvoidUtilityClass(configRules: List) : DiktatRule( - "avoid-utility-class", - configRules, - listOf(AVOID_USING_UTILITY_CLASS)) { + "avoid-utility-class", + configRules, + listOf(AVOID_USING_UTILITY_CLASS)) { override fun logic(node: ASTNode) { val config by configRules.getCommonConfiguration() val filePath = node.getRootNode().getFilePath() diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/CustomGetterSetterRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/CustomGetterSetterRule.kt index 56782e1dbc..647ef47b84 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/CustomGetterSetterRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/CustomGetterSetterRule.kt @@ -16,9 +16,9 @@ import org.jetbrains.kotlin.com.intellij.lang.ASTNode * Inspection that checks that no custom getters and setters are used for properties. */ class CustomGetterSetterRule(configRules: List) : DiktatRule( - "custom-getter-setter", - configRules, - listOf(CUSTOM_GETTERS_SETTERS)) { + "custom-getter-setter", + configRules, + listOf(CUSTOM_GETTERS_SETTERS)) { override fun logic(node: ASTNode) { if (node.elementType == PROPERTY_ACCESSOR) { checkForCustomGetersSetters(node) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/ExtensionFunctionsSameNameRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/ExtensionFunctionsSameNameRule.kt index 68978e1394..2f37ae2de6 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/ExtensionFunctionsSameNameRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/ExtensionFunctionsSameNameRule.kt @@ -33,9 +33,9 @@ internal typealias SimilarSignatures = List) : DiktatRule( - "extension-functions-same-name", - configRules, - listOf(EXTENSION_FUNCTION_SAME_SIGNATURE)) { + "extension-functions-same-name", + configRules, + listOf(EXTENSION_FUNCTION_SAME_SIGNATURE)) { override fun logic(node: ASTNode) { /** * 1) Collect all classes that extend other classes (collect related classes) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/ImplicitBackingPropertyRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/ImplicitBackingPropertyRule.kt index b25001c91f..23116a6607 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/ImplicitBackingPropertyRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/ImplicitBackingPropertyRule.kt @@ -25,9 +25,9 @@ import org.jetbrains.kotlin.psi.KtProperty * This rule checks if there is a backing property for field with property accessors, in case they don't use field keyword */ class ImplicitBackingPropertyRule(configRules: List) : DiktatRule( - "implicit-backing-property", - configRules, - listOf(NO_CORRESPONDING_PROPERTY)) { + "implicit-backing-property", + configRules, + listOf(NO_CORRESPONDING_PROPERTY)) { override fun logic(node: ASTNode) { if (node.elementType == CLASS_BODY) { findAllProperties(node) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/PropertyAccessorFields.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/PropertyAccessorFields.kt index 5562494b97..10d05e6136 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/PropertyAccessorFields.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/PropertyAccessorFields.kt @@ -21,9 +21,9 @@ import org.jetbrains.kotlin.psi.KtProperty * Rule check that never use the name of a variable in the custom getter or setter */ class PropertyAccessorFields(configRules: List) : DiktatRule( - "getter-setter-fields", - configRules, - listOf(WRONG_NAME_OF_VARIABLE_INSIDE_ACCESSOR)) { + "getter-setter-fields", + configRules, + listOf(WRONG_NAME_OF_VARIABLE_INSIDE_ACCESSOR)) { override fun logic(node: ASTNode) { if (node.elementType == PROPERTY_ACCESSOR) { checkPropertyAccessor(node) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/TrivialPropertyAccessors.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/TrivialPropertyAccessors.kt index 5436c98257..899f71f390 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/TrivialPropertyAccessors.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/TrivialPropertyAccessors.kt @@ -27,9 +27,9 @@ import org.jetbrains.kotlin.psi.KtPropertyAccessor * This rule checks if there are any trivial getters and setters and, if so, deletes them */ class TrivialPropertyAccessors(configRules: List) : DiktatRule( - "trivial-property-accessors", - configRules, - listOf(TRIVIAL_ACCESSORS_ARE_NOT_RECOMMENDED)) { + "trivial-property-accessors", + configRules, + listOf(TRIVIAL_ACCESSORS_ARE_NOT_RECOMMENDED)) { override fun logic(node: ASTNode) { if (node.elementType == PROPERTY_ACCESSOR) { handlePropertyAccessors(node) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/UselessSupertype.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/UselessSupertype.kt index 2047f0b88d..9b63c527fb 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/UselessSupertype.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/UselessSupertype.kt @@ -32,9 +32,9 @@ import java.util.HashMap * fixme can't fix supertypes that are defined in other files. */ class UselessSupertype(configRules: List) : DiktatRule( - "useless-override", - configRules, - listOf(USELESS_SUPERTYPE)) { + "useless-override", + configRules, + listOf(USELESS_SUPERTYPE)) { override fun logic(node: ASTNode) { if (node.elementType == CLASS) { checkClass(node) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/AbstractClassesRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/AbstractClassesRule.kt index 8a864f43b7..66b9fcc8c6 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/AbstractClassesRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/AbstractClassesRule.kt @@ -20,9 +20,9 @@ import org.jetbrains.kotlin.com.intellij.lang.ASTNode * Checks if abstract class has any abstract method. If not, warns that class should not be abstract */ class AbstractClassesRule(configRules: List) : DiktatRule( - "abstract-classes", - configRules, - listOf(CLASS_SHOULD_NOT_BE_ABSTRACT)) { + "abstract-classes", + configRules, + listOf(CLASS_SHOULD_NOT_BE_ABSTRACT)) { override fun logic(node: ASTNode) { if (node.elementType == CLASS) { val classBody = node.getFirstChildWithType(CLASS_BODY) ?: return diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/CompactInitialization.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/CompactInitialization.kt index 5b17102eb3..f9dfcf8b9c 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/CompactInitialization.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/CompactInitialization.kt @@ -28,9 +28,9 @@ import org.jetbrains.kotlin.psi.psiUtil.startOffset * e.g `this@Foo`. But for this we need a mechanism to determine declaration scope and it's label. */ class CompactInitialization(configRules: List) : DiktatRule( - "class-compact-initialization", - configRules, - listOf(COMPACT_OBJECT_INITIALIZATION)) { + "class-compact-initialization", + configRules, + listOf(COMPACT_OBJECT_INITIALIZATION)) { private val kotlinParser by lazy { KotlinParser() } override fun logic(node: ASTNode) { diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/DataClassesRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/DataClassesRule.kt index 2c205907aa..eede606cbf 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/DataClassesRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/DataClassesRule.kt @@ -32,9 +32,9 @@ import org.jetbrains.kotlin.psi.KtPrimaryConstructor * This rule checks if class can be made as data class */ class DataClassesRule(configRules: List) : DiktatRule( - "data-classes", - configRules, - listOf(USE_DATA_CLASS)) { + "data-classes", + configRules, + listOf(USE_DATA_CLASS)) { override fun logic(node: ASTNode) { if (node.elementType == CLASS) { handleClass(node) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/InlineClassesRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/InlineClassesRule.kt index a2edfc58f8..9474688f6a 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/InlineClassesRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/InlineClassesRule.kt @@ -26,9 +26,9 @@ import org.jetbrains.kotlin.psi.psiUtil.visibilityModifierType * This rule checks if inline class can be used. */ class InlineClassesRule(configRules: List) : DiktatRule( - "inline-classes", - configRules, - listOf(INLINE_CLASS_CAN_BE_USED)) { + "inline-classes", + configRules, + listOf(INLINE_CLASS_CAN_BE_USED)) { override fun logic(node: ASTNode) { val configuration by configRules.getCommonConfiguration() if (node.elementType == CLASS && configuration.kotlinVersion >= ktVersion) { diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/SingleConstructorRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/SingleConstructorRule.kt index b75538529f..6924e6a508 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/SingleConstructorRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/SingleConstructorRule.kt @@ -34,9 +34,9 @@ import org.jetbrains.kotlin.psi.psiUtil.collectDescendantsOfType * Secondary constructor is converted into primary, statements that are not assignments are moved into an `init` block. */ class SingleConstructorRule(configRules: List) : DiktatRule( - "single-constructor", - configRules, - listOf(SINGLE_CONSTRUCTOR_SHOULD_BE_PRIMARY)) { + "single-constructor", + configRules, + listOf(SINGLE_CONSTRUCTOR_SHOULD_BE_PRIMARY)) { private val kotlinParser by lazy { KotlinParser() } override fun logic(node: ASTNode) { diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/SingleInitRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/SingleInitRule.kt index a8ac3cc5a2..8e0fbf7649 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/SingleInitRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/SingleInitRule.kt @@ -26,9 +26,9 @@ import org.jetbrains.kotlin.psi.psiUtil.children * The rule that checks whether a class has a single `init` block or multiple. Having multiple `init` blocks is a bad practice. */ class SingleInitRule(configRules: List) : DiktatRule( - "multiple-init-block", - configRules, - listOf(MULTIPLE_INIT_BLOCKS)) { + "multiple-init-block", + configRules, + listOf(MULTIPLE_INIT_BLOCKS)) { override fun logic(node: ASTNode) { when (node.elementType) { CLASS_BODY -> handleInitBlocks(node) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/StatelessClassesRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/StatelessClassesRule.kt index 70778ddc5d..3512aaa33e 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/StatelessClassesRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/StatelessClassesRule.kt @@ -28,9 +28,9 @@ import org.jetbrains.kotlin.psi.KtClass * This rule checks if class is stateless and if so changes it to object. */ class StatelessClassesRule(configRules: List) : DiktatRule( - "stateless-class", - configRules, - listOf(OBJECT_IS_PREFERRED)) { + "stateless-class", + configRules, + listOf(OBJECT_IS_PREFERRED)) { override fun logic(node: ASTNode) { // Fixme: We should find interfaces in all project and then check them if (node.elementType == FILE) { From 4da662a02837708954f91be93a44e51e78d01e02 Mon Sep 17 00:00:00 2001 From: aktsay6 Date: Tue, 9 Feb 2021 14:53:37 +0300 Subject: [PATCH 07/20] bugfix/newlinesrule(#748) ### What's done: * Fixed bugs --- .../diktat/ruleset/rules/chapter3/files/NewlinesRule.kt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/NewlinesRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/NewlinesRule.kt index 6fd0653518..ecd61df6f5 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/NewlinesRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/NewlinesRule.kt @@ -354,14 +354,15 @@ class NewlinesRule(configRules: List) : DiktatRule( } WRONG_NEWLINES.warnAndFix(configRules, emitWarn, isFixMode, freeText, node.startOffset, node) { node.appendNewlineMergingWhiteSpace( - it.first() + list.first() .treePrev .takeIf { it.elementType == WHITE_SPACE }, - it.first() + list.first() ) } } + @Suppress("AVOID_NULL_CHECK") private fun handleValueParameterList(node: ASTNode, entryType: String) = node .children() .filter { @@ -371,7 +372,7 @@ class NewlinesRule(configRules: List) : DiktatRule( .toList() .takeIf { it.isNotEmpty() } ?.let { invalidCommas -> - val warnText = if (node.getParentIdentifier() ?: false) { + val warnText = if (node.getParentIdentifier() != null) { "$entryType should be placed on different lines in declaration of <${node.getParentIdentifier()}>" } else { "$entryType should be placed on different lines" From 1627b36c331e0ed8acad7d753e41790da80eb412 Mon Sep 17 00:00:00 2001 From: aktsay6 Date: Tue, 9 Feb 2021 14:53:56 +0300 Subject: [PATCH 08/20] bugfix/newlinesrule(#748) ### What's done: * Fixed bugs --- .../diktat/ruleset/rules/chapter2/comments/HeaderCommentRule.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/comments/HeaderCommentRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/comments/HeaderCommentRule.kt index eadda8a774..0b7541f012 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/comments/HeaderCommentRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/comments/HeaderCommentRule.kt @@ -43,7 +43,7 @@ class HeaderCommentRule(configRules: List) : DiktatRule( "header-comment", configRules, listOf(HEADER_MISSING_IN_NON_SINGLE_CLASS_FILE, HEADER_MISSING_OR_WRONG_COPYRIGHT, HEADER_NOT_BEFORE_PACKAGE, - HEADER_NOT_BEFORE_PACKAGE, HEADER_WRONG_FORMAT, WRONG_COPYRIGHT_YEAR)) { + HEADER_NOT_BEFORE_PACKAGE, HEADER_WRONG_FORMAT, WRONG_COPYRIGHT_YEAR)) { override fun logic(node: ASTNode) { if (node.elementType == FILE) { checkCopyright(node) From 0d8431e82d946810d8f7ed3ff02d7785573e553c Mon Sep 17 00:00:00 2001 From: aktsay6 Date: Tue, 9 Feb 2021 14:57:11 +0300 Subject: [PATCH 09/20] bugfix/newlinesrule(#748) ### What's done: * Fixed bugs --- .../cqfn/diktat/ruleset/rules/chapter3/files/NewlinesRule.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/NewlinesRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/NewlinesRule.kt index ecd61df6f5..c2084967ab 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/NewlinesRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/NewlinesRule.kt @@ -362,7 +362,7 @@ class NewlinesRule(configRules: List) : DiktatRule( } } - @Suppress("AVOID_NULL_CHECK") + @Suppress("AVOID_NULL_CHECKS") private fun handleValueParameterList(node: ASTNode, entryType: String) = node .children() .filter { From 67d6d0cd371d1438519086df7a717c87b2ec39f0 Mon Sep 17 00:00:00 2001 From: aktsay6 Date: Tue, 9 Feb 2021 15:38:16 +0300 Subject: [PATCH 10/20] bugfix/newlinesrule(#748) ### What's done: * Fixed bugs --- .../rules/chapter3/files/NewlinesRule.kt | 3 ++- .../chapter3/files/NewlinesRuleWarnTest.kt | 18 +++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/NewlinesRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/NewlinesRule.kt index c2084967ab..59b1d12349 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/NewlinesRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/NewlinesRule.kt @@ -51,6 +51,7 @@ import com.pinterest.ktlint.core.ast.ElementType.PLUS import com.pinterest.ktlint.core.ast.ElementType.PLUSEQ import com.pinterest.ktlint.core.ast.ElementType.POSTFIX_EXPRESSION import com.pinterest.ktlint.core.ast.ElementType.PRIMARY_CONSTRUCTOR +import com.pinterest.ktlint.core.ast.ElementType.REFERENCE_EXPRESSION import com.pinterest.ktlint.core.ast.ElementType.RETURN import com.pinterest.ktlint.core.ast.ElementType.RETURN_KEYWORD import com.pinterest.ktlint.core.ast.ElementType.SAFE_ACCESS @@ -310,7 +311,7 @@ class NewlinesRule(configRules: List) : DiktatRule( return } - if (node.elementType == VALUE_ARGUMENT_LIST && !node.hasParent(SUPER_TYPE_LIST)) { + if (node.elementType == VALUE_ARGUMENT_LIST && node.treePrev != null && node.treePrev.elementType == REFERENCE_EXPRESSION) { // check that it is not function invocation, but only supertype constructor calls return } diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/files/NewlinesRuleWarnTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/files/NewlinesRuleWarnTest.kt index 153b55c392..7566dacb50 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/files/NewlinesRuleWarnTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/files/NewlinesRuleWarnTest.kt @@ -614,7 +614,9 @@ class NewlinesRuleWarnTest : LintTestBase(::NewlinesRule) { LintError(3, 10, ruleId, "${WRONG_NEWLINES.warnText()} value parameters should be placed on different lines in declaration of ", true), LintError(4, 16, ruleId, "${WRONG_NEWLINES.warnText()} first parameter should be placed on a separate line or all other parameters " + "should be aligned with it in declaration of ", true), - LintError(4, 16, ruleId, "${WRONG_NEWLINES.warnText()} value parameters should be placed on different lines in declaration of ", true) + LintError(4, 16, ruleId, "${WRONG_NEWLINES.warnText()} value parameters should be placed on different lines in declaration of ", true), + LintError(4, 62, ruleId, "${WRONG_NEWLINES.warnText()} first value argument (arg1) should be placed on the new line or all other parameters should be aligned with it", true), + LintError(4, 62, ruleId, "${WRONG_NEWLINES.warnText()} value arguments should be placed on different lines", true) ) } @@ -657,6 +659,20 @@ class NewlinesRuleWarnTest : LintTestBase(::NewlinesRule) { ) } + @Test + @Tag(WarningNames.WRONG_NEWLINES) + fun `should not raise warning on list params`() { + lintMethod( + """ + |class SomeRule(configRules: List) : Rule("id", + |configRules, + |listOf("foo", "baz", "triple", "bar")) { + | + |} + """.trimMargin() + ) + } + @Test @Tag(WarningNames.WRONG_NEWLINES) fun `should raise warning on value arguments`() { From f360824bd5fc21620149cff44b1cfd3cc3d1db4e Mon Sep 17 00:00:00 2001 From: aktsay6 Date: Tue, 9 Feb 2021 15:40:16 +0300 Subject: [PATCH 11/20] bugfix/newlinesrule(#748) ### What's done: * Fixed bugs --- .../cqfn/diktat/ruleset/chapter3/files/NewlinesRuleWarnTest.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/files/NewlinesRuleWarnTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/files/NewlinesRuleWarnTest.kt index 7566dacb50..6105e78abe 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/files/NewlinesRuleWarnTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/files/NewlinesRuleWarnTest.kt @@ -615,7 +615,8 @@ class NewlinesRuleWarnTest : LintTestBase(::NewlinesRule) { LintError(4, 16, ruleId, "${WRONG_NEWLINES.warnText()} first parameter should be placed on a separate line or all other parameters " + "should be aligned with it in declaration of ", true), LintError(4, 16, ruleId, "${WRONG_NEWLINES.warnText()} value parameters should be placed on different lines in declaration of ", true), - LintError(4, 62, ruleId, "${WRONG_NEWLINES.warnText()} first value argument (arg1) should be placed on the new line or all other parameters should be aligned with it", true), + LintError(4, 62, ruleId, "${WRONG_NEWLINES.warnText()} first value argument (arg1) should be placed on the new line or " + + "all other parameters should be aligned with it", true), LintError(4, 62, ruleId, "${WRONG_NEWLINES.warnText()} value arguments should be placed on different lines", true) ) } From b22652b29b6ce4669f7099d76294927610e1996c Mon Sep 17 00:00:00 2001 From: aktsay6 Date: Tue, 9 Feb 2021 15:43:22 +0300 Subject: [PATCH 12/20] bugfix/newlinesrule(#748) ### What's done: * Fixed bugs --- .../cqfn/diktat/ruleset/chapter3/files/NewlinesRuleWarnTest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/files/NewlinesRuleWarnTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/files/NewlinesRuleWarnTest.kt index 6105e78abe..06973b02e1 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/files/NewlinesRuleWarnTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/files/NewlinesRuleWarnTest.kt @@ -664,7 +664,7 @@ class NewlinesRuleWarnTest : LintTestBase(::NewlinesRule) { @Tag(WarningNames.WRONG_NEWLINES) fun `should not raise warning on list params`() { lintMethod( - """ + """ |class SomeRule(configRules: List) : Rule("id", |configRules, |listOf("foo", "baz", "triple", "bar")) { From 2a2e2366ade01689b1fdbbc18d5b64c466627096 Mon Sep 17 00:00:00 2001 From: aktsay6 Date: Tue, 9 Feb 2021 15:48:54 +0300 Subject: [PATCH 13/20] bugfix/newlinesrule(#748) ### What's done: * Fixed bugs --- .../test/paragraph3/newlines/ParameterListExpected.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/diktat-rules/src/test/resources/test/paragraph3/newlines/ParameterListExpected.kt b/diktat-rules/src/test/resources/test/paragraph3/newlines/ParameterListExpected.kt index c18ac4bf33..cdcff7da86 100644 --- a/diktat-rules/src/test/resources/test/paragraph3/newlines/ParameterListExpected.kt +++ b/diktat-rules/src/test/resources/test/paragraph3/newlines/ParameterListExpected.kt @@ -18,7 +18,10 @@ val arg1: Int, constructor( arg1: Int, arg2: String, - arg3: String) : this(arg1, 0, 0) { } + arg3: String) : this( +arg1, + 0, + 0) { } } class Foo(val arg1: Int, From 46b1568c882833fa4d193427d9c77ec2932b39bb Mon Sep 17 00:00:00 2001 From: aktsay6 Date: Tue, 9 Feb 2021 16:07:24 +0300 Subject: [PATCH 14/20] bugfix/newlinesrule(#748) ### What's done: * Fixed bugs --- .../cqfn/diktat/ruleset/rules/chapter3/files/NewlinesRule.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/NewlinesRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/NewlinesRule.kt index 59b1d12349..bf98038dfe 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/NewlinesRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/files/NewlinesRule.kt @@ -311,7 +311,7 @@ class NewlinesRule(configRules: List) : DiktatRule( return } - if (node.elementType == VALUE_ARGUMENT_LIST && node.treePrev != null && node.treePrev.elementType == REFERENCE_EXPRESSION) { + if (node.elementType == VALUE_ARGUMENT_LIST && node.siblings(forward = false).any { it.elementType == REFERENCE_EXPRESSION }) { // check that it is not function invocation, but only supertype constructor calls return } From 443ce0840a9675447374679b598d90f18623d6ae Mon Sep 17 00:00:00 2001 From: aktsay6 Date: Tue, 9 Feb 2021 16:28:12 +0300 Subject: [PATCH 15/20] bugfix/newlinesrule(#748) ### What's done: * Fixed bugs --- .../org/cqfn/diktat/ruleset/constants/Warnings.kt | 7 ++++++- .../diktat/ruleset/rules/chapter1/IdentifierNaming.kt | 6 +++++- .../chapter3/BracesInConditionalsAndLoopsRule.kt | 7 ++++++- .../rules/chapter3/ClassLikeStructuresOrderRule.kt | 7 ++++++- .../ruleset/rules/chapter6/classes/DataClassesRule.kt | 6 +++++- .../org/cqfn/diktat/ruleset/utils/AstNodeUtils.kt | 6 +++++- .../org/cqfn/diktat/ruleset/utils/KotlinParser.kt | 6 +++++- .../diktat/ruleset/utils/PositionInTextLocator.kt | 6 +++++- .../diktat/ruleset/utils/search/VariablesSearch.kt | 6 +++++- .../utils/search/VariablesWithAssignmentSearch.kt | 11 +++++++++-- .../ruleset/chapter1/IdentifierNamingWarnTest.kt | 6 +++++- .../ruleset/chapter2/CommentsFormattingFixTest.kt | 7 ++++++- .../cqfn/diktat/ruleset/chapter2/KdocMethodsTest.kt | 8 ++++++-- .../org/cqfn/diktat/ruleset/utils/AstNodeUtilsTest.kt | 6 +++++- .../org/cqfn/diktat/ruleset/utils/KotlinParserTest.kt | 6 +++++- .../test/kotlin/org/cqfn/diktat/util/FixTestBase.kt | 3 ++- 16 files changed, 86 insertions(+), 18 deletions(-) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/constants/Warnings.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/constants/Warnings.kt index 92d00419a9..2940d03f5f 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/constants/Warnings.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/constants/Warnings.kt @@ -18,7 +18,12 @@ typealias ListOfPairs = MutableList> * @property canBeAutoCorrected whether this inspection can automatically fix the code * @property ruleId number of the inspection according to []diktat code style](https://www.cqfn.org/diKTat/info/guide/diktat-coding-convention.html) */ -@Suppress("ForbiddenComment", "MagicNumber", "WRONG_DECLARATIONS_ORDER", "MaxLineLength") +@Suppress( + "ForbiddenComment", + "MagicNumber", + "WRONG_DECLARATIONS_ORDER", + "MaxLineLength" +) enum class Warnings( val canBeAutoCorrected: Boolean, val ruleId: String, diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter1/IdentifierNaming.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter1/IdentifierNaming.kt index ece3047eca..5974a76ad5 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter1/IdentifierNaming.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter1/IdentifierNaming.kt @@ -150,7 +150,11 @@ class IdentifierNaming(configRules: List) : DiktatRule( /** * all checks for case and naming for vals/vars/constants */ - @Suppress("SAY_NO_TO_VAR", "TOO_LONG_FUNCTION", "ComplexMethod") + @Suppress( + "SAY_NO_TO_VAR", + "TOO_LONG_FUNCTION", + "ComplexMethod" + ) private fun checkVariableName(node: ASTNode): List { // special case for Destructuring declarations that can be treated as parameters in lambda: var namesOfVariables = extractVariableIdentifiers(node) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/BracesInConditionalsAndLoopsRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/BracesInConditionalsAndLoopsRule.kt index 4b72d25e09..40ce08799a 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/BracesInConditionalsAndLoopsRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/BracesInConditionalsAndLoopsRule.kt @@ -50,7 +50,12 @@ class BracesInConditionalsAndLoopsRule(configRules: List) : DiktatR /** * Check braces in if-else statements. Check for both IF and ELSE needs to be done in one method to discover single-line if-else statements correctly. */ - @Suppress("ForbiddenComment", "UnsafeCallOnNullableType", "ComplexMethod", "TOO_LONG_FUNCTION") + @Suppress( + "ForbiddenComment", + "UnsafeCallOnNullableType", + "ComplexMethod", + "TOO_LONG_FUNCTION" + ) private fun checkIfNode(node: ASTNode) { val ifPsi = node.psi as KtIfExpression val thenNode = ifPsi.then?.node diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/ClassLikeStructuresOrderRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/ClassLikeStructuresOrderRule.kt index 49a1f37e52..bcfddb8934 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/ClassLikeStructuresOrderRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/ClassLikeStructuresOrderRule.kt @@ -53,7 +53,12 @@ class ClassLikeStructuresOrderRule(configRules: List) : DiktatRule( } } - @Suppress("UnsafeCallOnNullableType", "LongMethod", "ComplexMethod", "TOO_LONG_FUNCTION") + @Suppress( + "UnsafeCallOnNullableType", + "LongMethod", + "ComplexMethod", + "TOO_LONG_FUNCTION" + ) private fun checkDeclarationsOrderInClass(node: ASTNode) { val allProperties = node.getChildren(TokenSet.create(PROPERTY)) val constProperties = allProperties.filter { it.findLeafWithSpecificType(CONST_KEYWORD) != null }.toMutableList() diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/DataClassesRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/DataClassesRule.kt index eede606cbf..c7461d5d37 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/DataClassesRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/classes/DataClassesRule.kt @@ -56,7 +56,11 @@ class DataClassesRule(configRules: List) : DiktatRule( USE_DATA_CLASS.warn(configRules, emitWarn, isFixMode, "${(node.psi as KtClass).name}", node.startOffset, node) } - @Suppress("UnsafeCallOnNullableType", "FUNCTION_BOOLEAN_PREFIX", "ComplexMethod") + @Suppress( + "UnsafeCallOnNullableType", + "FUNCTION_BOOLEAN_PREFIX", + "ComplexMethod" + ) private fun ASTNode.canBeDataClass(): Boolean { val isNotPropertyInClassBody = findChildByType(CLASS_BODY)?.let { (it.psi as KtClassBody).properties.isEmpty() } ?: true val hasPropertyInConstructor = findChildByType(PRIMARY_CONSTRUCTOR) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/AstNodeUtils.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/AstNodeUtils.kt index 8352db3b0f..a7a52b8a82 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/AstNodeUtils.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/AstNodeUtils.kt @@ -3,7 +3,11 @@ * FixMe: fix suppressed inspections on KDocs */ -@file:Suppress("FILE_NAME_MATCH_CLASS", "KDOC_WITHOUT_RETURN_TAG", "KDOC_WITHOUT_PARAM_TAG") +@file:Suppress( + "FILE_NAME_MATCH_CLASS", + "KDOC_WITHOUT_RETURN_TAG", + "KDOC_WITHOUT_PARAM_TAG" +) package org.cqfn.diktat.ruleset.utils diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/KotlinParser.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/KotlinParser.kt index d5e0cbc0a6..3a994703f7 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/KotlinParser.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/KotlinParser.kt @@ -89,7 +89,11 @@ class KotlinParser { * Else, try to create node based on text. * If this node will contain ERROR_ELEMENT type children this mean that cannot create node based on this text */ - @Suppress("UnsafeCallOnNullableType", "TOO_LONG_FUNCTION", "SAY_NO_TO_VAR") + @Suppress( + "UnsafeCallOnNullableType", + "TOO_LONG_FUNCTION", + "SAY_NO_TO_VAR" + ) private fun makeNode(text: String, isPackage: Boolean = false): ASTNode? { if (text.isEmpty()) { return null diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/PositionInTextLocator.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/PositionInTextLocator.kt index cb7906d23d..28d8fd2874 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/PositionInTextLocator.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/PositionInTextLocator.kt @@ -7,7 +7,11 @@ package org.cqfn.diktat.ruleset.utils internal typealias LineAndColumn = Pair -@Suppress("MISSING_KDOC_ON_FUNCTION", "KDOC_WITHOUT_PARAM_TAG", "KDOC_WITHOUT_RETURN_TAG") +@Suppress( + "MISSING_KDOC_ON_FUNCTION", + "KDOC_WITHOUT_PARAM_TAG", + "KDOC_WITHOUT_RETURN_TAG" +) private class SegmentTree(sortedArray: IntArray) { private val segments: List = sortedArray .dropLast(1) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/search/VariablesSearch.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/search/VariablesSearch.kt index fbc1789e8d..86985471e4 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/search/VariablesSearch.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/search/VariablesSearch.kt @@ -1,4 +1,8 @@ -@file:Suppress("KDOC_NO_CONSTRUCTOR_PROPERTY", "MISSING_KDOC_CLASS_ELEMENTS", "MISSING_KDOC_ON_FUNCTION", "KDOC_WITHOUT_PARAM_TAG", +@file:Suppress( + "KDOC_NO_CONSTRUCTOR_PROPERTY", + "MISSING_KDOC_CLASS_ELEMENTS", + "MISSING_KDOC_ON_FUNCTION", + "KDOC_WITHOUT_PARAM_TAG", "KDOC_WITHOUT_RETURN_TAG") package org.cqfn.diktat.ruleset.utils.search diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/search/VariablesWithAssignmentSearch.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/search/VariablesWithAssignmentSearch.kt index bc9ec08ce3..4cdf7e7f3f 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/search/VariablesWithAssignmentSearch.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/search/VariablesWithAssignmentSearch.kt @@ -1,5 +1,12 @@ -@file:Suppress("MISSING_KDOC_TOP_LEVEL", "KDOC_NO_CONSTRUCTOR_PROPERTY", "MISSING_KDOC_CLASS_ELEMENTS", "MISSING_KDOC_ON_FUNCTION", "KDOC_WITHOUT_PARAM_TAG", - "KDOC_WITHOUT_RETURN_TAG", "KDOC_NO_EMPTY_TAGS") +@file:Suppress( + "MISSING_KDOC_TOP_LEVEL", + "KDOC_NO_CONSTRUCTOR_PROPERTY", + "MISSING_KDOC_CLASS_ELEMENTS", + "MISSING_KDOC_ON_FUNCTION", + "KDOC_WITHOUT_PARAM_TAG", + "KDOC_WITHOUT_RETURN_TAG", + "KDOC_NO_EMPTY_TAGS" +) package org.cqfn.diktat.ruleset.utils.search diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter1/IdentifierNamingWarnTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter1/IdentifierNamingWarnTest.kt index ea4e5b813d..22ff9a0a90 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter1/IdentifierNamingWarnTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter1/IdentifierNamingWarnTest.kt @@ -122,7 +122,11 @@ class IdentifierNamingWarnTest : LintTestBase(::IdentifierNaming) { } @Test - @Tags(Tag(WarningNames.CLASS_NAME_INCORRECT), Tag(WarningNames.VARIABLE_NAME_INCORRECT_FORMAT), Tag(WarningNames.CONSTANT_UPPERCASE)) + @Tags( + Tag(WarningNames.CLASS_NAME_INCORRECT), + Tag(WarningNames.VARIABLE_NAME_INCORRECT_FORMAT), + Tag(WarningNames.CONSTANT_UPPERCASE) + ) fun `check identifiers case format (check - negative)`() { val code = """ diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter2/CommentsFormattingFixTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter2/CommentsFormattingFixTest.kt index 43150abcfe..53d0f3a217 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter2/CommentsFormattingFixTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter2/CommentsFormattingFixTest.kt @@ -19,7 +19,12 @@ class CommentsFormattingFixTest : FixTestBase("test/paragraph2/kdoc/", ::Comment } @Test - @Tags(Tag(WRONG_NEWLINES_AROUND_KDOC), Tag(COMMENT_WHITE_SPACE), Tag(IF_ELSE_COMMENTS), Tag(FIRST_COMMENT_NO_BLANK_LINE)) + @Tags( + Tag(WRONG_NEWLINES_AROUND_KDOC), + Tag(COMMENT_WHITE_SPACE), + Tag(IF_ELSE_COMMENTS), + Tag(FIRST_COMMENT_NO_BLANK_LINE) + ) fun `check lines and spaces in comments`() { fixAndCompare("KdocCodeBlocksFormattingExpected.kt", "KdocCodeBlocksFormattingTest.kt") } diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter2/KdocMethodsTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter2/KdocMethodsTest.kt index 0e3b8fa47d..5f690224ea 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter2/KdocMethodsTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter2/KdocMethodsTest.kt @@ -51,8 +51,12 @@ class KdocMethodsTest : LintTestBase(::KdocMethods) { } @Test - @Tags(Tag(WarningNames.KDOC_WITHOUT_PARAM_TAG), Tag(WarningNames.KDOC_WITHOUT_RETURN_TAG), Tag(WarningNames.KDOC_WITHOUT_THROWS_TAG), - Tag(WarningNames.MISSING_KDOC_ON_FUNCTION)) + @Tags( + Tag(WarningNames.KDOC_WITHOUT_PARAM_TAG), + Tag(WarningNames.KDOC_WITHOUT_RETURN_TAG), + Tag(WarningNames.KDOC_WITHOUT_THROWS_TAG), + Tag(WarningNames.MISSING_KDOC_ON_FUNCTION) + ) fun `Warning should not be triggered for functions in tests`() { val validCode = "@Test $funCode" val complexAnnotationCode = "@Anno(test = [\"args\"]) $funCode" diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/utils/AstNodeUtilsTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/utils/AstNodeUtilsTest.kt index 0f49f436c8..c1c7089986 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/utils/AstNodeUtilsTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/utils/AstNodeUtilsTest.kt @@ -1,4 +1,8 @@ -@file:Suppress("HEADER_MISSING_IN_NON_SINGLE_CLASS_FILE", "LOCAL_VARIABLE_EARLY_DECLARATION", "AVOID_NULL_CHECKS") +@file:Suppress( + "HEADER_MISSING_IN_NON_SINGLE_CLASS_FILE", + "LOCAL_VARIABLE_EARLY_DECLARATION", + "AVOID_NULL_CHECKS" +) package org.cqfn.diktat.ruleset.utils diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/utils/KotlinParserTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/utils/KotlinParserTest.kt index ff1ab3e719..284b7de51a 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/utils/KotlinParserTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/utils/KotlinParserTest.kt @@ -96,7 +96,11 @@ class KotlinParserTest { } @Test - @Suppress("UnsafeCallOnNullableType", "TOO_LONG_FUNCTION", "AVOID_NULL_CHECKS") + @Suppress( + "UnsafeCallOnNullableType", + "TOO_LONG_FUNCTION", + "AVOID_NULL_CHECKS" + ) fun `test multiline class code compare with applyToCode`() { val emptyClass = """ |package org.cqfn.diktat.ruleset.utils diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/util/FixTestBase.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/util/FixTestBase.kt index daf3fa71f1..94ad54041d 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/util/FixTestBase.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/util/FixTestBase.kt @@ -22,7 +22,8 @@ open class FixTestBase(protected val resourceFilePath: String, ruleSupplier: (rulesConfigList: List) -> Rule, rulesConfigList: List? = null, cb: LintErrorCallback = defaultCallback) : this( - resourceFilePath, { overrideRulesConfigList -> DiktatRuleSetProvider4Test(ruleSupplier, overrideRulesConfigList) }, + resourceFilePath, + { overrideRulesConfigList -> DiktatRuleSetProvider4Test(ruleSupplier, overrideRulesConfigList) }, cb, rulesConfigList ) From 10bfb94e737ebcde55e6c814a93b21696e49d2d7 Mon Sep 17 00:00:00 2001 From: aktsay6 Date: Tue, 9 Feb 2021 16:33:53 +0300 Subject: [PATCH 16/20] bugfix/newlinesrule(#748) ### What's done: * Fixed bugs --- .../kotlin/org/cqfn/diktat/ruleset/constants/Warnings.kt | 3 ++- .../org/cqfn/diktat/ruleset/chapter2/KdocMethodsTest.kt | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/constants/Warnings.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/constants/Warnings.kt index 2940d03f5f..495c6c2aab 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/constants/Warnings.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/constants/Warnings.kt @@ -22,7 +22,8 @@ typealias ListOfPairs = MutableList> "ForbiddenComment", "MagicNumber", "WRONG_DECLARATIONS_ORDER", - "MaxLineLength" + "MaxLineLength", + "WRONG_NEWLINES" ) enum class Warnings( val canBeAutoCorrected: Boolean, diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter2/KdocMethodsTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter2/KdocMethodsTest.kt index 5f690224ea..9002b23029 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter2/KdocMethodsTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter2/KdocMethodsTest.kt @@ -27,7 +27,11 @@ class KdocMethodsTest : LintTestBase(::KdocMethods) { """.trimIndent() @Test - @Tags(Tag(WarningNames.KDOC_WITHOUT_PARAM_TAG), Tag(WarningNames.KDOC_WITHOUT_RETURN_TAG), Tag(WarningNames.KDOC_WITHOUT_THROWS_TAG)) + @Tags( + Tag(WarningNames.KDOC_WITHOUT_PARAM_TAG), + Tag(WarningNames.KDOC_WITHOUT_RETURN_TAG), + Tag(WarningNames.KDOC_WITHOUT_THROWS_TAG) + ) fun `Accessible methods with parameters, return type and throws should have proper KDoc (positive example)`() { val validCode = """ /** From 09d52ce748080b2ab20cdbc95276eff554b8ad25 Mon Sep 17 00:00:00 2001 From: aktsay6 Date: Tue, 9 Feb 2021 16:39:39 +0300 Subject: [PATCH 17/20] bugfix/newlinesrule(#748) ### What's done: * Fixed bugs --- .../ruleset/utils/search/VariablesWithUsagesSearch.kt | 11 +++++++++-- .../diktat/ruleset/chapter2/KdocMethodsFixTest.kt | 6 +++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/search/VariablesWithUsagesSearch.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/search/VariablesWithUsagesSearch.kt index c18d7e115f..ccea032ad0 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/search/VariablesWithUsagesSearch.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/search/VariablesWithUsagesSearch.kt @@ -1,5 +1,12 @@ -@file:Suppress("MISSING_KDOC_TOP_LEVEL", "KDOC_NO_CONSTRUCTOR_PROPERTY", "MISSING_KDOC_CLASS_ELEMENTS", "MISSING_KDOC_ON_FUNCTION", "KDOC_WITHOUT_PARAM_TAG", - "KDOC_WITHOUT_RETURN_TAG", "KDOC_NO_EMPTY_TAGS") +@file:Suppress( + "MISSING_KDOC_TOP_LEVEL", + "KDOC_NO_CONSTRUCTOR_PROPERTY", + "MISSING_KDOC_CLASS_ELEMENTS", + "MISSING_KDOC_ON_FUNCTION", + "KDOC_WITHOUT_PARAM_TAG", + "KDOC_WITHOUT_RETURN_TAG", + "KDOC_NO_EMPTY_TAGS" +) package org.cqfn.diktat.ruleset.utils.search diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter2/KdocMethodsFixTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter2/KdocMethodsFixTest.kt index 440f5cdfdb..ae8a5074c9 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter2/KdocMethodsFixTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter2/KdocMethodsFixTest.kt @@ -47,7 +47,11 @@ class KdocMethodsFixTest : FixTestBase("test/paragraph2/kdoc/package/src/main/ko } @Test - @Tags(Tag(WarningNames.KDOC_WITHOUT_PARAM_TAG), Tag(WarningNames.KDOC_WITHOUT_RETURN_TAG), Tag(WarningNames.KDOC_WITHOUT_THROWS_TAG)) + @Tags( + Tag(WarningNames.KDOC_WITHOUT_PARAM_TAG), + Tag(WarningNames.KDOC_WITHOUT_RETURN_TAG), + Tag(WarningNames.KDOC_WITHOUT_THROWS_TAG) + ) fun `KdocMethods rule should reformat code (full example)`() { fixAndCompare("KdocMethodsFullExpected.kt", "KdocMethodsFullTested.kt") } From bf741f863c4a916ff81d50cc58d6fbd165bb6026 Mon Sep 17 00:00:00 2001 From: aktsay6 Date: Tue, 9 Feb 2021 16:46:33 +0300 Subject: [PATCH 18/20] bugfix/newlinesrule(#748) ### What's done: * Fixed bugs --- .../main/kotlin/org/cqfn/diktat/plugin/gradle/Utils.kt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/diktat-gradle-plugin/src/main/kotlin/org/cqfn/diktat/plugin/gradle/Utils.kt b/diktat-gradle-plugin/src/main/kotlin/org/cqfn/diktat/plugin/gradle/Utils.kt index 58ee144069..12cdf78f1c 100644 --- a/diktat-gradle-plugin/src/main/kotlin/org/cqfn/diktat/plugin/gradle/Utils.kt +++ b/diktat-gradle-plugin/src/main/kotlin/org/cqfn/diktat/plugin/gradle/Utils.kt @@ -8,8 +8,14 @@ package org.cqfn.diktat.plugin.gradle import groovy.lang.Closure -@Suppress("MISSING_KDOC_TOP_LEVEL", "MISSING_KDOC_CLASS_ELEMENTS", "KDOC_NO_CONSTRUCTOR_PROPERTY", - "MISSING_KDOC_ON_FUNCTION", "KDOC_WITHOUT_PARAM_TAG", "KDOC_WITHOUT_RETURN_TAG") +@Suppress( + "MISSING_KDOC_TOP_LEVEL", + "MISSING_KDOC_CLASS_ELEMENTS", + "KDOC_NO_CONSTRUCTOR_PROPERTY", + "MISSING_KDOC_ON_FUNCTION", + "KDOC_WITHOUT_PARAM_TAG", + "KDOC_WITHOUT_RETURN_TAG" +) class KotlinClosure1( val function: T.() -> V?, owner: Any? = null, From 140f3db2ef68f4a24810ac8715f4968d5b65277a Mon Sep 17 00:00:00 2001 From: aktsay6 Date: Tue, 9 Feb 2021 16:52:08 +0300 Subject: [PATCH 19/20] bugfix/newlinesrule(#748) ### What's done: * Fixed bugs --- .../src/main/kotlin/org/cqfn/diktat/plugin/gradle/Utils.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/diktat-gradle-plugin/src/main/kotlin/org/cqfn/diktat/plugin/gradle/Utils.kt b/diktat-gradle-plugin/src/main/kotlin/org/cqfn/diktat/plugin/gradle/Utils.kt index 12cdf78f1c..20bda86b63 100644 --- a/diktat-gradle-plugin/src/main/kotlin/org/cqfn/diktat/plugin/gradle/Utils.kt +++ b/diktat-gradle-plugin/src/main/kotlin/org/cqfn/diktat/plugin/gradle/Utils.kt @@ -27,6 +27,11 @@ class KotlinClosure1( // These two are copy-pasted from `kotlin-dsl` plugin's groovy interop. // Because `kotlin-dsl` depends on kotlin 1.3.x. -@Suppress("MISSING_KDOC_TOP_LEVEL", "MISSING_KDOC_ON_FUNCTION", "KDOC_WITHOUT_PARAM_TAG", "KDOC_WITHOUT_RETURN_TAG") +@Suppress( + "MISSING_KDOC_TOP_LEVEL", + "MISSING_KDOC_ON_FUNCTION", + "KDOC_WITHOUT_PARAM_TAG", + "KDOC_WITHOUT_RETURN_TAG" +) fun Any.closureOf(action: T.() -> Unit): Closure = KotlinClosure1(action, this, this) From 39387e46c8864bb82500fa5ba572b20f6b37aac7 Mon Sep 17 00:00:00 2001 From: aktsay6 Date: Mon, 15 Feb 2021 11:25:48 +0300 Subject: [PATCH 20/20] bugfix/newlinesrule(#748) ### What's done: * Fixed bug --- .../org/cqfn/diktat/ruleset/rules/chapter3/TrailingCommaRule.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/TrailingCommaRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/TrailingCommaRule.kt index 6e288e23af..c1061ff8cc 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/TrailingCommaRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/TrailingCommaRule.kt @@ -53,7 +53,7 @@ class TrailingCommaRule(configRules: List) : DiktatRule( "trailing-comma", configRules, listOf(TRAILING_COMMA)) { - private val commonConfig by configRules.getCommonConfiguration() + private val commonConfig = configRules.getCommonConfiguration() private val trailingConfig = this.configRules.getRuleConfig(TRAILING_COMMA)?.configuration ?: emptyMap() private val configuration by lazy { if (trailingConfig.isEmpty()) {