diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/DiktatRuleSetProvider.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/DiktatRuleSetProvider.kt index 65adab2617..fc8733acb3 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/DiktatRuleSetProvider.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/DiktatRuleSetProvider.kt @@ -107,7 +107,8 @@ class DiktatRuleSetProvider(private var diktatConfigFile: String = DIKTAT_ANALYS @Suppress( "LongMethod", "TOO_LONG_FUNCTION", - "SpreadOperator") + "SpreadOperator" + ) override fun get(): RuleSet { log.debug("Will run $DIKTAT_RULE_SET_ID with $diktatConfigFile" + " (it can be placed to the run directory or the default file from resources will be used)") 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 8c89d666d8..846ecda121 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 @@ -29,7 +29,8 @@ import java.io.File class FileNaming(configRules: List) : DiktatRule( "file-naming", configRules, - listOf(FILE_NAME_INCORRECT, FILE_NAME_MATCH_CLASS)) { + 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 d71ceb8380..71383f9d84 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 @@ -76,7 +76,8 @@ class IdentifierNaming(configRules: List) : DiktatRule( 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, - IDENTIFIER_LENGTH, OBJECT_NAME_INCORRECT, TYPEALIAS_NAME_INCORRECT_CASE)) { + IDENTIFIER_LENGTH, OBJECT_NAME_INCORRECT, TYPEALIAS_NAME_INCORRECT_CASE) +) { private val allMethodPrefixes by lazy { if (configuration.allowedBooleanPrefixes.isEmpty()) { booleanMethodPrefixes 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 c3caae1879..49725726fb 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 @@ -45,7 +45,8 @@ 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)) { + PACKAGE_NAME_INCORRECT_PATH, PACKAGE_NAME_INCORRECT_PREFIX, PACKAGE_NAME_INCORRECT_SYMBOLS) +) { private lateinit var domainName: String override fun logic(node: ASTNode) { @@ -89,7 +90,8 @@ class PackageNaming(configRules: List) : DiktatRule( private fun warnAndFixMissingPackageName( initialPackageDirectiveNode: ASTNode, realPackageName: List, - filePath: String) { + filePath: String + ) { val fileName = filePath.substringAfterLast(File.separator) // if the file path contains "buildSrc" - don't add the package name to the file @@ -262,7 +264,8 @@ class PackageNaming(configRules: List) : DiktatRule( */ private fun checkFilePathMatchesWithPackageName(packageNameParts: List, realNameParts: List, - packageDirective: ASTNode) { + packageDirective: ASTNode + ) { if (realNameParts.isNotEmpty() && packageNameParts.map { node -> node.text } != realNameParts) { val realPackageNameStr = realNameParts.joinToString(PACKAGE_SEPARATOR) val offset = packageNameParts[0].startOffset 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 3b85d7b49d..c13ffb7ce9 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 @@ -28,7 +28,8 @@ import org.slf4j.LoggerFactory class CommentsRule(configRules: List) : DiktatRule( "comments", configRules, - listOf(COMMENTED_OUT_CODE)) { + 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 cf26f22114..82e4db265f 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 @@ -45,7 +45,8 @@ 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 && !node.getFilePath().isGradleScript()) { 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 e8fd022ad8..6de13bf9f8 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 @@ -53,7 +53,8 @@ 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)) { + IF_ELSE_COMMENTS, WRONG_NEWLINES_AROUND_KDOC) +) { /** * @param node */ @@ -143,7 +144,8 @@ class CommentsFormatting(configRules: List) : DiktatRule( elseBlock: ASTNode, elseKeyWord: ASTNode, comment: ASTNode, - copyComment: ASTNode?) { + copyComment: ASTNode? + ) { if (elseBlock.hasChildOfType(BLOCK)) { val elseCodeBlock = elseBlock.getFirstChildWithType(BLOCK)!! elseCodeBlock.addChild(copyComment!!, 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 ade7dd4f0d..0b2f792586 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 @@ -32,6 +32,7 @@ import com.pinterest.ktlint.core.ast.ElementType.VAL_KEYWORD import com.pinterest.ktlint.core.ast.ElementType.VAR_KEYWORD import com.pinterest.ktlint.core.ast.ElementType.WHITE_SPACE import com.pinterest.ktlint.core.ast.parent +import com.pinterest.ktlint.core.ast.prevSibling import org.jetbrains.kotlin.com.intellij.lang.ASTNode import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.LeafPsiElement import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.PsiWhiteSpaceImpl @@ -39,6 +40,7 @@ import org.jetbrains.kotlin.com.intellij.psi.tree.TokenSet import org.jetbrains.kotlin.kdoc.parser.KDocKnownTag import org.jetbrains.kotlin.psi.KtParameterList import org.jetbrains.kotlin.psi.psiUtil.parents +import org.jetbrains.kotlin.psi.psiUtil.siblings /** * This rule checks the following features in KDocs: @@ -50,12 +52,14 @@ 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_NO_CONSTRUCTOR_PROPERTY_WITH_COMMENT, MISSING_KDOC_CLASS_ELEMENTS, MISSING_KDOC_TOP_LEVEL) +) { + private val config by lazy { configRules.getCommonConfiguration() } + /** * @param node */ override fun logic(node: ASTNode) { - val config = configRules.getCommonConfiguration() val filePath = node.getFilePath() if (!node.hasTestAnnotation() && !isLocatedInTest(filePath.splitPathToDirs(), config.testAnchors)) { when (node.elementType) { @@ -86,34 +90,36 @@ class KdocComments(configRules: List) : DiktatRule( } @Suppress("UnsafeCallOnNullableType", "ComplexMethod") - private fun checkValueParameter(node: ASTNode) { - if (node.parents().none { it.elementType == PRIMARY_CONSTRUCTOR } || - !node.hasChildOfType(VAL_KEYWORD) && !node.hasChildOfType(VAR_KEYWORD)) { + private fun checkValueParameter(valueParameterNode: ASTNode) { + if (valueParameterNode.parents().none { it.elementType == PRIMARY_CONSTRUCTOR } || + !valueParameterNode.hasChildOfType(VAL_KEYWORD) && + !valueParameterNode.hasChildOfType(VAR_KEYWORD) + ) { return } - val prevComment = if (node.treePrev.elementType == WHITE_SPACE && - (node.treePrev.treePrev.elementType == EOL_COMMENT || - node.treePrev.treePrev.elementType == BLOCK_COMMENT)) { - node.treePrev.treePrev - } else if (node.hasChildOfType(KDOC)) { - node.findChildByType(KDOC)!! - } else if (node.treePrev.elementType == BLOCK_COMMENT) { - node.treePrev + val prevComment = if (valueParameterNode.siblings(forward = false) + .takeWhile { it.elementType != EOL_COMMENT && it.elementType != BLOCK_COMMENT } + .all { it.elementType == WHITE_SPACE } + ) { + // take previous comment, if it's immediately before `valueParameterNode` or separated only with white space + valueParameterNode.prevSibling { it.elementType == EOL_COMMENT || it.elementType == BLOCK_COMMENT } + } else if (valueParameterNode.hasChildOfType(KDOC)) { + valueParameterNode.findChildByType(KDOC)!! } else { null } - val kdocBeforeClass = node.parent({ it.elementType == CLASS })!!.findChildByType(KDOC) + val kdocBeforeClass = valueParameterNode.parent({ it.elementType == CLASS })!!.findChildByType(KDOC) prevComment?.let { kdocBeforeClass?.let { - checkKdocBeforeClass(node, kdocBeforeClass, prevComment) + checkKdocBeforeClass(valueParameterNode, kdocBeforeClass, prevComment) } - ?: createKdocWithProperty(node, prevComment) + ?: createKdocWithProperty(valueParameterNode, prevComment) } ?: kdocBeforeClass?.let { - checkBasicKdocBeforeClass(node, kdocBeforeClass) + checkBasicKdocBeforeClass(valueParameterNode, kdocBeforeClass) } - ?: createKdocBasicKdoc(node) + ?: createKdocBasicKdoc(valueParameterNode) } @Suppress("UnsafeCallOnNullableType") @@ -133,7 +139,8 @@ class KdocComments(configRules: List) : DiktatRule( private fun checkKdocBeforeClass( node: ASTNode, kdocBeforeClass: ASTNode, - prevComment: ASTNode) { + prevComment: ASTNode + ) { val propertyInClassKdoc = kdocBeforeClass .kDocTags() .firstOrNull { it.knownTag == KDocKnownTag.PROPERTY && it.getSubjectName() == node.findChildByType(IDENTIFIER)!!.text } @@ -170,27 +177,20 @@ class KdocComments(configRules: List) : DiktatRule( } @Suppress("UnsafeCallOnNullableType") - private fun createKdocWithProperty(node: ASTNode, prevComment: ASTNode) { - KDOC_NO_CONSTRUCTOR_PROPERTY_WITH_COMMENT.warnAndFix(configRules, emitWarn, isFixMode, prevComment.text, prevComment.startOffset, node) { - val classNode = node.parent({ it.elementType == CLASS })!! + private fun createKdocWithProperty(valueParameterNode: ASTNode, prevComment: ASTNode) { + KDOC_NO_CONSTRUCTOR_PROPERTY_WITH_COMMENT.warnAndFix(configRules, emitWarn, isFixMode, prevComment.text, prevComment.startOffset, valueParameterNode) { + val classNode = valueParameterNode.parent({ it.elementType == CLASS })!! val newKdocText = if (prevComment.elementType == KDOC) { prevComment.text } else if (prevComment.elementType == EOL_COMMENT) { - "/**\n * @property ${node.findChildByType(IDENTIFIER)!!.text} ${prevComment.text.removePrefix("//")}\n */" + "/**\n * @property ${valueParameterNode.findChildByType(IDENTIFIER)!!.text} ${prevComment.text.removePrefix("//")}\n */" } else { - "/**\n * @property ${node.findChildByType(IDENTIFIER)!!.text}${prevComment.text.removePrefix("/*").removeSuffix("*/")} */" + "/**\n * @property ${valueParameterNode.findChildByType(IDENTIFIER)!!.text}${prevComment.text.removePrefix("/*").removeSuffix("*/")} */" } val newKdoc = KotlinParser().createNode(newKdocText).findChildByType(KDOC)!! classNode.addChild(PsiWhiteSpaceImpl("\n"), classNode.firstChildNode) classNode.addChild(newKdoc, classNode.firstChildNode) - if (prevComment.elementType == EOL_COMMENT) { - node.treeParent.removeRange(prevComment, node) - } else { - if (prevComment.treeNext.elementType == WHITE_SPACE) { - node.removeChild(prevComment.treeNext) - } - node.removeChild(prevComment) - } + valueParameterNode.removeWithWhiteSpace(prevComment) } } @@ -200,7 +200,8 @@ class KdocComments(configRules: List) : DiktatRule( prevComment: ASTNode, kdocBeforeClass: ASTNode, propertyInClassKdoc: ASTNode?, - propertyInLocalKdoc: ASTNode?) { + propertyInLocalKdoc: ASTNode? + ) { val kdocText = if (prevComment.elementType == KDOC) { prevComment.text.removePrefix("/**").removeSuffix("*/").trim('\n', ' ') } else { @@ -209,17 +210,14 @@ class KdocComments(configRules: List) : DiktatRule( // if property is documented with KDoc, which has a property tag inside, then it can contain some additional more complicated // structure, that will be hard to move automatically val isFixable = propertyInLocalKdoc == null - KDOC_NO_CONSTRUCTOR_PROPERTY.warnAndFix(configRules, emitWarn, isFixable, prevComment.text, prevComment.startOffset, node, isFixable) { + KDOC_NO_CONSTRUCTOR_PROPERTY.warnAndFix(configRules, emitWarn, isFixMode, prevComment.text, prevComment.startOffset, node, isFixable) { propertyInClassKdoc?.let { // local docs should be appended to docs in class appendKdocTagContent(propertyInClassKdoc, "\n$kdocText") } ?: insertTextInKdoc(kdocBeforeClass, " * @property ${node.findChildByType(IDENTIFIER)!!.text} ${kdocText.removePrefix("*")}\n") - if (prevComment.treeNext.elementType == WHITE_SPACE) { - node.removeChild(prevComment.treeNext) - } - node.removeChild(prevComment) + node.removeWithWhiteSpace(prevComment) } } @@ -228,7 +226,8 @@ class KdocComments(configRules: List) : DiktatRule( node: ASTNode, kdocBeforeClass: ASTNode, prevComment: ASTNode, - propertyInClassKdoc: ASTNode?) { + propertyInClassKdoc: ASTNode? + ) { propertyInClassKdoc?.let { if (propertyInClassKdoc.hasChildOfType(KDOC_TEXT)) { val kdocText = propertyInClassKdoc.findChildByType(KDOC_TEXT)!! @@ -240,7 +239,7 @@ class KdocComments(configRules: List) : DiktatRule( ?: run { insertTextInKdoc(kdocBeforeClass, "* @property ${node.findChildByType(IDENTIFIER)!!.text} ${prevComment.text.removeRange(0, 2)}\n") } - node.treeParent.removeRange(prevComment, node) + node.treeParent.removeChildMergingSurroundingWhitespaces(prevComment) } @Suppress("UnsafeCallOnNullableType") @@ -330,3 +329,35 @@ class KdocComments(configRules: List) : DiktatRule( private val statementsToDocument = TokenSet.create(CLASS, FUN, PROPERTY) } } + +private fun ASTNode.removeWithWhiteSpace(prevComment: ASTNode) { + if (prevComment.elementType == KDOC) { + if (prevComment.treeNext.elementType == WHITE_SPACE) { + removeChild(prevComment.treeNext) + } + removeChild(prevComment) + } else { + removeChildMergingSurroundingWhitespaces(prevComment) + } +} + +/** + * If [child] node is surrounded by nodes with type `WHITE_SPACE`, remove [child] and merge surrounding nodes, + * preserving only a single newline if present (i.e. leaving no empty lines after merging). In any case, [child] is removed + * from the tree. + */ +private fun ASTNode.removeChildMergingSurroundingWhitespaces(child: ASTNode) { + with(child) { + if (treeNext?.elementType == WHITE_SPACE && treePrev?.elementType == WHITE_SPACE) { + val mergedText = (treePrev.text + treeNext.text) + val mergedSpace = if (mergedText.contains('\n')) { + '\n' + mergedText.substringAfterLast('\n') + } else { + mergedText + } + treeParent.replaceWhiteSpaceText(treePrev, mergedSpace) + } + treeParent.removeChild(treeNext) + } + removeChild(child) +} 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 0425cbfaad..f91057e80b 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 @@ -65,7 +65,8 @@ class KdocFormatting(configRules: List) : DiktatRule( 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_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 6bca693f84..4e61b0dc28 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 @@ -73,7 +73,8 @@ 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_WITHOUT_THROWS_TAG, MISSING_KDOC_ON_FUNCTION) +) { /** * @param node */ @@ -212,7 +213,8 @@ class KdocMethods(configRules: List) : DiktatRule( kdoc: ASTNode?, missingParameters: Collection, kdocMissingParameters: List, - kdocTags: Collection?) { + kdocTags: Collection? + ) { kdocMissingParameters.forEach { KDOC_WITHOUT_PARAM_TAG.warn(configRules, emitWarn, false, "${it.getSubjectName()} param isn't present in argument list", it.node.startOffset, 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 358de3675a..7346511e52 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 @@ -22,7 +22,8 @@ import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.PsiWhiteSpaceImpl class AnnotationNewLineRule(configRules: List) : DiktatRule( "annotation-new-line", configRules, - listOf(ANNOTATION_NEW_LINE)) { + 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 5e9da1e043..f78641d06e 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 @@ -53,7 +53,8 @@ import org.jetbrains.kotlin.psi.KtTryExpression class BlockStructureBraces(configRules: List) : DiktatRule( "block-structure", configRules, - listOf(BRACES_BLOCK_STRUCTURE_ERROR)) { + listOf(BRACES_BLOCK_STRUCTURE_ERROR) +) { override fun logic(node: ASTNode) { val configuration = BlockStructureBracesConfiguration( configRules.getRuleConfig(BRACES_BLOCK_STRUCTURE_ERROR)?.configuration ?: emptyMap() @@ -165,7 +166,8 @@ class BlockStructureBraces(configRules: List) : DiktatRule( private fun checkOpenBraceOnSameLine( node: ASTNode, beforeType: IElementType, - configuration: BlockStructureBracesConfiguration) { + configuration: BlockStructureBracesConfiguration + ) { if (!configuration.openBrace) { return } @@ -213,7 +215,8 @@ class BlockStructureBraces(configRules: List) : DiktatRule( private fun checkMidBrace( allMiddleSpace: List, node: ASTNode, - keyword: IElementType) { + keyword: IElementType + ) { allMiddleSpace.forEach { space -> if (checkBraceNode(space, true)) { BRACES_BLOCK_STRUCTURE_ERROR.warnAndFix(configRules, emitWarn, isFixMode, "incorrect new line after closing brace", diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/BooleanExpressionsRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/BooleanExpressionsRule.kt index ba0b06ee8b..278f73e4ba 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/BooleanExpressionsRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter3/BooleanExpressionsRule.kt @@ -34,7 +34,8 @@ import java.lang.RuntimeException class BooleanExpressionsRule(configRules: List) : DiktatRule( "boolean-expressions-rule", configRules, - listOf(COMPLEX_BOOLEAN_EXPRESSION)) { + listOf(COMPLEX_BOOLEAN_EXPRESSION) +) { override fun logic(node: ASTNode) { if (node.elementType == CONDITION) { checkBooleanExpression(node) @@ -154,7 +155,8 @@ class BooleanExpressionsRule(configRules: List) : DiktatRule( private fun fixBooleanExpression( node: ASTNode, simplifiedExpr: Expression, - mapOfExpressionToChar: HashMap) { + mapOfExpressionToChar: HashMap + ) { var correctKotlinBooleanExpression = simplifiedExpr .toString() .replace("&", "&&") @@ -180,7 +182,8 @@ class BooleanExpressionsRule(configRules: List) : DiktatRule( private fun checkDistributiveLaw( expr: Expression, mapOfExpressionToChar: HashMap, - node: ASTNode): String? { + node: ASTNode + ): String? { // checking that expression can be considered as distributive law val commonDistributiveOperand = getCommonDistributiveOperand(node, expr.toString(), mapOfExpressionToChar) ?: return null val correctSymbolsSequence = mapOfExpressionToChar.values.toMutableList() @@ -217,7 +220,8 @@ class BooleanExpressionsRule(configRules: List) : DiktatRule( private fun getCommonDistributiveOperand( node: ASTNode, expression: String, - mapOfExpressionToChar: HashMap): Char? { + mapOfExpressionToChar: HashMap + ): Char? { val operationSequence = expression.filter { it == '&' || it == '|' } val numberOfOperationReferences = operationSequence.length // There should be three operands and three operation references in order to consider the expression @@ -251,7 +255,8 @@ class BooleanExpressionsRule(configRules: List) : DiktatRule( private fun getCommonOperand( expression: String, firstSplitDelimiter: Char, - secondSplitDelimiter: Char): Char? { + secondSplitDelimiter: Char + ): Char? { val expressions = expression.split(firstSplitDelimiter) val listOfPairs: MutableList> = mutableListOf() expressions.forEach { expr -> 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 40ce08799a..2bdc259935 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 @@ -37,7 +37,8 @@ import org.jetbrains.kotlin.psi.psiUtil.astReplace class BracesInConditionalsAndLoopsRule(configRules: List) : DiktatRule( "braces-rule", configRules, - listOf(NO_BRACES_IN_CONDITIONALS_AND_LOOPS)) { + listOf(NO_BRACES_IN_CONDITIONALS_AND_LOOPS) +) { override fun logic(node: ASTNode) { when (node.elementType) { IF -> checkIfNode(node) @@ -156,7 +157,8 @@ class BracesInConditionalsAndLoopsRule(configRules: List) : DiktatR private fun ASTNode.insertEmptyBlockBetweenChildren( firstChild: ASTNode, secondChild: ASTNode?, - indent: Int) { + indent: Int + ) { val emptyBlock = CompositeElement(ElementType.BLOCK_CODE_FRAGMENT) addChild(emptyBlock, firstChild) addChild(PsiWhiteSpaceImpl(" "), emptyBlock) 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 75ba3892cf..3e7c2a19a8 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 @@ -46,7 +46,8 @@ import org.jetbrains.kotlin.psi.psiUtil.siblings class ClassLikeStructuresOrderRule(configRules: List) : DiktatRule( "class-like-structures", configRules, - listOf(BLANK_LINE_BETWEEN_PROPERTIES, WRONG_ORDER_IN_CLASS_LIKE_STRUCTURES)) { + listOf(BLANK_LINE_BETWEEN_PROPERTIES, WRONG_ORDER_IN_CLASS_LIKE_STRUCTURES) +) { override fun logic(node: ASTNode) { if (node.elementType == CLASS_BODY) { checkDeclarationsOrderInClass(node) @@ -165,7 +166,8 @@ class ClassLikeStructuresOrderRule(configRules: List) : DiktatRule( private data class AllProperties(val loggers: List, val constProperties: List, val properties: List, - val lateInitProperties: List) { + val lateInitProperties: List + ) { companion object { /** * Create [AllProperties] wrapper from node with type [CLASS_BODY] @@ -206,7 +208,8 @@ class ClassLikeStructuresOrderRule(configRules: List) : DiktatRule( val methods: List, val usedClasses: List, val companion: List, - val unusedClasses: List) { + val unusedClasses: List + ) { init { require(companion.size in 0..1) { "There is more than one companion object in class" } } 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 a02d43db04..1067aa5b19 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 @@ -23,7 +23,8 @@ 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)) { + 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 91d02e9e25..9fe4513942 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 @@ -27,7 +27,8 @@ import org.jetbrains.kotlin.psi.psiUtil.parents class EmptyBlock(configRules: List) : DiktatRule( "empty-block-structure", configRules, - listOf(EMPTY_BLOCK_STRUCTURE_ERROR)) { + 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 13957d4e42..1fa78ea8d0 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 @@ -29,7 +29,8 @@ import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.PsiWhiteSpaceImpl class EnumsSeparated(configRules: List) : DiktatRule( "enum-separated", configRules, - listOf(ENUMS_SEPARATED)) { + listOf(ENUMS_SEPARATED) +) { override fun logic(node: ASTNode) { if (node.elementType == CLASS && node.hasChildOfType(CLASS_BODY) && node.isClassEnum()) { checkEnumEntry(node) 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 e2f48757a0..9b141f3aba 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 @@ -65,7 +65,8 @@ import java.net.URL class LineLength(configRules: List) : DiktatRule( "line-length", configRules, - listOf(LONG_LINE)) { + listOf(LONG_LINE) +) { private val configuration by lazy { LineLengthConfiguration( configRules.getRuleConfig(LONG_LINE)?.configuration ?: emptyMap() @@ -467,7 +468,8 @@ class LineLength(configRules: List) : DiktatRule( private fun splitTextAndCreateNode( node: ASTNode, text: String, - index: Int) { + index: Int + ) { val resultText = "\"${text.substring(0, index)}\" +\n\"${text.substring(index)}\"" val newNode = KotlinParser().createNode(resultText) node.removeChild(node.findChildByType(STRING_TEMPLATE)!!) @@ -500,7 +502,8 @@ class LineLength(configRules: List) : DiktatRule( class Comment( val node: ASTNode, val hasNewLineBefore: Boolean, - val indexLastSpace: Int = 0) : LongLineFixableCases() + val indexLastSpace: Int = 0 + ) : LongLineFixableCases() /** * @property node node @@ -510,21 +513,24 @@ class LineLength(configRules: List) : DiktatRule( class StringTemplate( val node: ASTNode, val delimiterIndex: Int, - val isOneLineString: Boolean) : LongLineFixableCases() + val isOneLineString: Boolean + ) : LongLineFixableCases() class BinaryExpression(val node: ASTNode) : LongLineFixableCases() class Condition( val maximumLineLength: Long, val leftOffset: Int, - val binList: MutableList) : LongLineFixableCases() + val binList: MutableList + ) : LongLineFixableCases() class Fun(val node: ASTNode) : LongLineFixableCases() class Property( val node: ASTNode, val indexLastSpace: Int, - val text: String) : LongLineFixableCases() + val text: String + ) : LongLineFixableCases() } /** 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 7fe8f58a14..d72970e004 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 @@ -19,7 +19,8 @@ import java.lang.StringBuilder class LongNumericalValuesSeparatedRule(configRules: List) : DiktatRule( "long-numerical-values", configRules, - listOf(LONG_NUMERICAL_VALUES_SEPARATED)) { + listOf(LONG_NUMERICAL_VALUES_SEPARATED) +) { override fun logic(node: ASTNode) { val configuration = LongNumericalValuesConfiguration( configRules.getRuleConfig(LONG_NUMERICAL_VALUES_SEPARATED)?.configuration ?: emptyMap()) @@ -55,7 +56,8 @@ class LongNumericalValuesSeparatedRule(configRules: List) : DiktatR realPart: String, fractionalPart: String, configuration: LongNumericalValuesConfiguration, - node: ASTNode) { + node: ASTNode + ) { val resultRealPart = StringBuilder(nodePrefix(realPart)) val resultFractionalPart = StringBuilder() @@ -100,7 +102,8 @@ class LongNumericalValuesSeparatedRule(configRules: List) : DiktatR private fun isValidConstant( text: String, configuration: LongNumericalValuesConfiguration, - node: ASTNode): Boolean { + node: ASTNode + ): Boolean { if (text.contains("_")) { checkBlocks(removePrefixSuffix(text), configuration, node) return true @@ -115,7 +118,8 @@ class LongNumericalValuesSeparatedRule(configRules: List) : DiktatR private fun checkBlocks( text: String, configuration: LongNumericalValuesConfiguration, - node: ASTNode) { + node: ASTNode + ) { val blocks = text.split("_", ".") blocks.forEach { 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 a326996341..c5fb88d1dc 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 @@ -18,7 +18,8 @@ import org.jetbrains.kotlin.psi.psiUtil.children class MultipleModifiersSequence(configRules: List) : DiktatRule( "multiple-modifiers", configRules, - listOf(WRONG_MULTIPLE_MODIFIERS_ORDER)) { + 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 7d0bb0e8fb..3736bf08d1 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 @@ -40,7 +40,8 @@ import org.jetbrains.kotlin.com.intellij.psi.tree.IElementType class NullableTypeRule(configRules: List) : DiktatRule( "nullable-type", configRules, - listOf(NULLABLE_PROPERTY_TYPE)) { + listOf(NULLABLE_PROPERTY_TYPE) +) { override fun logic(node: ASTNode) { if (node.elementType == PROPERTY) { checkProperty(node) @@ -135,7 +136,8 @@ class NullableTypeRule(configRules: List) : DiktatRule( node: ASTNode, insertConstantType: IElementType, insertType: IElementType, - textNode: String) { + textNode: String + ) { val value = CompositeElement(insertConstantType) node.addChild(value, node.findChildByType(NULL)!!) node.removeChild(node.findChildByType(NULL)!!) @@ -156,7 +158,8 @@ class NullableTypeRule(configRules: List) : DiktatRule( val insertConstantType: IElementType?, val insertType: IElementType?, val textNode: String, - val isString: Boolean = false) + val isString: Boolean = false + ) companion object { private val allowExpression = listOf("emptyList", "emptySequence", "emptyArray", "emptyMap", "emptySet", 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 a4fc8ec5e4..506c2e31f2 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 @@ -21,7 +21,8 @@ import org.jetbrains.kotlin.com.intellij.psi.tree.TokenSet class SingleLineStatementsRule(configRules: List) : DiktatRule( "statement", configRules, - listOf(MORE_THAN_ONE_STATEMENT_PER_LINE)) { + 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 fb1d2a3a90..ad0a116efa 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 @@ -34,7 +34,8 @@ import org.jetbrains.kotlin.psi.psiUtil.siblings class SortRule(configRules: List) : DiktatRule( "sort-rule", configRules, - listOf(WRONG_DECLARATIONS_ORDER)) { + listOf(WRONG_DECLARATIONS_ORDER) +) { override fun logic(node: ASTNode) { val configuration = SortRuleConfiguration( configRules.getRuleConfig(WRONG_DECLARATIONS_ORDER)?.configuration ?: emptyMap() @@ -79,7 +80,8 @@ class SortRule(configRules: List) : DiktatRule( private fun swapSortNodes( sortList: List, nonSortList: List, - node: ASTNode) { + node: ASTNode + ) { val isEnum = nonSortList.first().elementType == ENUM_ENTRY val spaceBefore = if (node.findAllDescendantsWithSpecificType(EOL_COMMENT).isNotEmpty() && isEnum) { nonSortList.last().run { 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 72b87de096..7bd89a5081 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 @@ -123,7 +123,8 @@ class StringConcatenationRule(configRules: List) : DiktatRule( "TOO_LONG_FUNCTION", "NESTED_BLOCK", "SAY_NO_TO_VAR", - "ComplexMethod") + "ComplexMethod" + ) private fun checkKtExpression(binaryExpressionPsi: KtBinaryExpression): String { var lvalueText = binaryExpressionPsi.left?.text?.trim('"') val rvalueText = binaryExpressionPsi.right?.text 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 7d20ed9548..2b4492048f 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 @@ -30,7 +30,8 @@ import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.LeafPsiElement class StringTemplateFormatRule(configRules: List) : DiktatRule( "string-template-format", configRules, - listOf(STRING_TEMPLATE_CURLY_BRACES, STRING_TEMPLATE_QUOTES)) { + 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 94af992387..d928595337 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 @@ -55,7 +55,8 @@ import org.slf4j.LoggerFactory class TrailingCommaRule(configRules: List) : DiktatRule( "trailing-comma", configRules, - listOf(TRAILING_COMMA)) { + listOf(TRAILING_COMMA) +) { private val commonConfig = 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 98f289431a..9ba599ca00 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 @@ -39,7 +39,8 @@ import org.jetbrains.kotlin.psi.KtWhenExpression class WhenMustHaveElseRule(configRules: List) : DiktatRule( "no-else-in-when", configRules, - listOf(WHEN_WITHOUT_ELSE)) { + 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 6e363f52b0..443a1a8b8f 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,7 +24,8 @@ import org.jetbrains.kotlin.com.intellij.lang.ASTNode class BlankLinesRule(configRules: List) : DiktatRule( "blank-lines", configRules, - listOf(TOO_MANY_BLANK_LINES)) { + 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 d556473ffe..43d0f862f0 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,8 @@ import org.jetbrains.kotlin.com.intellij.lang.ASTNode class FileSize(configRules: List) : DiktatRule( "file-size", configRules, - listOf(FILE_IS_TOO_LONG)) { + 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 1ef2ae388c..6f6713f6c4 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 @@ -60,7 +60,8 @@ 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)) { + FILE_UNORDERED_IMPORTS, FILE_WILDCARD_IMPORTS, UNUSED_IMPORT) +) { private val domainName by lazy { configRules .getCommonConfiguration() @@ -116,7 +117,8 @@ class FileStructureRule(configRules: List) : DiktatRule( @Suppress( "ComplexMethod", "TOO_LONG_FUNCTION", - "SpreadOperator") + "SpreadOperator" + ) private fun checkCodeBlocksOrderAndEmptyLines(node: ASTNode) { // From KtFile.kt: 'scripts have no package directive, all other files must have package directives'. // Kotlin compiler itself enforces it's position in the file if it is present. @@ -283,7 +285,8 @@ class FileStructureRule(configRules: List) : DiktatRule( private fun rearrangeImports( node: ASTNode, imports: List, - sortedImportsGroups: List>) { + sortedImportsGroups: List> + ) { require(node.elementType == IMPORT_LIST) // move all commented lines among import before imports block node.getChildren(TokenSet.create(EOL_COMMENT)) 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 2d30c0c148..e3d706353b 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 @@ -71,7 +71,8 @@ import kotlin.math.abs class IndentationRule(configRules: List) : DiktatRule( "indentation", configRules, - listOf(WRONG_INDENTATION)) { + listOf(WRONG_INDENTATION) +) { private val configuration: IndentationConfig by lazy { IndentationConfig(configRules.getRuleConfig(WRONG_INDENTATION)?.configuration ?: emptyMap()) } @@ -352,8 +353,8 @@ class IndentationRule(configRules: List) : DiktatRule( fun addException( initiator: ASTNode, indent: Int, - includeLastChild: Boolean) = - exceptionalIndents.add(ExceptionalIndent(initiator, indent, includeLastChild)) + includeLastChild: Boolean + ) = exceptionalIndents.add(ExceptionalIndent(initiator, indent, includeLastChild)) /** * @param astNode the node which is used to determine whether exceptinoal indents are still active @@ -369,7 +370,8 @@ class IndentationRule(configRules: List) : DiktatRule( private data class ExceptionalIndent( val initiator: ASTNode, val indent: Int, - val includeLastChild: Boolean = true) { + val includeLastChild: Boolean = true + ) { /** * Checks whether this exceptional indent is still active. This is a hypotheses that exceptional indentation will end * outside of node where it appeared, e.g. when an expression after assignment operator is over. 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 578077deac..4333e85111 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 @@ -71,6 +71,7 @@ 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_LIST +import com.pinterest.ktlint.core.ast.ElementType.TYPE_REFERENCE import com.pinterest.ktlint.core.ast.ElementType.VALUE_ARGUMENT import com.pinterest.ktlint.core.ast.ElementType.VALUE_ARGUMENT_LIST import com.pinterest.ktlint.core.ast.ElementType.VALUE_PARAMETER @@ -116,7 +117,8 @@ import org.slf4j.LoggerFactory class NewlinesRule(configRules: List) : DiktatRule( "newlines", configRules, - listOf(COMPLEX_EXPRESSION, REDUNDANT_SEMICOLON, WRONG_NEWLINES)) { + listOf(COMPLEX_EXPRESSION, REDUNDANT_SEMICOLON, WRONG_NEWLINES) +) { private val configuration by lazy { NewlinesRuleConfiguration(configRules.getRuleConfig(WRONG_NEWLINES)?.configuration ?: emptyMap()) } @@ -290,7 +292,7 @@ class NewlinesRule(configRules: List) : DiktatRule( // lambda with explicit arguments val newlinesBeforeArrow = arrowNode .siblings(false) - .filter { it.elementType == WHITE_SPACE && it.textContains('\n') } + .filter { it.isNewLineNode() } .toList() if (newlinesBeforeArrow.isNotEmpty() || !arrowNode.isFollowedByNewline()) { WRONG_NEWLINES.warnAndFix(configRules, emitWarn, isFixMode, @@ -401,7 +403,8 @@ class NewlinesRule(configRules: List) : DiktatRule( private fun handleFirstValue(node: ASTNode, filterType: IElementType, - warnText: String) = node + warnText: String + ) = node .children() .takeWhile { !it.textContains('\n') } .filter { it.elementType == filterType } @@ -429,8 +432,9 @@ class NewlinesRule(configRules: List) : DiktatRule( private fun handleValueParameterList(node: ASTNode, entryType: String) = node .children() .filter { - (it.elementType == COMMA && !it.treeNext.run { elementType == WHITE_SPACE && textContains('\n') } - ) || (it.elementType == RPAR && it.treePrev.elementType != COMMA && !it.treePrev.run { elementType == WHITE_SPACE && textContains('\n') }) + (it.elementType == COMMA && !it.treeNext.isNewLineNode()) || + // Move RPAR to the new line + (it.elementType == RPAR && it.treePrev.elementType != COMMA && !it.treePrev.isNewLineNode()) } .toList() .takeIf { it.isNotEmpty() } @@ -455,6 +459,8 @@ class NewlinesRule(configRules: List) : DiktatRule( } } + private fun ASTNode.isNewLineNode(): Boolean = this.run { elementType == WHITE_SPACE && textContains('\n') } + @Suppress("UnsafeCallOnNullableType") private fun ASTNode.getParentIdentifier() = when (treeParent.elementType) { PRIMARY_CONSTRUCTOR -> treeParent.treeParent 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 d539bfddb3..0a3956ea21 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 @@ -29,7 +29,8 @@ import org.jetbrains.kotlin.psi.psiUtil.siblings class TopLevelOrderRule(configRules: List) : DiktatRule( "top-level-order", configRules, - listOf(TOP_LEVEL_ORDER)) { + listOf(TOP_LEVEL_ORDER) +) { override fun logic(node: ASTNode) { if (node.elementType == FILE) { checkNode(node) @@ -98,7 +99,8 @@ class TopLevelOrderRule(configRules: List) : DiktatRule( private val properties: List, private val typealiases: List, private val functions: List, - private val classes: List) : Elements { + private val classes: List + ) : Elements { override fun sortElements(): MutableList { val (extensionFun, nonExtensionFun) = functions.partition { (it.psi as KtFunction).isExtensionDeclaration() } return (properties + listOf(typealiases, classes, extensionFun, nonExtensionFun).flatMap { nodes -> 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 8eb2bfe916..98a0eacc97 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 @@ -96,7 +96,8 @@ import org.slf4j.LoggerFactory class WhiteSpaceRule(configRules: List) : DiktatRule( "horizontal-whitespace", configRules, - listOf(WRONG_WHITESPACE)) { + listOf(WRONG_WHITESPACE) +) { @Suppress("ComplexMethod") override fun logic(node: ASTNode) { when (node.elementType) { @@ -201,7 +202,8 @@ class WhiteSpaceRule(configRules: List) : DiktatRule( isFromLambdaAsArgument: Boolean, numWhiteSpace: Int?, whitespaceOrPrevNode: ASTNode, - prevNode: ASTNode) { + prevNode: ASTNode + ) { // note: the conditions in the following `if`s cannot be collapsed into simple conjunctions if (isFromLambdaAsArgument) { val isFirstArgument = node @@ -281,7 +283,8 @@ class WhiteSpaceRule(configRules: List) : DiktatRule( private fun handleToken( node: ASTNode, requiredSpacesBefore: Int?, - requiredSpacesAfter: Int?) { + requiredSpacesAfter: Int? + ) { require(requiredSpacesBefore != null || requiredSpacesAfter != null) { "requiredSpacesBefore=$requiredSpacesBefore and requiredSpacesAfter=$requiredSpacesAfter, but at least one should not be null" } @@ -407,7 +410,8 @@ class WhiteSpaceRule(configRules: List) : DiktatRule( private fun getDescription(shouldBefore: Boolean, shouldAfter: Boolean, before: Int?, - after: Int?): String = + after: Int? + ): String = if (shouldBefore && shouldAfter) { " $before space(s) before and $after space(s) after" } else if (shouldBefore && !shouldAfter) { 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 64ca0e67aa..45c377fe21 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 @@ -40,7 +40,8 @@ import org.jetbrains.kotlin.psi.psiUtil.startOffset class LocalVariablesRule(configRules: List) : DiktatRule( "local-variables", configRules, - listOf(LOCAL_VARIABLE_EARLY_DECLARATION)) { + listOf(LOCAL_VARIABLE_EARLY_DECLARATION) +) { override fun logic(node: ASTNode) { if (node.elementType == FILE) { // collect all local properties and associate with corresponding references @@ -155,7 +156,8 @@ class LocalVariablesRule(configRules: List) : DiktatRule( property: KtProperty, firstUsageStatementLine: Int, offset: Int = 0, - firstUsageLine: Int? = null) { + firstUsageLine: Int? = null + ) { val numLinesToSkip = property .siblings(forward = true, withItself = false) .takeWhile { it is PsiWhiteSpace || it.node.isPartOfComment() } @@ -212,7 +214,8 @@ class LocalVariablesRule(configRules: List) : DiktatRule( private fun warnMessage( name: String, declared: Int, - used: Int) = "<$name> is declared on line <$declared> and is used for the first time on line <$used>" + used: Int + ) = "<$name> is declared on line <$declared> and is used for the first time on line <$used>" companion object { private var functionInitializers = listOf( 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 bbbb6a33c6..ec0fd46cb7 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 @@ -22,7 +22,8 @@ import org.jetbrains.kotlin.psi.psiUtil.getParentOfType class ImmutableValNoVarRule(configRules: List) : DiktatRule( "no-var-rule", configRules, - listOf(SAY_NO_TO_VAR)) { + 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 6ee7e9ce64..da03cc778c 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 @@ -32,7 +32,8 @@ import org.jetbrains.kotlin.psi.KtIfExpression class NullChecksRule(configRules: List) : DiktatRule( "null-checks", configRules, - listOf(AVOID_NULL_CHECKS)) { + listOf(AVOID_NULL_CHECKS) +) { override fun logic(node: ASTNode) { if (node.elementType == CONDITION) { node.parent(IF)?.let { @@ -116,7 +117,8 @@ class NullChecksRule(configRules: List) : DiktatRule( @Suppress("UnsafeCallOnNullableType", "TOO_LONG_FUNCTION") private fun fixNullInIfCondition(condition: ASTNode, binaryExpression: KtBinaryExpression, - isEqualToNull: Boolean) { + isEqualToNull: Boolean + ) { val variableName = binaryExpression.left!!.text val thenCodeLines = condition.extractLinesFromBlock(THEN) val elseCodeLines = condition.extractLinesFromBlock(ELSE) @@ -251,7 +253,8 @@ class NullChecksRule(configRules: List) : DiktatRule( condition: KtBinaryExpression, canBeAutoFixed: Boolean, freeText: String, - autofix: () -> Unit) { + autofix: () -> Unit + ) { AVOID_NULL_CHECKS.warnAndFix( configRules, emitWarn, 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 f0a09c9aae..a3c5e23060 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 @@ -42,7 +42,8 @@ import org.jetbrains.kotlin.psi.psiUtil.parents class SmartCastRule(configRules: List) : DiktatRule( "smart-cast-rule", configRules, - listOf(SMART_CAST_NEEDED)) { + listOf(SMART_CAST_NEEDED) +) { override fun logic(node: ASTNode) { if (node.elementType == FILE) { val usages = collectLocalPropertiesWithUsages(node) @@ -117,7 +118,8 @@ class SmartCastRule(configRules: List) : DiktatRule( @Suppress("TYPE_ALIAS") private fun groupIsAndAsExpr(isExpr: List, asExpr: List, - prop: KtProperty): Map> { + prop: KtProperty + ): Map> { if (isExpr.isEmpty() && asExpr.isNotEmpty()) { handleZeroIsCase(asExpr, prop) return emptyMap() @@ -281,7 +283,8 @@ class SmartCastRule(configRules: List) : DiktatRule( class AsExpressions( val identifier: String, val type: String, - val node: ASTNode) + val node: ASTNode + ) /** * @property identifier a reference that is checked 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 429610a690..cdb20b0cab 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 @@ -22,7 +22,8 @@ import org.jetbrains.kotlin.psi.psiUtil.parents class TypeAliasRule(configRules: List) : DiktatRule( "type-alias", configRules, - listOf(TYPE_ALIAS)) { + 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 b90dde5ff6..f5a6c18519 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 @@ -24,7 +24,8 @@ import org.jetbrains.kotlin.psi.KtProperty class VariableGenericTypeDeclarationRule(configRules: List) : DiktatRule( "variable-generic-type", configRules, - listOf(GENERIC_VARIABLE_WRONG_DECLARATION)) { + 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 73c4a2ca45..6a2d3c6fbb 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 @@ -27,7 +27,8 @@ import org.jetbrains.kotlin.psi.psiUtil.startOffset class AccurateCalculationsRule(configRules: List) : DiktatRule( "accurate-calculations", configRules, - listOf(FLOAT_IN_ACCURATE_CALCULATIONS)) { + 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 e79140b160..fcdfc3be26 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 @@ -20,7 +20,8 @@ import org.jetbrains.kotlin.psi.psiUtil.hasSuspendModifier class AsyncAndSyncRule(configRules: List) : DiktatRule( "sync-in-async", configRules, - listOf(RUN_BLOCKING_INSIDE_ASYNC)) { + 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 56e047d780..d1b21e37c3 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 @@ -27,7 +27,8 @@ import org.jetbrains.kotlin.psi.psiUtil.parents class AvoidNestedFunctionsRule(configRules: List) : DiktatRule( "avoid-nested-functions", configRules, - listOf(AVOID_NESTED_FUNCTIONS)) { + 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 c5504798d7..7a2d8b50ea 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 @@ -25,7 +25,8 @@ import org.jetbrains.kotlin.psi.psiUtil.siblings class CheckInverseMethodRule(configRules: List) : DiktatRule( "inverse-method", configRules, - listOf(INVERSE_FUNCTION_PREFERRED)) { + 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 2359b3a8aa..9abaa4438a 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 @@ -20,7 +20,8 @@ import org.jetbrains.kotlin.psi.psiUtil.parents class CustomLabel(configRules: List) : DiktatRule( "custom-label", configRules, - listOf(CUSTOM_LABEL)) { + 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 a5ee1f9045..f3da4d5e26 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 @@ -17,7 +17,8 @@ import org.jetbrains.kotlin.psi.KtFunction class FunctionArgumentsSize(configRules: List) : DiktatRule( "argument-size", configRules, - listOf(TOO_MANY_PARAMETERS)) { + 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 22de1d88a6..e231a16371 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 @@ -17,7 +17,8 @@ import org.jetbrains.kotlin.psi.KtFunction class FunctionLength(configRules: List) : DiktatRule( "function-length", configRules, - listOf(TOO_LONG_FUNCTION)) { + 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 06b9d02aac..73493b5fe4 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 @@ -16,7 +16,8 @@ import org.jetbrains.kotlin.com.intellij.lang.ASTNode class LambdaLengthRule(configRules: List) : DiktatRule( "lambda-length", configRules, - listOf(TOO_MANY_LINES_IN_LAMBDA)) { + 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 6cef205889..a0984a2413 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 @@ -19,7 +19,8 @@ import org.jetbrains.kotlin.utils.addToStdlib.ifNotEmpty class LambdaParameterOrder(configRules: List) : DiktatRule( "lambda-parameter-order", configRules, - listOf(LAMBDA_IS_NOT_LAST_PARAMETER)) { + 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 bb93f77f3e..6acbf98e21 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 @@ -23,7 +23,8 @@ import org.jetbrains.kotlin.psi.psiUtil.parents class NestedFunctionBlock(configRules: List) : DiktatRule( "nested-block", configRules, - listOf(NESTED_BLOCK)) { + 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 9c67a1b7fe..8f9d68a769 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 @@ -20,7 +20,8 @@ import org.jetbrains.kotlin.psi.psiUtil.startOffset class OverloadingArgumentsFunction(configRules: List) : DiktatRule( "overloading-default-values", configRules, - listOf(WRONG_OVERLOADING_FUNCTION_ARGUMENTS)) { + 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 d5a500660f..6607489752 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 @@ -14,7 +14,8 @@ import org.jetbrains.kotlin.psi.KtClass class AvoidEmptyPrimaryConstructor(configRules: List) : DiktatRule( "avoid-empty-primary-constructor", configRules, - listOf(EMPTY_PRIMARY_CONSTRUCTOR)) { + 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 ccb46dff50..df564b62c5 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 @@ -28,7 +28,8 @@ import java.util.Locale class AvoidUtilityClass(configRules: List) : DiktatRule( "avoid-utility-class", configRules, - listOf(AVOID_USING_UTILITY_CLASS)) { + listOf(AVOID_USING_UTILITY_CLASS) +) { override fun logic(node: ASTNode) { val config = configRules.getCommonConfiguration() val filePath = node.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 647ef47b84..fff4c40a65 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 @@ -18,7 +18,8 @@ import org.jetbrains.kotlin.com.intellij.lang.ASTNode class CustomGetterSetterRule(configRules: List) : DiktatRule( "custom-getter-setter", configRules, - listOf(CUSTOM_GETTERS_SETTERS)) { + 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 ebf37b90d5..de174d013f 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 @@ -23,7 +23,8 @@ import org.jetbrains.kotlin.psi.KtFunction class ExtensionFunctionsInFileRule(configRules: List) : DiktatRule( "extension-functions-class-file", configRules, - listOf(EXTENSION_FUNCTION_WITH_CLASS)) { + listOf(EXTENSION_FUNCTION_WITH_CLASS) +) { override fun logic(node: ASTNode) { if (node.elementType == ElementType.FILE) { val classNames = collectAllClassNames(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 0ff833175a..33ea8cf660 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 @@ -35,7 +35,8 @@ internal typealias SimilarSignatures = List) : DiktatRule( "extension-functions-same-name", configRules, - listOf(EXTENSION_FUNCTION_SAME_SIGNATURE)) { + listOf(EXTENSION_FUNCTION_SAME_SIGNATURE) +) { override fun logic(node: ASTNode) { /** * 1) Collect all classes that extend other classes (collect related classes) @@ -116,7 +117,8 @@ class ExtensionFunctionsSameNameRule(configRules: List) : DiktatRul private fun raiseWarning( node: ASTNode, firstFunc: ExtensionFunction, - secondFunc: ExtensionFunction) { + secondFunc: ExtensionFunction + ) { EXTENSION_FUNCTION_SAME_SIGNATURE.warn(configRules, emitWarn, isFixMode, "$firstFunc and $secondFunc", node.startOffset, node) } @@ -129,7 +131,8 @@ class ExtensionFunctionsSameNameRule(configRules: List) : DiktatRul internal data class FunctionSignature( val name: String, val parameters: List, - val returnType: String?) { + val returnType: String? + ) { override fun toString() = "$name$parameters${returnType?.let { ": $it" } ?: ""}" } @@ -142,7 +145,8 @@ class ExtensionFunctionsSameNameRule(configRules: List) : DiktatRul internal data class ExtensionFunction( val className: String, val signature: FunctionSignature, - val node: ASTNode) { + val node: ASTNode + ) { override fun toString() = "fun $className.$signature" } } 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 53a4398bd2..8679f50938 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 @@ -27,7 +27,8 @@ import org.jetbrains.kotlin.psi.KtProperty class ImplicitBackingPropertyRule(configRules: List) : DiktatRule( "implicit-backing-property", configRules, - listOf(NO_CORRESPONDING_PROPERTY)) { + listOf(NO_CORRESPONDING_PROPERTY) +) { override fun logic(node: ASTNode) { if (node.elementType == CLASS_BODY) { findAllProperties(node) @@ -60,7 +61,8 @@ class ImplicitBackingPropertyRule(configRules: List) : DiktatRule( private fun handleGetAccessors( accessor: ASTNode, node: ASTNode, - propsWithBackSymbol: List) { + propsWithBackSymbol: List + ) { val refExprs = accessor .findAllDescendantsWithSpecificType(RETURN) .filterNot { it.hasChildOfType(DOT_QUALIFIED_EXPRESSION) } @@ -79,7 +81,8 @@ class ImplicitBackingPropertyRule(configRules: List) : DiktatRule( private fun handleSetAccessors( accessor: ASTNode, node: ASTNode, - propsWithBackSymbol: List) { + propsWithBackSymbol: List + ) { val refExprs = accessor.findAllDescendantsWithSpecificType(REFERENCE_EXPRESSION) // In set we don't check for local properties. At least one reference expression should contain field or _prop @@ -92,7 +95,8 @@ class ImplicitBackingPropertyRule(configRules: List) : DiktatRule( private fun handleReferenceExpressions(node: ASTNode, expressions: List, backingPropertiesNames: List, - localProperties: List?) { + localProperties: List? + ) { if (expressions.none { backingPropertiesNames.contains(it.text) || it.text == "field" || localProperties?.contains(it.text) == true }) { 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 af85ad03e8..c352d9175b 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 @@ -25,7 +25,8 @@ import org.jetbrains.kotlin.psi.KtProperty class PropertyAccessorFields(configRules: List) : DiktatRule( "getter-setter-fields", configRules, - listOf(WRONG_NAME_OF_VARIABLE_INSIDE_ACCESSOR)) { + 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 144cf594b1..3c4c300d12 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 @@ -29,7 +29,8 @@ import org.jetbrains.kotlin.psi.KtPropertyAccessor class TrivialPropertyAccessors(configRules: List) : DiktatRule( "trivial-property-accessors", configRules, - listOf(TRIVIAL_ACCESSORS_ARE_NOT_RECOMMENDED)) { + 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 994f58f11e..37e285ba3e 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 @@ -34,7 +34,8 @@ import java.util.HashMap class UselessSupertype(configRules: List) : DiktatRule( "useless-override", configRules, - listOf(USELESS_SUPERTYPE)) { + 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 b2c3e881b5..d95aa0dbf3 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 @@ -27,7 +27,8 @@ import org.jetbrains.kotlin.psi.psiUtil.children class AbstractClassesRule(configRules: List) : DiktatRule( "abstract-classes", configRules, - listOf(CLASS_SHOULD_NOT_BE_ABSTRACT)) { + 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 4a9d29aa91..ecabc48285 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 @@ -38,7 +38,8 @@ import org.slf4j.LoggerFactory class CompactInitialization(configRules: List) : DiktatRule( "class-compact-initialization", configRules, - listOf(COMPACT_OBJECT_INITIALIZATION)) { + listOf(COMPACT_OBJECT_INITIALIZATION) +) { private val kotlinParser by lazy { KotlinParser() } override fun logic(node: ASTNode) { @@ -88,7 +89,8 @@ class CompactInitialization(configRules: List) : DiktatRule( @Suppress( "UnsafeCallOnNullableType", "NestedBlockDepth", - "TOO_LONG_FUNCTION") + "TOO_LONG_FUNCTION" + ) private fun moveAssignmentIntoApply(property: KtProperty, assignment: KtBinaryExpression) { // get apply expression or create empty; convert `apply(::foo)` to `apply { foo(this) }` if necessary getOrCreateApplyBlock(property).let(::convertValueParametersToLambdaArgument) 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 51ab593aca..885cd85269 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 @@ -33,7 +33,8 @@ import org.jetbrains.kotlin.psi.KtPrimaryConstructor class DataClassesRule(configRules: List) : DiktatRule( "data-classes", configRules, - listOf(USE_DATA_CLASS)) { + 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 bb448cdede..c103b5e0c1 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 @@ -28,7 +28,8 @@ import org.jetbrains.kotlin.psi.psiUtil.visibilityModifierType class InlineClassesRule(configRules: List) : DiktatRule( "inline-classes", configRules, - listOf(INLINE_CLASS_CAN_BE_USED)) { + listOf(INLINE_CLASS_CAN_BE_USED) +) { override fun logic(node: ASTNode) { val configuration = configRules.getCommonConfiguration() if (node.elementType == CLASS && 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 6924e6a508..96a1f4ff96 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 @@ -36,7 +36,8 @@ import org.jetbrains.kotlin.psi.psiUtil.collectDescendantsOfType class SingleConstructorRule(configRules: List) : DiktatRule( "single-constructor", configRules, - listOf(SINGLE_CONSTRUCTOR_SHOULD_BE_PRIMARY)) { + listOf(SINGLE_CONSTRUCTOR_SHOULD_BE_PRIMARY) +) { private val kotlinParser by lazy { KotlinParser() } override fun logic(node: ASTNode) { @@ -180,7 +181,8 @@ class SingleConstructorRule(configRules: List) : DiktatRule( @Suppress("UnsafeCallOnNullableType") private fun getNonTrivialParameters(secondaryCtor: ASTNode, nonTrivialAssignments: Collection, - localProperties: List) = (secondaryCtor.psi as KtSecondaryConstructor) + localProperties: List + ) = (secondaryCtor.psi as KtSecondaryConstructor) .valueParameters.run { val dependencies = nonTrivialAssignments .flatMap { it.left!!.collectDescendantsOfType() } @@ -195,7 +197,8 @@ class SingleConstructorRule(configRules: List) : DiktatRule( private fun createPrimaryCtor(secondaryCtor: ASTNode, declarationsAssignedInCtor: List, - valueParameters: List) = kotlinParser.createPrimaryConstructor( + valueParameters: List + ) = kotlinParser.createPrimaryConstructor( (secondaryCtor .findChildByType(MODIFIER_LIST) ?.text 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 4029a8855d..f205756442 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 @@ -34,7 +34,8 @@ import org.jetbrains.kotlin.psi.psiUtil.children class SingleInitRule(configRules: List) : DiktatRule( "multiple-init-block", configRules, - listOf(MULTIPLE_INIT_BLOCKS)) { + listOf(MULTIPLE_INIT_BLOCKS) +) { override fun logic(node: ASTNode) { when (node.elementType) { CLASS_BODY -> handleInitBlocks(node) @@ -98,7 +99,8 @@ class SingleInitRule(configRules: List) : DiktatRule( private fun moveAssignmentsToProperties( propertiesFromClassBody: List, propertiesFromPrimaryConstructor: List?, - initBlock: ASTNode) { + initBlock: ASTNode + ) { initBlock .findChildByType(BLOCK) ?.run { 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 f3c6ab6eb0..4cbb7c4915 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 @@ -30,7 +30,8 @@ import org.jetbrains.kotlin.psi.KtClass class StatelessClassesRule(configRules: List) : DiktatRule( "stateless-class", configRules, - listOf(OBJECT_IS_PREFERRED)) { + 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/main/kotlin/org/cqfn/diktat/ruleset/utils/AstNodeUtils.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/AstNodeUtils.kt index 8fb437f207..d6dca4009c 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 @@ -131,7 +131,7 @@ fun ASTNode.reversedChildren(): Sequence = sequence { } /** - * Replaces the [beforeNode] of type [WHITE_SPACE] with the node with specified [text] + * Replaces `this` node's child [beforeNode] of type [WHITE_SPACE] with the node with specified [text] * * @param beforeNode a node to replace * @param text a text (white space characters only) for the new node 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 28d8fd2874..8bde7ec106 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 @@ -34,7 +34,8 @@ private class SegmentTree(sortedArray: IntArray) { private fun binarySearch( compareElement: Int, left: Int, - right: Int): Int = when { + right: Int + ): Int = when { left > right -> -1 else -> { val index = left + (right - left) / 2 diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/indentation/CustomIndentationChecker.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/indentation/CustomIndentationChecker.kt index 1cd102afa8..8b9eec1051 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/indentation/CustomIndentationChecker.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/utils/indentation/CustomIndentationChecker.kt @@ -32,7 +32,8 @@ internal data class CheckResult( val isCorrect: Boolean, val expectedIndent: Int, val adjustNext: Boolean, - val includeLastChild: Boolean = true) { + val includeLastChild: Boolean = true +) { companion object { /** * @param actual actual indentation @@ -44,7 +45,7 @@ internal data class CheckResult( fun from(actual: Int, expected: Int, adjustNext: Boolean = false, - includeLastChild: Boolean = true) = - CheckResult(actual == expected, expected, adjustNext, includeLastChild) + includeLastChild: Boolean = true + ) = CheckResult(actual == expected, expected, adjustNext, includeLastChild) } } 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 7a04e90fa5..b9ade13e28 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 @@ -3,7 +3,8 @@ "MISSING_KDOC_CLASS_ELEMENTS", "MISSING_KDOC_ON_FUNCTION", "KDOC_WITHOUT_PARAM_TAG", - "KDOC_WITHOUT_RETURN_TAG") + "KDOC_WITHOUT_RETURN_TAG" +) package org.cqfn.diktat.ruleset.utils.search @@ -88,7 +89,8 @@ abstract class VariablesSearch(val node: ASTNode, */ protected fun isReferenceToOtherVariableWithSameName(expression: KtNameReferenceExpression, codeBlock: KtElement, - property: KtProperty) = expression.parents + property: KtProperty + ) = expression.parents // getting all block expressions/class bodies/file node from bottom to the top // FixMe: Object companion is not resolved properly yet .filter { it is KtBlockExpression || it is KtClassBody || it is KtFile } diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter2/KdocCommentsFixTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter2/KdocCommentsFixTest.kt index d02504fb9b..16ad239b22 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter2/KdocCommentsFixTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter2/KdocCommentsFixTest.kt @@ -19,4 +19,10 @@ class KdocCommentsFixTest : FixTestBase("test/paragraph2/kdoc/", ::KdocComments) fun `check fix without class kdoc`() { fixAndCompare("ConstructorCommentNoKDocExpected.kt", "ConstructorCommentNoKDocTest.kt") } + + @Test + @Tag(WarningNames.KDOC_NO_CONSTRUCTOR_PROPERTY) + fun `should preserve newlines when moving comments from value parameters`() { + fixAndCompare("ConstructorCommentNewlineExpected.kt", "ConstructorCommentNewlineTest.kt") + } } diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/LocalVariablesWarnTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/LocalVariablesWarnTest.kt index 391e6f8122..542e586022 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/LocalVariablesWarnTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/LocalVariablesWarnTest.kt @@ -17,8 +17,8 @@ class LocalVariablesWarnTest : LintTestBase(::LocalVariablesRule) { private fun warnMessage(name: String, declared: Int, - used: Int) = - "<$name> is declared on line <$declared> and is used for the first time on line <$used>" + used: Int + ) = "<$name> is declared on line <$declared> and is used for the first time on line <$used>" @Test @Tag(LOCAL_VARIABLE_EARLY_DECLARATION) diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/spaces/WhiteSpaceRuleWarnTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/spaces/WhiteSpaceRuleWarnTest.kt index 47260d5b39..0526425bf5 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/spaces/WhiteSpaceRuleWarnTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/spaces/WhiteSpaceRuleWarnTest.kt @@ -22,15 +22,15 @@ class WhiteSpaceRuleWarnTest : LintTestBase(::WhiteSpaceRule) { before: Int?, after: Int?, reqBefore: Int?, - reqAfter: Int?) = - "${WRONG_WHITESPACE.warnText()} $token should have" + - (reqBefore?.let { " $it space(s) before" } ?: "") + - (if (reqBefore != null && reqAfter != null) " and" else "") + - (reqAfter?.let { " $it space(s) after" } ?: "") + - ", but has" + - (before?.let { " $it space(s) before" } ?: "") + - (if (before != null && after != null) " and" else "") + - (after?.let { " $it space(s) after" } ?: "") + reqAfter: Int? + ) = "${WRONG_WHITESPACE.warnText()} $token should have" + + (reqBefore?.let { " $it space(s) before" } ?: "") + + (if (reqBefore != null && reqAfter != null) " and" else "") + + (reqAfter?.let { " $it space(s) after" } ?: "") + + ", but has" + + (before?.let { " $it space(s) before" } ?: "") + + (if (before != null && after != null) " and" else "") + + (after?.let { " $it space(s) after" } ?: "") @Test @Tag(WarningNames.WRONG_WHITESPACE) 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 c82cf91afb..1222fe7a9e 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 @@ -735,10 +735,12 @@ class AstNodeUtilsTest { private class PrettyPrintingVisitor(private val elementType: IElementType, private val level: Int, private val maxLevel: Int, - private val expected: String) : Rule("print-ast") { + private val expected: String +) : Rule("print-ast") { override fun visit(node: ASTNode, autoCorrect: Boolean, - emit: EmitType) { + emit: EmitType + ) { if (node.elementType == elementType) { Assertions.assertEquals( expected.replace("\n", System.lineSeparator()), @@ -753,7 +755,8 @@ private class PrettyPrintingVisitor(private val elementType: IElementType, code: String, level: Int = 0, maxLevel: Int = -1, - expected: String) { + expected: String + ) { KtLint.lint( KtLint.Params( text = code, 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 632058eb77..ea538ffcdc 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 @@ -13,7 +13,8 @@ import org.junit.jupiter.api.Assertions open class FixTestBase(protected val resourceFilePath: String, private val ruleSetProviderRef: (rulesConfigList: List?) -> RuleSetProvider, private val cb: LintErrorCallback = defaultCallback, - private val rulesConfigList: List? = null) { + private val rulesConfigList: List? = null +) { private val testComparatorUnit = TestComparatorUnit(resourceFilePath) { text, fileName -> format(ruleSetProviderRef, text, fileName, rulesConfigList, cb = cb) } @@ -21,7 +22,8 @@ open class FixTestBase(protected val resourceFilePath: String, constructor(resourceFilePath: String, ruleSupplier: (rulesConfigList: List) -> Rule, rulesConfigList: List? = null, - cb: LintErrorCallback = defaultCallback) : this( + cb: LintErrorCallback = defaultCallback + ) : this( resourceFilePath, { overrideRulesConfigList -> DiktatRuleSetProvider4Test(ruleSupplier, overrideRulesConfigList) }, cb, @@ -57,7 +59,8 @@ open class FixTestBase(protected val resourceFilePath: String, */ protected fun fixAndCompare(expectedPath: String, testPath: String, - overrideRulesConfigList: List) { + overrideRulesConfigList: List + ) { val testComparatorUnit = TestComparatorUnit(resourceFilePath) { text, fileName -> format(ruleSetProviderRef, text, fileName, overrideRulesConfigList) } diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/util/LintTestBase.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/util/LintTestBase.kt index bc4098575f..b30db41139 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/util/LintTestBase.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/util/LintTestBase.kt @@ -24,7 +24,8 @@ open class LintTestBase(private val ruleSupplier: (rulesConfigList: List? = null, - fileName: String? = null) { + fileName: String? = null + ) { val actualFileName = fileName ?: TEST_FILE_NAME val res: MutableList = mutableListOf() KtLint.lint( diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/util/TestUtils.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/util/TestUtils.kt index 6bac637f11..17a2f3b63d 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/util/TestUtils.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/util/TestUtils.kt @@ -82,17 +82,17 @@ internal fun format(ruleSetProviderRef: (rulesConfigList: List?) -> text: String, fileName: String, rulesConfigList: List? = null, - cb: LintErrorCallback = defaultCallback) = - KtLint.format( - KtLint.Params( - text = text, - ruleSets = listOf(ruleSetProviderRef.invoke(rulesConfigList).get()), - fileName = fileName.removeSuffix("_copy"), - script = fileName.removeSuffix("_copy").endsWith("kts"), - cb = cb, - userData = mapOf("file_path" to fileName.removeSuffix("_copy")) - ) - ) + cb: LintErrorCallback = defaultCallback +) = KtLint.format( + KtLint.Params( + text = text, + ruleSets = listOf(ruleSetProviderRef.invoke(rulesConfigList).get()), + fileName = fileName.removeSuffix("_copy"), + script = fileName.removeSuffix("_copy").endsWith("kts"), + cb = cb, + userData = mapOf("file_path" to fileName.removeSuffix("_copy")) + ) +) /** * This utility function lets you run arbitrary code on every node of given [code]. @@ -106,7 +106,8 @@ internal fun format(ruleSetProviderRef: (rulesConfigList: List?) -> @Suppress("TYPE_ALIAS") internal fun applyToCode(code: String, expectedAsserts: Int, - applyToNode: (node: ASTNode, counter: AtomicInteger) -> Unit) { + applyToNode: (node: ASTNode, counter: AtomicInteger) -> Unit +) { val counter = AtomicInteger(0) KtLint.lint( KtLint.Params( @@ -115,7 +116,8 @@ internal fun applyToCode(code: String, RuleSet("test", object : Rule("astnode-utils-test") { override fun visit(node: ASTNode, autoCorrect: Boolean, - emit: EmitType) { + emit: EmitType + ) { applyToNode(node, counter) } }) diff --git a/diktat-rules/src/test/resources/test/paragraph2/kdoc/ConstructorCommentNewlineExpected.kt b/diktat-rules/src/test/resources/test/paragraph2/kdoc/ConstructorCommentNewlineExpected.kt new file mode 100644 index 0000000000..64e5156d99 --- /dev/null +++ b/diktat-rules/src/test/resources/test/paragraph2/kdoc/ConstructorCommentNewlineExpected.kt @@ -0,0 +1,19 @@ +package test.paragraph2.kdoc + +/** + * @property param1 + * @property param2 first comment +*/ +class Example( + val param1: String, + val param2: String, // second comment +) + +/** + * @property param1 + * @property param2 first comment +*/ +class Example( + val param1: String, + val param2: String, /* second comment */ +) \ No newline at end of file diff --git a/diktat-rules/src/test/resources/test/paragraph2/kdoc/ConstructorCommentNewlineTest.kt b/diktat-rules/src/test/resources/test/paragraph2/kdoc/ConstructorCommentNewlineTest.kt new file mode 100644 index 0000000000..5984676a5a --- /dev/null +++ b/diktat-rules/src/test/resources/test/paragraph2/kdoc/ConstructorCommentNewlineTest.kt @@ -0,0 +1,11 @@ +package test.paragraph2.kdoc + +class Example( + val param1: String, // first comment + val param2: String, // second comment +) + +class Example( + val param1: String, /* first comment */ + val param2: String, /* second comment */ +) \ No newline at end of file diff --git a/diktat-rules/src/test/resources/test/paragraph3/newlines/FunctionalStyleExpected.kt b/diktat-rules/src/test/resources/test/paragraph3/newlines/FunctionalStyleExpected.kt index 9d4a390efc..f2015e0bfe 100644 --- a/diktat-rules/src/test/resources/test/paragraph3/newlines/FunctionalStyleExpected.kt +++ b/diktat-rules/src/test/resources/test/paragraph3/newlines/FunctionalStyleExpected.kt @@ -63,4 +63,10 @@ code: CodeBlock, .beginControlFlow(format, *args) .add(code) .endControlFlow() -.build() \ No newline at end of file +.build() + +fun foo( +a: Int, + b: Int, + c: Int +): Int = 42 diff --git a/diktat-rules/src/test/resources/test/paragraph3/newlines/FunctionalStyleTest.kt b/diktat-rules/src/test/resources/test/paragraph3/newlines/FunctionalStyleTest.kt index 1ba0dcb74a..0323fafde1 100644 --- a/diktat-rules/src/test/resources/test/paragraph3/newlines/FunctionalStyleTest.kt +++ b/diktat-rules/src/test/resources/test/paragraph3/newlines/FunctionalStyleTest.kt @@ -40,4 +40,6 @@ fun controlFlow(code: CodeBlock, format: String, vararg args: Any?): CodeBlock = fun controlFlow(code: CodeBlock, format: String, vararg args: Any?,): CodeBlock = CodeBlock.builder().beginControlFlow(format, *args).add(code) - .endControlFlow().build() \ No newline at end of file + .endControlFlow().build() + +fun foo(a: Int, b: Int, c: Int): Int = 42 diff --git a/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/processing/FileComparator.kt b/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/processing/FileComparator.kt index 6bdedbf43c..cafbb63ad4 100644 --- a/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/processing/FileComparator.kt +++ b/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/processing/FileComparator.kt @@ -43,7 +43,8 @@ class FileComparator { @Suppress( "ReturnCount", "FUNCTION_BOOLEAN_PREFIX", - "TOO_LONG_FUNCTION") + "TOO_LONG_FUNCTION" + ) fun compareFilesEqual(): Boolean { try { val expect = readFile(expectedResultFile.absolutePath) diff --git a/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/processing/TestComparatorUnit.kt b/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/processing/TestComparatorUnit.kt index cd8f0ee587..a77519727c 100644 --- a/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/processing/TestComparatorUnit.kt +++ b/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/processing/TestComparatorUnit.kt @@ -28,7 +28,8 @@ class TestComparatorUnit(private val resourceFilePath: String, fun compareFilesFromResources( expectedResult: String, testFileStr: String, - trimLastEmptyLine: Boolean = false): Boolean { + trimLastEmptyLine: Boolean = false + ): Boolean { val expectedPath = javaClass.classLoader.getResource("$resourceFilePath/$expectedResult") val testPath = javaClass.classLoader.getResource("$resourceFilePath/$testFileStr") if (testPath == null || expectedPath == null) {