diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/DiktatRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/DiktatRule.kt index 2683290bb2..46a08cc875 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/DiktatRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/DiktatRule.kt @@ -51,10 +51,10 @@ abstract class DiktatRule( logic(node) } catch (internalError: Throwable) { log.error( - """Internal error has occurred in rule [$id]. Please make an issue on this bug at https://github.com/saveourtool/diKTat/. + """Internal error has occurred in rule [$id]. Please make an issue on this bug at https://github.com/saveourtool/diKTat/. As a workaround you can disable these inspections in yml config: <$inspections>. Root cause of the problem is in [${node.getFilePath()}] file. - """.trimIndent(), internalError + """.trimIndent(), internalError ) // we are very sorry for throwing common Error here, but unfortunately we are not able to throw // any existing Exception, as they will be caught in ktlint framework and the logging will be confusing: 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 dc9b2c4ce8..0ba1b38fe9 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 @@ -22,6 +22,7 @@ import org.cqfn.diktat.ruleset.utils.indentation.SuperTypeListChecker import org.cqfn.diktat.ruleset.utils.indentation.ValueParameterListChecker import com.pinterest.ktlint.core.ast.ElementType.CALL_EXPRESSION +import com.pinterest.ktlint.core.ast.ElementType.CLOSING_QUOTE import com.pinterest.ktlint.core.ast.ElementType.DOT_QUALIFIED_EXPRESSION import com.pinterest.ktlint.core.ast.ElementType.ELSE import com.pinterest.ktlint.core.ast.ElementType.FILE @@ -32,6 +33,7 @@ import com.pinterest.ktlint.core.ast.ElementType.LONG_STRING_TEMPLATE_ENTRY import com.pinterest.ktlint.core.ast.ElementType.LONG_TEMPLATE_ENTRY_END import com.pinterest.ktlint.core.ast.ElementType.LONG_TEMPLATE_ENTRY_START import com.pinterest.ktlint.core.ast.ElementType.LPAR +import com.pinterest.ktlint.core.ast.ElementType.OPEN_QUOTE import com.pinterest.ktlint.core.ast.ElementType.RBRACE import com.pinterest.ktlint.core.ast.ElementType.RBRACKET import com.pinterest.ktlint.core.ast.ElementType.RPAR @@ -39,6 +41,7 @@ import com.pinterest.ktlint.core.ast.ElementType.SAFE_ACCESS_EXPRESSION import com.pinterest.ktlint.core.ast.ElementType.SHORT_STRING_TEMPLATE_ENTRY import com.pinterest.ktlint.core.ast.ElementType.STRING_TEMPLATE import com.pinterest.ktlint.core.ast.ElementType.THEN +import com.pinterest.ktlint.core.ast.ElementType.VALUE_ARGUMENT import com.pinterest.ktlint.core.ast.ElementType.WHITE_SPACE import com.pinterest.ktlint.core.ast.visit import org.jetbrains.kotlin.com.intellij.lang.ASTNode @@ -78,6 +81,7 @@ class IndentationRule(configRules: List) : DiktatRule( } private lateinit var filePath: String private lateinit var customIndentationCheckers: List + private lateinit var positionByOffset: (Int) -> Pair override fun logic(node: ASTNode) { if (node.elementType == FILE) { @@ -173,10 +177,25 @@ class IndentationRule(configRules: List) : DiktatRule( } } + private fun isCloseAndOpenQuoterOffset(nodeWhiteSpace: ASTNode, expectedIndent: Int): Boolean { + val nextNode = nodeWhiteSpace.treeNext + if (nextNode.elementType == VALUE_ARGUMENT) { + val nextNodeDot = getNextDotExpression(nextNode) + nextNodeDot?.getFirstChildWithType(STRING_TEMPLATE)?.let { + if (it.getAllChildrenWithType(LITERAL_STRING_TEMPLATE_ENTRY).size > 1) { + val closingQuote = it.getFirstChildWithType(CLOSING_QUOTE)?.treePrev?.text + ?.length ?: -1 + return expectedIndent == closingQuote + } + } + } + return true + } + @Suppress("ForbiddenComment") private fun visitWhiteSpace(astNode: ASTNode, context: IndentContext) { context.maybeIncrement() - + positionByOffset = astNode.treeParent.calculateLineColByOffset() val whiteSpace = astNode.psi as PsiWhiteSpace if (astNode.treeNext.elementType in decreasingTokens) { // if newline is followed by closing token, it should already be indented less @@ -199,8 +218,15 @@ class IndentationRule(configRules: List) : DiktatRule( context.addException(astNode.treeParent, abs(indentError.expected - indentError.actual), false) } - if (checkResult?.isCorrect != true && expectedIndent != indentError.actual) { - WRONG_INDENTATION.warnAndFix(configRules, emitWarn, isFixMode, "expected $expectedIndent but was ${indentError.actual}", + val difOffsetCloseAndOpenQuote = isCloseAndOpenQuoterOffset(astNode, indentError.actual) + + if ((checkResult?.isCorrect != true && expectedIndent != indentError.actual) || !difOffsetCloseAndOpenQuote) { + val warnText = if (!difOffsetCloseAndOpenQuote) { + "the same number of indents to the opening and closing quotes was expected" + } else { + "expected $expectedIndent but was ${indentError.actual}" + } + WRONG_INDENTATION.warnAndFix(configRules, emitWarn, isFixMode, warnText, whiteSpace.startOffset + whiteSpace.text.lastIndexOf('\n') + 1, whiteSpace.node) { checkStringLiteral(whiteSpace, expectedIndent, indentError.actual) whiteSpace.node.indentBy(expectedIndent) @@ -216,16 +242,16 @@ class IndentationRule(configRules: List) : DiktatRule( expectedIndent: Int, actualIndent: Int ) { - val nextNode = whiteSpace.node.treeNext - if (nextNode != null && - nextNode.elementType == DOT_QUALIFIED_EXPRESSION && - nextNode.firstChildNode.elementType == STRING_TEMPLATE && - nextNode.firstChildNode.text.startsWith("\"\"\"") && - nextNode.findChildByType(CALL_EXPRESSION)?.text?.let { + val nextNodeDot = getNextDotExpression(whiteSpace.node.treeNext) + if (nextNodeDot != null && + nextNodeDot.elementType == DOT_QUALIFIED_EXPRESSION && + nextNodeDot.firstChildNode.elementType == STRING_TEMPLATE && + nextNodeDot.firstChildNode.text.startsWith("\"\"\"") && + nextNodeDot.findChildByType(CALL_EXPRESSION)?.text?.let { it == "trimIndent()" || it == "trimMargin()" } == true) { - fixStringLiteral(whiteSpace, expectedIndent, actualIndent) + fixStringLiteral(nextNodeDot.firstChildNode, expectedIndent, actualIndent) } } @@ -234,15 +260,12 @@ class IndentationRule(configRules: List) : DiktatRule( */ @Suppress("LOCAL_VARIABLE_EARLY_DECLARATION") private fun fixStringLiteral( - whiteSpace: PsiWhiteSpace, + stringTemplate: ASTNode, expectedIndent: Int, actualIndent: Int ) { val textIndent = " ".repeat(expectedIndent + INDENT_SIZE) - val templateEntries = whiteSpace.node - .treeNext - .firstChildNode - .getAllChildrenWithType(LITERAL_STRING_TEMPLATE_ENTRY) + val templateEntries = stringTemplate.getAllChildrenWithType(LITERAL_STRING_TEMPLATE_ENTRY) templateEntries.forEach { node -> if (!node.text.contains("\n")) { fixFirstTemplateEntries(node, textIndent, actualIndent) @@ -256,6 +279,12 @@ class IndentationRule(configRules: List) : DiktatRule( .trim()) } + private fun getNextDotExpression(node: ASTNode) = if (node.elementType == DOT_QUALIFIED_EXPRESSION) { + node + } else { + node.getFirstChildWithType(DOT_QUALIFIED_EXPRESSION) + } + /** * This method fixes all lines of string template except the last one * Also it considers $foo insertions in string diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter1/IdentifierNamingWarnTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter1/IdentifierNamingWarnTest.kt index d05182f194..028ce860a9 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter1/IdentifierNamingWarnTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter1/IdentifierNamingWarnTest.kt @@ -321,7 +321,6 @@ class IdentifierNamingWarnTest : LintTestBase(::IdentifierNaming) { const val M_GLOB = "" val aPrefix = "" """.trimIndent() - lintMethod(code, LintError(1, 11, ruleId, "${VARIABLE_HAS_PREFIX.warnText()} M_GLOB", true), LintError(2, 5, ruleId, "${VARIABLE_HAS_PREFIX.warnText()} aPrefix", true) @@ -336,7 +335,6 @@ class IdentifierNamingWarnTest : LintTestBase(::IdentifierNaming) { val I_AM_CONSTANT1 = "" const val I_AM_CONSTANT2 = "" """.trimIndent() - lintMethod(code, LintError(1, 5, ruleId, "${VARIABLE_NAME_INCORRECT_FORMAT.warnText()} I_AM_CONSTANT1", true), LintError(1, 5, ruleId, "${VARIABLE_HAS_PREFIX.warnText()} I_AM_CONSTANT1", true), @@ -358,7 +356,6 @@ class IdentifierNamingWarnTest : LintTestBase(::IdentifierNaming) { } } """.trimIndent() - lintMethod(code, LintError(5, 13, ruleId, "${VARIABLE_NAME_INCORRECT_FORMAT.warnText()} STRANGECASE", true) ) @@ -376,7 +373,6 @@ class IdentifierNamingWarnTest : LintTestBase(::IdentifierNaming) { } } """.trimIndent() - lintMethod(code, LintError(3, 35, ruleId, "${VARIABLE_NAME_INCORRECT_FORMAT.warnText()} STRANGECASE", true) ) @@ -387,13 +383,13 @@ class IdentifierNamingWarnTest : LintTestBase(::IdentifierNaming) { fun `FUNCTION_BOOLEAN_PREFIX - positive example`() { lintMethod( """ - fun ASTNode.hasEmptyLineAfter(): Boolean { } - fun hasEmptyLineAfter(): Boolean { } - fun ASTNode.isEmpty(): Boolean { } - fun isEmpty(): Boolean { } + fun ASTNode.hasEmptyLineAfter(): Boolean { } + fun hasEmptyLineAfter(): Boolean { } + fun ASTNode.isEmpty(): Boolean { } + fun isEmpty(): Boolean { } override fun empty(): Boolean { } override fun ASTNode.empty(): Boolean { } - """.trimIndent() + """.trimIndent() ) } @@ -402,11 +398,11 @@ class IdentifierNamingWarnTest : LintTestBase(::IdentifierNaming) { fun `FUNCTION_BOOLEAN_PREFIX - negative example`() { lintMethod( """ - fun ASTNode.emptyLineAfter(): Boolean { } - fun emptyLineAfter(): Boolean { } - fun ASTNode.empty(): Boolean { } - fun empty(): Boolean { } - """.trimIndent(), + fun ASTNode.emptyLineAfter(): Boolean { } + fun emptyLineAfter(): Boolean { } + fun ASTNode.empty(): Boolean { } + fun empty(): Boolean { } + """.trimIndent(), LintError(1, 13, ruleId, "${FUNCTION_BOOLEAN_PREFIX.warnText()} emptyLineAfter", true), LintError(2, 5, ruleId, "${FUNCTION_BOOLEAN_PREFIX.warnText()} emptyLineAfter", true), LintError(3, 13, ruleId, "${FUNCTION_BOOLEAN_PREFIX.warnText()} empty", true), @@ -419,12 +415,12 @@ class IdentifierNamingWarnTest : LintTestBase(::IdentifierNaming) { fun `all prefixes for boolean methods`() { lintMethod( """ - fun hasEmptyLineAfter(): Boolean { } - fun haveEmptyLineAfter(): Boolean { } - fun isEmpty(): Boolean { } + fun hasEmptyLineAfter(): Boolean { } + fun haveEmptyLineAfter(): Boolean { } + fun isEmpty(): Boolean { } fun shouldBeEmpty(): Boolean { } fun areEmpty(): Boolean { } - """.trimIndent() + """.trimIndent() ) } @@ -436,7 +432,7 @@ class IdentifierNamingWarnTest : LintTestBase(::IdentifierNaming) { fun equalsSome(): Boolean { } fun fooBar(): Boolean { } fun equivalentToAnother(): Boolean { } - """.trimIndent(), + """.trimIndent(), rulesConfigList = rulesConfigBooleanFunctions ) } @@ -447,15 +443,15 @@ class IdentifierNamingWarnTest : LintTestBase(::IdentifierNaming) { // valid example, should not cause exceptions lintMethod( """ - fun foo(predicate: (Int) -> Boolean) = Unit - """.trimIndent() + fun foo(predicate: (Int) -> Boolean) = Unit + """.trimIndent() ) // identifier names in function types are still checked if present lintMethod( """ - fun foo(predicate: (a: Int) -> Boolean) = Unit - """.trimIndent(), + fun foo(predicate: (a: Int) -> Boolean) = Unit + """.trimIndent(), LintError(1, 21, ruleId, "${IDENTIFIER_LENGTH.warnText()} a", false) ) } @@ -469,7 +465,6 @@ class IdentifierNamingWarnTest : LintTestBase(::IdentifierNaming) { override fun visit(node: ASTNode) {} }) """.trimIndent() - lintMethod(code) } @@ -484,7 +479,6 @@ class IdentifierNamingWarnTest : LintTestBase(::IdentifierNaming) { } } """.trimIndent() - lintMethod(code) } @@ -501,7 +495,6 @@ class IdentifierNamingWarnTest : LintTestBase(::IdentifierNaming) { } } """.trimIndent() - lintMethod(code, LintError(4, 17, ruleId, "${IDENTIFIER_LENGTH.warnText()} e", false)) } @@ -516,7 +509,6 @@ class IdentifierNamingWarnTest : LintTestBase(::IdentifierNaming) { } } """.trimIndent() - lintMethod(code) } @@ -529,7 +521,6 @@ class IdentifierNamingWarnTest : LintTestBase(::IdentifierNaming) { val `foo variable` = "" } """.trimIndent() - lintMethod(code, LintError(1, 5, ruleId, "${BACKTICKS_PROHIBITED.warnText()} `foo function`"), LintError(1, 20, ruleId, "${BACKTICKS_PROHIBITED.warnText()} `argument with backstick`"), @@ -546,7 +537,6 @@ class IdentifierNamingWarnTest : LintTestBase(::IdentifierNaming) { fun `test function with backstick`() { } """.trimIndent() - lintMethod(code) } @@ -561,7 +551,6 @@ class IdentifierNamingWarnTest : LintTestBase(::IdentifierNaming) { } """.trimIndent() - lintMethod(code, LintError(3, 9, ruleId, "${BACKTICKS_PROHIBITED.warnText()} `should not be used`")) } @@ -572,7 +561,6 @@ class IdentifierNamingWarnTest : LintTestBase(::IdentifierNaming) { """ class `my class name` {} """.trimIndent() - lintMethod(code, LintError(1, 7, ruleId, "${BACKTICKS_PROHIBITED.warnText()} `my class name`")) } @@ -614,7 +602,6 @@ class IdentifierNamingWarnTest : LintTestBase(::IdentifierNaming) { } } """.trimIndent() - lintMethod(code) } @@ -632,7 +619,6 @@ class IdentifierNamingWarnTest : LintTestBase(::IdentifierNaming) { B } """.trimIndent() - lintMethod(code, LintError(2, 9, ruleId, "${CONFUSING_IDENTIFIER_NAMING.warnText()} better name is: obj, dgt", false), LintError(2, 9, ruleId, "${VARIABLE_NAME_INCORRECT_FORMAT.warnText()} D", true), diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter1/MethodNamingWarnTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter1/MethodNamingWarnTest.kt index 189bef37e6..0e0b8f1990 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter1/MethodNamingWarnTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter1/MethodNamingWarnTest.kt @@ -106,7 +106,7 @@ class MethodNamingWarnTest : LintTestBase(::IdentifierNaming) { class TestPackageName { typealias RelatedClasses = List> } - """.trimIndent() + """.trimIndent() ) } diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter1/PackageNamingWarnTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter1/PackageNamingWarnTest.kt index 4a1226f81a..a870421b1a 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter1/PackageNamingWarnTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter1/PackageNamingWarnTest.kt @@ -277,7 +277,7 @@ class PackageNamingWarnTest : LintTestBase(::PackageNaming) { lintMethod( """ package org.cqfn.diktat.ruleset.chapter1 - """.trimIndent(), + """.trimIndent(), fileName = "~/diktat/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter1/EnumValueCaseTest.kt", rulesConfigList = rulesConfigList ) @@ -285,7 +285,7 @@ class PackageNamingWarnTest : LintTestBase(::PackageNaming) { lintMethod( """ package org.cqfn.diktat.chapter1 - """.trimIndent(), + """.trimIndent(), LintError(1, 9, ruleId, "${PACKAGE_NAME_INCORRECT_PATH.warnText()} org.cqfn.diktat.ruleset.chapter1", true), fileName = "~/diktat/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter1/EnumValueCaseTest.kt", rulesConfigList = rulesConfigList @@ -298,7 +298,7 @@ class PackageNamingWarnTest : LintTestBase(::PackageNaming) { lintMethod( """ |package org.cqfn.diktat.test.processing - """.trimMargin(), + """.trimMargin(), fileName = "/home/testu/project/module/src/test/kotlin/org/cqfn/diktat/test/processing/SpecialPackageNaming.kt", rulesConfigList = rulesConfigList ) @@ -306,7 +306,7 @@ class PackageNamingWarnTest : LintTestBase(::PackageNaming) { lintMethod( """ |package kotlin.collections - """.trimMargin(), + """.trimMargin(), fileName = "/home/testu/project/module/src/main/kotlin/kotlin/collections/Collections.kt", rulesConfigList = listOf( RulesConfig("DIKTAT_COMMON", true, mapOf("domainName" to "kotlin")) diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter2/KdocCommentsWarnTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter2/KdocCommentsWarnTest.kt index dfae0c5cf0..29c3bf3e3f 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter2/KdocCommentsWarnTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter2/KdocCommentsWarnTest.kt @@ -236,7 +236,7 @@ class KdocCommentsWarnTest : LintTestBase(::KdocComments) { private class InternalClass { } } - """.trimIndent() + """.trimIndent() ) } @@ -289,7 +289,7 @@ class KdocCommentsWarnTest : LintTestBase(::KdocComments) { |class Example { | override fun toString() = "" |} - """.trimMargin() + """.trimMargin() ) } @@ -308,7 +308,7 @@ class KdocCommentsWarnTest : LintTestBase(::KdocComments) { | val name: String |) { |} - """.trimMargin(), + """.trimMargin(), LintError(7, 4, ruleId, "${KDOC_NO_CONSTRUCTOR_PROPERTY_WITH_COMMENT.warnText()} name", true) ) } @@ -322,7 +322,7 @@ class KdocCommentsWarnTest : LintTestBase(::KdocComments) { |public class Example ( | override val serializersModule: SerializersModule = EmptySerializersModule |) - """.trimMargin() + """.trimMargin() ) } @@ -343,7 +343,7 @@ class KdocCommentsWarnTest : LintTestBase(::KdocComments) { | OneMoreName: String | ) |} - """.trimMargin() + """.trimMargin() ) } @@ -362,7 +362,7 @@ class KdocCommentsWarnTest : LintTestBase(::KdocComments) { | OneMoreName: String | ) { |} - """.trimMargin(), + """.trimMargin(), LintError(5, 4, ruleId, "${KDOC_NO_CONSTRUCTOR_PROPERTY_WITH_COMMENT.warnText()} name", true) ) } @@ -381,7 +381,7 @@ class KdocCommentsWarnTest : LintTestBase(::KdocComments) { | OneMoreName: String | ) { |} - """.trimMargin(), + """.trimMargin(), LintError(5, 4, ruleId, "${KDOC_NO_CONSTRUCTOR_PROPERTY.warnText()} /*some descriptions*/", true) ) } @@ -401,7 +401,7 @@ class KdocCommentsWarnTest : LintTestBase(::KdocComments) { | OneMoreName: String | ) { |} - """.trimMargin() + """.trimMargin() ) } @@ -424,7 +424,7 @@ class KdocCommentsWarnTest : LintTestBase(::KdocComments) { | OneMoreName: String | ) { |} - """.trimMargin(), + """.trimMargin(), LintError(5, 4, ruleId, "${KDOC_NO_CONSTRUCTOR_PROPERTY.warnText()} /**...", true) ) } @@ -445,7 +445,7 @@ class KdocCommentsWarnTest : LintTestBase(::KdocComments) { | val name: String, | ) { |} - """.trimMargin(), + """.trimMargin(), LintError(5, 4, ruleId, "${KDOC_NO_CONSTRUCTOR_PROPERTY.warnText()} /**...", false) ) } @@ -462,7 +462,7 @@ class KdocCommentsWarnTest : LintTestBase(::KdocComments) { | private val name: String, | ) { |} - """.trimMargin() + """.trimMargin() ) } @@ -479,7 +479,7 @@ class KdocCommentsWarnTest : LintTestBase(::KdocComments) { | val name: String, | ) { |} - """.trimMargin(), + """.trimMargin(), LintError(2, 4, ruleId, "${KDOC_EXTRA_PROPERTY.warnText()} @property Name text", false), LintError(6, 4, ruleId, "${KDOC_NO_CONSTRUCTOR_PROPERTY.warnText()} add to KDoc", true) ) @@ -495,7 +495,7 @@ class KdocCommentsWarnTest : LintTestBase(::KdocComments) { | private val surname: String | ) { |} - """.trimMargin(), + """.trimMargin(), LintError(1, 1, ruleId, "${MISSING_KDOC_TOP_LEVEL.warnText()} Example"), LintError(2, 4, ruleId, "${KDOC_NO_CONSTRUCTOR_PROPERTY.warnText()} add to KDoc", true) ) @@ -515,7 +515,7 @@ class KdocCommentsWarnTest : LintTestBase(::KdocComments) { | private val surname: String | ) { |} - """.trimMargin(), + """.trimMargin(), LintError(3, 4, ruleId, "${KDOC_EXTRA_PROPERTY.warnText()} @property kek", false) ) } diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter2/KdocMethodsTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter2/KdocMethodsTest.kt index 0cb229990d..412311f41f 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter2/KdocMethodsTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter2/KdocMethodsTest.kt @@ -273,28 +273,28 @@ class KdocMethodsTest : LintTestBase(::KdocMethods) { """ |class Example { | override fun toString() = "example" - | + | | override fun equals(other: Any?) = false - | + | | override fun hashCode() = 42 |} | |fun main() { } - """.trimMargin() + """.trimMargin() ) lintMethod( """ |class Example { | override fun toString(): String { return "example" } - | + | | override fun equals(other: Any?): Boolean { return false } - | + | | override fun hashCode(): Int { return 42 } |} | |fun main(vararg args: String) { } - """.trimMargin() + """.trimMargin() ) } @@ -307,24 +307,24 @@ class KdocMethodsTest : LintTestBase(::KdocMethods) { | fun setX(x: Type) { | this.x = x | } - | + | | fun getX(): Type { | return x | } - | + | | fun getY() = this.y - | + | | fun setY(y: Type) { | this.validate(y) | this.y = y | } - | + | | fun getZ(): TypeZ { | baz(z) | return z | } |} - """.trimMargin(), + """.trimMargin(), LintError(12, 5, ruleId, "${MISSING_KDOC_ON_FUNCTION.warnText()} setY", true), LintError(17, 5, ruleId, "${MISSING_KDOC_ON_FUNCTION.warnText()} getZ", true) ) @@ -336,7 +336,7 @@ class KdocMethodsTest : LintTestBase(::KdocMethods) { lintMethod( """ |fun foo() { } - """.trimMargin(), + """.trimMargin(), LintError(1, 1, ruleId, "${MISSING_KDOC_ON_FUNCTION.warnText()} foo", false) ) } @@ -350,7 +350,7 @@ class KdocMethodsTest : LintTestBase(::KdocMethods) { | * Returns X | */ |fun getX(): TypeX { return x } - """.trimMargin(), + """.trimMargin(), LintError(2, 3, ruleId, "${KDOC_TRIVIAL_KDOC_ON_FUNCTION.warnText()} Returns X", false) ) } @@ -362,10 +362,10 @@ class KdocMethodsTest : LintTestBase(::KdocMethods) { """ |class Some : A { | override fun foo() {} - | + | | override fun bar(t: T): U { return U() } |} - """.trimMargin() + """.trimMargin() ) } @@ -374,12 +374,12 @@ class KdocMethodsTest : LintTestBase(::KdocMethods) { fun `should check if KfDoc is not trivial`() { lintMethod( """ - |fun foo(x: Int): TypeX { + |fun foo(x: Int): TypeX { | val q = goo() | throw UnsupportedOperationException() - | return qwe + | return qwe |} - """.trimMargin(), + """.trimMargin(), LintError(1, 1, ruleId, "${MISSING_KDOC_ON_FUNCTION.warnText()} foo", true) ) } @@ -391,7 +391,7 @@ class KdocMethodsTest : LintTestBase(::KdocMethods) { """ |fun hasNoChildren() = children.size == 0 |fun getFirstChild() = children.elementAtOrNull(0) - """.trimMargin(), + """.trimMargin(), LintError(1, 1, ruleId, "${MISSING_KDOC_ON_FUNCTION.warnText()} hasNoChildren", true), LintError(2, 1, ruleId, "${MISSING_KDOC_ON_FUNCTION.warnText()} getFirstChild", true) ) @@ -404,7 +404,7 @@ class KdocMethodsTest : LintTestBase(::KdocMethods) { """ |@GetMapping("/projects") |fun getProjects() = projectService.getProjects(x.prop()) - """.trimMargin(), + """.trimMargin(), ) } @@ -415,7 +415,7 @@ class KdocMethodsTest : LintTestBase(::KdocMethods) { """ |actual fun writeToConsoleAc(msg: String, outputType: OutputStreamType) {} |expect fun writeToConsoleEx(msg: String, outputType: OutputStreamType) {} - """.trimMargin(), + """.trimMargin(), LintError(2, 1, ruleId, "${MISSING_KDOC_ON_FUNCTION.warnText()} writeToConsoleEx", true), ) } diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter2/KdocParamPresentWarnTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter2/KdocParamPresentWarnTest.kt index 1b6d5d4580..40231a66cc 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter2/KdocParamPresentWarnTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter2/KdocParamPresentWarnTest.kt @@ -24,7 +24,7 @@ class KdocParamPresentWarnTest : LintTestBase(::KdocMethods) { |* @param a - leftOffset |*/ |fun foo(a: Int) {} - """.trimMargin() + """.trimMargin() ) } @@ -38,7 +38,7 @@ class KdocParamPresentWarnTest : LintTestBase(::KdocMethods) { |* @param В - russian letter |*/ |fun foo(a: Int, B: Int) {} - """.trimMargin(), + """.trimMargin(), LintError(1, 1, ruleId, "${KDOC_WITHOUT_PARAM_TAG.warnText()} foo (a, B)", true), LintError(2, 3, ruleId, "${KDOC_WITHOUT_PARAM_TAG.warnText()} A param isn't present in argument list"), LintError(3, 3, ruleId, "${KDOC_WITHOUT_PARAM_TAG.warnText()} В param isn't present in argument list") @@ -54,7 +54,7 @@ class KdocParamPresentWarnTest : LintTestBase(::KdocMethods) { |* @param A - leftOffset |*/ |fun foo() {} - """.trimMargin(), + """.trimMargin(), LintError(2, 3, ruleId, "${KDOC_WITHOUT_PARAM_TAG.warnText()} A param isn't present in argument list") ) } @@ -73,7 +73,7 @@ class KdocParamPresentWarnTest : LintTestBase(::KdocMethods) { |* @param |*/ |fun foo (a: Int) {} - """.trimMargin(), + """.trimMargin(), LintError(6, 1, ruleId, "${KDOC_WITHOUT_PARAM_TAG.warnText()} foo (a)", true) ) } @@ -88,7 +88,7 @@ class KdocParamPresentWarnTest : LintTestBase(::KdocMethods) { |* @param b - qwe |*/ |fun foo(b: Int, a: Int) {} - """.trimMargin() + """.trimMargin() ) } @@ -102,7 +102,7 @@ class KdocParamPresentWarnTest : LintTestBase(::KdocMethods) { |/** |* @param a - qwe |*/ - """.trimMargin(), + """.trimMargin(), LintError(1, 1, ruleId, "${MISSING_KDOC_ON_FUNCTION.warnText()} foo", true) ) } diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter2/comments/CommentedCodeTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter2/comments/CommentedCodeTest.kt index 1f07e119fa..fced63982e 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter2/comments/CommentedCodeTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter2/comments/CommentedCodeTest.kt @@ -34,9 +34,9 @@ class CommentedCodeTest : LintTestBase(::CommentsRule) { fun `Should warn if commented out imports are detected (block comments)`() { lintMethod( """ - |/*import org.junit.Test - |import org.junit.Ignore*/ - """.trimMargin(), + |/*import org.junit.Test + |import org.junit.Ignore*/ + """.trimMargin(), LintError(1, 1, ruleId, "${COMMENTED_OUT_CODE.warnText()} import org.junit.Test", false), LintError(1, 1, ruleId, "${COMMENTED_OUT_CODE.warnText()} import org.junit.Ignore", false) ) @@ -47,16 +47,16 @@ class CommentedCodeTest : LintTestBase(::CommentsRule) { fun `Should warn if commented out code is detected (block comments)`() { lintMethod( """ - |import org.junit.Test - | - |fun foo(a: Int): Int { - | /* println(a + 42) - | println("This is a test string") - | val b = a*10 - | */ - | return 0 - |} - """.trimMargin(), + |import org.junit.Test + | + |fun foo(a: Int): Int { + | /* println(a + 42) + | println("This is a test string") + | val b = a*10 + | */ + | return 0 + |} + """.trimMargin(), LintError(4, 5, ruleId, "${COMMENTED_OUT_CODE.warnText()} println(a + 42)", false) ) } @@ -66,14 +66,14 @@ class CommentedCodeTest : LintTestBase(::CommentsRule) { fun `Should warn if commented out code is detected (single line comments)`() { lintMethod( """ - |import org.junit.Test - | - |fun foo(a: Int): Int { - |// println(a + 42) - |// println("This is a test string") - | return 0 - |} - """.trimMargin()) + |import org.junit.Test + | + |fun foo(a: Int): Int { + |// println(a + 42) + |// println("This is a test string") + | return 0 + |} + """.trimMargin()) } @Test @@ -81,14 +81,14 @@ class CommentedCodeTest : LintTestBase(::CommentsRule) { fun `Should warn if commented out function is detected single line comments`() { lintMethod( """ - |import org.junit.Test - | - |//fun foo(a: Int): Int { - |// println(a + 42) - |// println("This is a test string") - |// return 0 - |//} - """.trimMargin(), + |import org.junit.Test + | + |//fun foo(a: Int): Int { + |// println(a + 42) + |// println("This is a test string") + |// return 0 + |//} + """.trimMargin(), LintError(3, 1, ruleId, "${COMMENTED_OUT_CODE.warnText()} fun foo(a: Int): Int {", false) ) } @@ -98,15 +98,15 @@ class CommentedCodeTest : LintTestBase(::CommentsRule) { fun `Should warn if commented out function is detected - single line comments with surrounding text`() { lintMethod( """ - |import org.junit.Test - | - |// this function is disabled for now - |//fun foo(a: Int): Int { - |// println(a + 42) - |// println("This is a test string") - |// return 0 - |//} - """.trimMargin(), + |import org.junit.Test + | + |// this function is disabled for now + |//fun foo(a: Int): Int { + |// println(a + 42) + |// println("This is a test string") + |// return 0 + |//} + """.trimMargin(), LintError(4, 1, ruleId, "${COMMENTED_OUT_CODE.warnText()} fun foo(a: Int): Int {", false) ) } @@ -116,14 +116,14 @@ class CommentedCodeTest : LintTestBase(::CommentsRule) { fun `Should warn if commented out function is detected (block comment)`() { lintMethod( """ - |import org.junit.Test - | - |/*fun foo(a: Int): Int { - | println(a + 42) - | println("This is a test string") - | return 0 - |}*/ - """.trimMargin(), + |import org.junit.Test + | + |/*fun foo(a: Int): Int { + | println(a + 42) + | println("This is a test string") + | return 0 + |}*/ + """.trimMargin(), LintError(3, 1, ruleId, "${COMMENTED_OUT_CODE.warnText()} fun foo(a: Int): Int {", false) ) } @@ -157,7 +157,7 @@ class CommentedCodeTest : LintTestBase(::CommentsRule) { lintMethod( """ |class ScheduleTest { - |/* + |/* | fun clickFilters_showFilters() { | checkAnimationsDisabled() | @@ -195,14 +195,14 @@ class CommentedCodeTest : LintTestBase(::CommentsRule) { | private fun applyFilter(filter: String) { | // Open the filters sheet | onView(withId(R.id.filter_fab)).perform(click()) - | + | | // Get the content description of the view we need to click on | val uncheckedFilterContentDesc = | resources.getString(R.string.a11y_filter_not_applied, filter) - | + | | onView(allOf(withId(R.id.recyclerview_filter), withParent(withId(R.id.filter_sheet)))) | .check(matches(isDisplayed())) - | + | | // Scroll to the filter | onView(allOf(withId(R.id.recyclerview_filter), withParent(withId(R.id.filter_sheet)))) | .perform( @@ -245,7 +245,7 @@ class CommentedCodeTest : LintTestBase(::CommentsRule) { fun `should trigger on class with one space after comment start token`() { lintMethod( """ - |// class Test: Exception() + |// class Test: Exception() """.trimMargin()) } @@ -254,7 +254,7 @@ class CommentedCodeTest : LintTestBase(::CommentsRule) { fun `should trigger on class with one space after comment start token and 2 modifiers #1`() { lintMethod( """ - |// public data class Test(val some: Int): Exception() + |// public data class Test(val some: Int): Exception() """.trimMargin(), LintError(1, 1, ruleId, "${COMMENTED_OUT_CODE.warnText()} public data class Test(val some: Int): Exception()", false)) } @@ -264,7 +264,7 @@ class CommentedCodeTest : LintTestBase(::CommentsRule) { fun `should trigger on one-line comment with var or val`() { lintMethod( """ - |// var foo: Int = 1 + |// var foo: Int = 1 """.trimMargin(), LintError(1, 1, ruleId, "${COMMENTED_OUT_CODE.warnText()} var foo: Int = 1", false)) } @@ -274,9 +274,9 @@ class CommentedCodeTest : LintTestBase(::CommentsRule) { fun `should trigger on one-line multi comment`() { lintMethod( """ - | // fun foo() { - | // varfoo adda foofoo - | // } + | // fun foo() { + | // varfoo adda foofoo + | // } """.trimMargin(), LintError(1, 2, ruleId, "${COMMENTED_OUT_CODE.warnText()} fun foo() {", false)) } @@ -286,7 +286,7 @@ class CommentedCodeTest : LintTestBase(::CommentsRule) { fun `should trigger on one-line comment`() { lintMethod( """ - | // class A { val a = 2 } + | // class A { val a = 2 } """.trimMargin(), LintError(1, 2, ruleId, "${COMMENTED_OUT_CODE.warnText()} class A { val a = 2 }", false)) } @@ -296,7 +296,7 @@ class CommentedCodeTest : LintTestBase(::CommentsRule) { fun `should trigger on one-line block comment`() { lintMethod( """ - | /* class A { val a = 2 } */ + | /* class A { val a = 2 } */ """.trimMargin(), LintError(1, 2, ruleId, "${COMMENTED_OUT_CODE.warnText()} class A { val a = 2 }", false)) } @@ -306,7 +306,7 @@ class CommentedCodeTest : LintTestBase(::CommentsRule) { fun `should trigger on class with one space after comment start token and 2 modifiers #2`() { lintMethod( """ - |// internal sealed class Test: Exception() + |// internal sealed class Test: Exception() """.trimMargin()) } @@ -315,7 +315,7 @@ class CommentedCodeTest : LintTestBase(::CommentsRule) { fun `should trigger on import with one space after comment start token`() { lintMethod( """ - |// import some.org + |// import some.org """.trimMargin(), LintError(1, 1, ruleId, "${COMMENTED_OUT_CODE.warnText()} import some.org", false)) } @@ -325,7 +325,7 @@ class CommentedCodeTest : LintTestBase(::CommentsRule) { fun `should trigger on package with one space after comment start token`() { lintMethod( """ - |// package some.org + |// package some.org """.trimMargin(), LintError(1, 1, ruleId, "${COMMENTED_OUT_CODE.warnText()} package some.org", false)) } @@ -335,9 +335,9 @@ class CommentedCodeTest : LintTestBase(::CommentsRule) { fun `should trigger on function with one space after comment start token - { sign`() { lintMethod( """ - |// fun someFunc(name: String): Boolean { - |// val a = 5 - |// } + |// fun someFunc(name: String): Boolean { + |// val a = 5 + |// } """.trimMargin(), LintError(1, 1, ruleId, "${COMMENTED_OUT_CODE.warnText()} fun someFunc(name: String): Boolean {", false)) } @@ -347,8 +347,8 @@ class CommentedCodeTest : LintTestBase(::CommentsRule) { fun `should trigger on function with one space after comment start token - = sign`() { lintMethod( """ - |// fun someFunc(name: String): Boolean = - |// name.contains("a") + |// fun someFunc(name: String): Boolean = + |// name.contains("a") """.trimMargin(), LintError(1, 1, ruleId, "${COMMENTED_OUT_CODE.warnText()} fun someFunc(name: String): Boolean =", false)) } @@ -358,8 +358,8 @@ class CommentedCodeTest : LintTestBase(::CommentsRule) { fun `should trigger on function with one space after comment start token pulbic modifier`() { lintMethod( """ - |// public fun someFunc(name: String): Boolean = - |// name.contains("a") + |// public fun someFunc(name: String): Boolean = + |// name.contains("a") """.trimMargin(), LintError(1, 1, ruleId, "${COMMENTED_OUT_CODE.warnText()} public fun someFunc(name: String): Boolean =", false)) } @@ -369,23 +369,23 @@ class CommentedCodeTest : LintTestBase(::CommentsRule) { fun `should not trigger on multiline comments #1`() { lintMethod( """ - |/* - | - | Copyright 2018-2020 John Doe. - | - | Licensed under the Apache License, Version 2.0 (the "License"); - | you may not use this file except in compliance with the License. - | You may obtain a copy of the License at - | - | http://www.apache.org/licenses/LICENSE-2.0 - | - | Unless required by applicable law or agreed to in writing, software - | distributed under the License is distributed on an "AS IS" BASIS, - | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - | See the License for the specific language governing permissions and - | limitations under the License. - | - |*/ + |/* + | + | Copyright 2018-2020 John Doe. + | + | Licensed under the Apache License, Version 2.0 (the "License"); + | you may not use this file except in compliance with the License. + | You may obtain a copy of the License at + | + | http://www.apache.org/licenses/LICENSE-2.0 + | + | Unless required by applicable law or agreed to in writing, software + | distributed under the License is distributed on an "AS IS" BASIS, + | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + | See the License for the specific language governing permissions and + | limitations under the License. + | + |*/ """.trimMargin()) } @@ -394,10 +394,10 @@ class CommentedCodeTest : LintTestBase(::CommentsRule) { fun `should not trigger on multiline comments #2`() { lintMethod( """ - | /* - | * some text here - | maybe even with another line - | */ + | /* + | * some text here + | maybe even with another line + | */ """.trimMargin()) } @@ -409,23 +409,23 @@ class CommentedCodeTest : LintTestBase(::CommentsRule) { /* Copyright (c) Your Company Name Here. 2010-2021 */ - + package org.cqfn.diktat - + /* x = 2 + 4 + 1 */ // x = 2+4 - + // if true make this - + /* class A { - - fun foo() - + + fun foo() + } - + */ """.trimMargin(), LintError(7, 13, ruleId, "${COMMENTED_OUT_CODE.warnText()} x = 2 + 4 + 1", false), @@ -440,12 +440,12 @@ class CommentedCodeTest : LintTestBase(::CommentsRule) { """ @Suppress("UnsafeCallOnNullableType", "COMMENTED_OUT_CODE") private fun handleProperty(property: KtProperty) { - + /* x = 1 */ } - + @Suppress("COMMENTED_OUT_CODE") class A { // val x = 10 @@ -461,10 +461,10 @@ class CommentedCodeTest : LintTestBase(::CommentsRule) { """ /* Checks if specified imports can be found in classpath. */ class Example - + /* Checks if specified import can be found in classpath. */ class Example2 - + /* import this and you died. */ class Example3 """.trimMargin() diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/AnnotationNewLineRuleWarnTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/AnnotationNewLineRuleWarnTest.kt index 9fe6d26cab..ec415a75b0 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/AnnotationNewLineRuleWarnTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/AnnotationNewLineRuleWarnTest.kt @@ -23,7 +23,7 @@ class AnnotationNewLineRuleWarnTest : LintTestBase(::AnnotationNewLineRule) { |class A { | val a = 5 |} - """.trimMargin() + """.trimMargin() ) } @@ -35,7 +35,7 @@ class AnnotationNewLineRuleWarnTest : LintTestBase(::AnnotationNewLineRule) { |@SomeAnnotation class A { | val a = 5 |} - """.trimMargin() + """.trimMargin() ) } @@ -48,7 +48,7 @@ class AnnotationNewLineRuleWarnTest : LintTestBase(::AnnotationNewLineRule) { |class A { | val a = 5 |} - """.trimMargin(), + """.trimMargin(), LintError(1, 1, ruleId, "${Warnings.ANNOTATION_NEW_LINE.warnText()} @SomeAnnotation not on a single line", true), LintError(1, 17, ruleId, "${Warnings.ANNOTATION_NEW_LINE.warnText()} @SecondAnnotation not on a single line", true) ) @@ -62,7 +62,7 @@ class AnnotationNewLineRuleWarnTest : LintTestBase(::AnnotationNewLineRule) { |@SomeAnnotation @SecondAnnotation class A { | val a = 5 |} - """.trimMargin(), + """.trimMargin(), LintError(1, 1, ruleId, "${Warnings.ANNOTATION_NEW_LINE.warnText()} @SomeAnnotation not on a single line", true), LintError(1, 17, ruleId, "${Warnings.ANNOTATION_NEW_LINE.warnText()} @SecondAnnotation not on a single line", true) ) @@ -75,14 +75,14 @@ class AnnotationNewLineRuleWarnTest : LintTestBase(::AnnotationNewLineRule) { """ |class A { | val a = 5 - | + | | @SomeAnnotation | @SecondAnnotation | fun someFunc() { | val a = 3 | } |} - """.trimMargin() + """.trimMargin() ) } @@ -93,12 +93,12 @@ class AnnotationNewLineRuleWarnTest : LintTestBase(::AnnotationNewLineRule) { """ |class A { | val a = 5 - | + | | @SomeAnnotation fun someFunc() { | val a = 3 | } |} - """.trimMargin() + """.trimMargin() ) } @@ -109,12 +109,12 @@ class AnnotationNewLineRuleWarnTest : LintTestBase(::AnnotationNewLineRule) { """ |class A { | val a = 5 - | + | | @SomeAnnotation @SecondAnnotation fun someFunc() { | val a = 3 | } |} - """.trimMargin(), + """.trimMargin(), LintError(4, 3, ruleId, "${Warnings.ANNOTATION_NEW_LINE.warnText()} @SomeAnnotation not on a single line", true), LintError(4, 19, ruleId, "${Warnings.ANNOTATION_NEW_LINE.warnText()} @SecondAnnotation not on a single line", true) ) @@ -127,13 +127,13 @@ class AnnotationNewLineRuleWarnTest : LintTestBase(::AnnotationNewLineRule) { """ |class A { | val a = 5 - | - | @SomeAnnotation @SecondAnnotation + | + | @SomeAnnotation @SecondAnnotation | fun someFunc() { | val a = 3 | } |} - """.trimMargin(), + """.trimMargin(), LintError(4, 3, ruleId, "${Warnings.ANNOTATION_NEW_LINE.warnText()} @SomeAnnotation not on a single line", true), LintError(4, 19, ruleId, "${Warnings.ANNOTATION_NEW_LINE.warnText()} @SecondAnnotation not on a single line", true) ) @@ -149,7 +149,7 @@ class AnnotationNewLineRuleWarnTest : LintTestBase(::AnnotationNewLineRule) { |constructor(conf: Int) { | |} - """.trimMargin() + """.trimMargin() ) } @@ -161,7 +161,7 @@ class AnnotationNewLineRuleWarnTest : LintTestBase(::AnnotationNewLineRule) { |public class Conf @Inject constructor(conf: Int) { | |} - """.trimMargin() + """.trimMargin() ) } @@ -170,13 +170,13 @@ class AnnotationNewLineRuleWarnTest : LintTestBase(::AnnotationNewLineRule) { fun `annotation constructor test good 3`() { lintMethod( """ - |public class Conf - |@Inject - |@SomeAnnotation + |public class Conf + |@Inject + |@SomeAnnotation |constructor(conf: Int) { | |} - """.trimMargin() + """.trimMargin() ) } @@ -187,10 +187,10 @@ class AnnotationNewLineRuleWarnTest : LintTestBase(::AnnotationNewLineRule) { """ |public class Conf { | @FirstAnnotation constructor(conf: Conf) { - | + | | } |} - """.trimMargin() + """.trimMargin() ) } @@ -201,10 +201,10 @@ class AnnotationNewLineRuleWarnTest : LintTestBase(::AnnotationNewLineRule) { """ |public class Conf { | @FirstAnnotation @SecondAnnotation constructor(conf: Conf) { - | + | | } |} - """.trimMargin(), + """.trimMargin(), LintError(2, 4, ruleId, "${Warnings.ANNOTATION_NEW_LINE.warnText()} @FirstAnnotation not on a single line", true), LintError(2, 21, ruleId, "${Warnings.ANNOTATION_NEW_LINE.warnText()} @SecondAnnotation not on a single line", true) ) @@ -218,7 +218,7 @@ class AnnotationNewLineRuleWarnTest : LintTestBase(::AnnotationNewLineRule) { |public class Conf @Inject @SomeAnnotation constructor(conf: Int) { | |} - """.trimMargin(), + """.trimMargin(), LintError(1, 19, ruleId, "${Warnings.ANNOTATION_NEW_LINE.warnText()} @Inject not on a single line", true), LintError(1, 27, ruleId, "${Warnings.ANNOTATION_NEW_LINE.warnText()} @SomeAnnotation not on a single line", true) ) @@ -229,11 +229,11 @@ class AnnotationNewLineRuleWarnTest : LintTestBase(::AnnotationNewLineRule) { fun `annotation constructor test bad 2`() { lintMethod( """ - |public class Conf @Inject + |public class Conf @Inject |@SomeAnnotation constructor(conf: Int) { | |} - """.trimMargin(), + """.trimMargin(), LintError(1, 19, ruleId, "${Warnings.ANNOTATION_NEW_LINE.warnText()} @Inject not on a single line", true), LintError(2, 1, ruleId, "${Warnings.ANNOTATION_NEW_LINE.warnText()} @SomeAnnotation not on a single line", true) ) @@ -246,10 +246,10 @@ class AnnotationNewLineRuleWarnTest : LintTestBase(::AnnotationNewLineRule) { """ |public class Conf { | fun someFunc(@SomeAnnotation conf: JsonConf, @SecondAnnotation some: Int) { - | + | | } |} - """.trimMargin() + """.trimMargin() ) } @@ -260,10 +260,10 @@ class AnnotationNewLineRuleWarnTest : LintTestBase(::AnnotationNewLineRule) { """ |public class Conf { | fun someFunc(@SomeAnnotation @AnotherAnnotation conf: JsonConf, @SecondAnnotation @ThirdAnnotation some: Int) { - | + | | } |} - """.trimMargin() + """.trimMargin() ) } @@ -275,7 +275,7 @@ class AnnotationNewLineRuleWarnTest : LintTestBase(::AnnotationNewLineRule) { |@ExperimentalStdlibApi // to use `scan` on sequence | @Suppress("WRONG_NEWLINES") | override fun checkNode() {} - """.trimMargin() + """.trimMargin() ) } @@ -305,7 +305,7 @@ class AnnotationNewLineRuleWarnTest : LintTestBase(::AnnotationNewLineRule) { | |@Foo |@goo val loader: DataLoader - """.trimMargin(), + """.trimMargin(), LintError(1, 1, ruleId, "${Warnings.ANNOTATION_NEW_LINE.warnText()} @ExperimentalStdlibApi not on a single line", true), LintError(1, 32, ruleId, "${Warnings.ANNOTATION_NEW_LINE.warnText()} @Hello not on a single line", true), ) diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/BlockStructureBracesWarnTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/BlockStructureBracesWarnTest.kt index 85f7fbaec4..40fbfdde83 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/BlockStructureBracesWarnTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/BlockStructureBracesWarnTest.kt @@ -38,7 +38,7 @@ class BlockStructureBracesWarnTest : LintTestBase(::BlockStructureBraces) { | else { | koo()} |} - """.trimMargin(), + """.trimMargin(), LintError(4, 6, ruleId, "${BRACES_BLOCK_STRUCTURE_ERROR.warnText()} incorrect new line after closing brace", true), LintError(6, 13, ruleId, "${BRACES_BLOCK_STRUCTURE_ERROR.warnText()} no newline before closing brace", true) ) @@ -78,10 +78,10 @@ class BlockStructureBracesWarnTest : LintTestBase(::BlockStructureBraces) { | } else if (x > 5) { | hoo() | } else { - | koo() + | koo() | } |} - """.trimMargin() + """.trimMargin() ) } @@ -91,11 +91,11 @@ class BlockStructureBracesWarnTest : LintTestBase(::BlockStructureBraces) { lintMethod( """ |fun foo() { - | run { - | + | run { + | | } |} - """.trimMargin() + """.trimMargin() ) } @@ -109,10 +109,10 @@ class BlockStructureBracesWarnTest : LintTestBase(::BlockStructureBraces) { | goo() | } else if (x > 5) { | hoo() - | } else { + | } else { | } |} - """.trimMargin() + """.trimMargin() ) } @@ -126,7 +126,7 @@ class BlockStructureBracesWarnTest : LintTestBase(::BlockStructureBraces) { | goo() | } else {} |} - """.trimMargin(), + """.trimMargin(), LintError(4, 13, ruleId, "${BRACES_BLOCK_STRUCTURE_ERROR.warnText()} incorrect same line after opening brace", true), LintError(4, 13, ruleId, "${BRACES_BLOCK_STRUCTURE_ERROR.warnText()} no newline before closing brace", true) ) @@ -144,7 +144,7 @@ class BlockStructureBracesWarnTest : LintTestBase(::BlockStructureBraces) { | } else { f() | } |} - """.trimMargin(), + """.trimMargin(), LintError(2, 16, ruleId, "${BRACES_BLOCK_STRUCTURE_ERROR.warnText()} incorrect newline before opening brace", true), LintError(5, 13, ruleId, "${BRACES_BLOCK_STRUCTURE_ERROR.warnText()} incorrect same line after opening brace", true) ) @@ -161,7 +161,7 @@ class BlockStructureBracesWarnTest : LintTestBase(::BlockStructureBraces) { | else { | f() } |} - """.trimMargin(), + """.trimMargin(), LintError(3, 13, ruleId, "${BRACES_BLOCK_STRUCTURE_ERROR.warnText()} no newline before closing brace", true), LintError(3, 14, ruleId, "${BRACES_BLOCK_STRUCTURE_ERROR.warnText()} incorrect new line after closing brace", true), LintError(5, 12, ruleId, "${BRACES_BLOCK_STRUCTURE_ERROR.warnText()} no newline before closing brace", true) @@ -174,14 +174,14 @@ class BlockStructureBracesWarnTest : LintTestBase(::BlockStructureBraces) { lintMethod( """ |fun foo() { - | if (x < -5) + | if (x < -5) | { | goo() } | else | { | hoo() } |} - """.trimMargin(), + """.trimMargin(), LintError(4, 15, ruleId, "${BRACES_BLOCK_STRUCTURE_ERROR.warnText()} incorrect new line after closing brace", true), rulesConfigList = rulesConfigList ) @@ -192,11 +192,11 @@ class BlockStructureBracesWarnTest : LintTestBase(::BlockStructureBraces) { fun `check function expression with wrong open brace with configuration`() { lintMethod( """ - |fun foo() + |fun foo() |{ | pyu() |} - """.trimMargin(), rulesConfigList = rulesConfigListIgnoreOpen + """.trimMargin(), rulesConfigList = rulesConfigListIgnoreOpen ) } @@ -207,7 +207,7 @@ class BlockStructureBracesWarnTest : LintTestBase(::BlockStructureBraces) { """ |override fun foo() { |} - """.trimMargin() + """.trimMargin() ) } @@ -217,7 +217,7 @@ class BlockStructureBracesWarnTest : LintTestBase(::BlockStructureBraces) { lintMethod( """ |fun foo() = 0 - """.trimMargin() + """.trimMargin() ) } @@ -227,8 +227,7 @@ class BlockStructureBracesWarnTest : LintTestBase(::BlockStructureBraces) { lintMethod( """ |fun foo() {} - """.trimMargin() - + """.trimMargin() ) } @@ -239,7 +238,7 @@ class BlockStructureBracesWarnTest : LintTestBase(::BlockStructureBraces) { """ |fun foo() { | pyu() } - """.trimMargin(), + """.trimMargin(), LintError(2, 10, ruleId, "${BRACES_BLOCK_STRUCTURE_ERROR.warnText()} no newline before closing brace", true) ) } @@ -256,7 +255,7 @@ class BlockStructureBracesWarnTest : LintTestBase(::BlockStructureBraces) { | else -> println("df") | } |} - """.trimMargin(), + """.trimMargin(), LintError(2, 12, ruleId, "${BRACES_BLOCK_STRUCTURE_ERROR.warnText()} incorrect newline before opening brace", true) ) } @@ -270,7 +269,7 @@ class BlockStructureBracesWarnTest : LintTestBase(::BlockStructureBraces) { | for (i in 1..3) | println(i) |} - """.trimMargin() + """.trimMargin() ) } @@ -282,7 +281,7 @@ class BlockStructureBracesWarnTest : LintTestBase(::BlockStructureBraces) { |fun a(x: Int) { | for (i in 1..3) {} |} - """.trimMargin() + """.trimMargin() ) } @@ -295,7 +294,7 @@ class BlockStructureBracesWarnTest : LintTestBase(::BlockStructureBraces) { | while (x > 0) | x-- |} - """.trimMargin() + """.trimMargin() ) } @@ -307,10 +306,10 @@ class BlockStructureBracesWarnTest : LintTestBase(::BlockStructureBraces) { |fun sdf() { | do | { - | x-- + | x-- | } while (x != 0) |} - """.trimMargin(), + """.trimMargin(), LintError(2, 6, ruleId, "${BRACES_BLOCK_STRUCTURE_ERROR.warnText()} incorrect newline before opening brace", true) ) } @@ -321,19 +320,19 @@ class BlockStructureBracesWarnTest : LintTestBase(::BlockStructureBraces) { lintMethod( """ |fun divideOrZero(numerator: Int, denominator: Int): Int { - | try { + | try { | return numerator / denominator | } catch (e: ArithmeticException) { - | return 0 - | } + | return 0 + | } | catch (e: Exception) { | return 1 - | } + | } | finally { | println("Hello") | } |} - """.trimMargin(), + """.trimMargin(), LintError(6, 5, ruleId, "${BRACES_BLOCK_STRUCTURE_ERROR.warnText()} incorrect new line after closing brace", true), LintError(9, 5, ruleId, "${BRACES_BLOCK_STRUCTURE_ERROR.warnText()} incorrect new line after closing brace", true) ) @@ -347,11 +346,11 @@ class BlockStructureBracesWarnTest : LintTestBase(::BlockStructureBraces) { |fun divideOrZero(numerator: Int, denominator: Int): Int { | try { return numerator / denominator | } catch (e: ArithmeticException) { - | return 0 + | return 0 | } catch (e: Exception) { | return 1 } |} - """.trimMargin(), + """.trimMargin(), LintError(2, 9, ruleId, "${BRACES_BLOCK_STRUCTURE_ERROR.warnText()} incorrect same line after opening brace", true), LintError(6, 17, ruleId, "${BRACES_BLOCK_STRUCTURE_ERROR.warnText()} no newline before closing brace", true) ) @@ -367,7 +366,7 @@ class BlockStructureBracesWarnTest : LintTestBase(::BlockStructureBraces) { | println("Hello") | } |} - """.trimMargin() + """.trimMargin() ) } @@ -376,12 +375,12 @@ class BlockStructureBracesWarnTest : LintTestBase(::BlockStructureBraces) { fun `check wrong simple class expression but with config`() { lintMethod( """ - |class A + |class A |{ | fun foo() { | println("Hello") | } } - """.trimMargin(), rulesConfigList = rulesConfigList + """.trimMargin(), rulesConfigList = rulesConfigList ) } @@ -394,9 +393,9 @@ class BlockStructureBracesWarnTest : LintTestBase(::BlockStructureBraces) { | fun foo() { | println("Hello") | } - | + | | val x: Int = 10 } - """.trimMargin(), rulesConfigList = rulesConfigListIgnoreClose + """.trimMargin(), rulesConfigList = rulesConfigListIgnoreClose ) } @@ -410,10 +409,10 @@ class BlockStructureBracesWarnTest : LintTestBase(::BlockStructureBraces) { | fun foo() { | println("Hello") | } - | + | | val x: Int = 10 |} - """.trimMargin(), + """.trimMargin(), LintError(1, 9, ruleId, "${BRACES_BLOCK_STRUCTURE_ERROR.warnText()} incorrect newline before opening brace", true) ) } @@ -427,12 +426,12 @@ class BlockStructureBracesWarnTest : LintTestBase(::BlockStructureBraces) { | init | { | foo() } - | + | | fun foo() { | println("Hello") | } |} - """.trimMargin(), + """.trimMargin(), LintError(2, 8, ruleId, "${BRACES_BLOCK_STRUCTURE_ERROR.warnText()} incorrect newline before opening brace", true), LintError(4, 14, ruleId, "${BRACES_BLOCK_STRUCTURE_ERROR.warnText()} no newline before closing brace", true) ) @@ -448,7 +447,7 @@ class BlockStructureBracesWarnTest : LintTestBase(::BlockStructureBraces) { | println(id) | } |} - """.trimMargin() + """.trimMargin() ) } @@ -463,7 +462,7 @@ class BlockStructureBracesWarnTest : LintTestBase(::BlockStructureBraces) { | println(id) | } |} - """.trimMargin(), rulesConfigList = rulesConfigListIgnoreOpen + """.trimMargin(), rulesConfigList = rulesConfigListIgnoreOpen ) } @@ -474,13 +473,13 @@ class BlockStructureBracesWarnTest : LintTestBase(::BlockStructureBraces) { """ |class Person() { | val list = listOf("Hello", "World") - | + | | fun foo(){ | val size = list.map { it.length } | size.forEach { println(it) } | } |} - """.trimMargin() + """.trimMargin() ) } @@ -499,7 +498,7 @@ class BlockStructureBracesWarnTest : LintTestBase(::BlockStructureBraces) { | .filter { it.elementType == CLASS && | it.text == "sdc" } |} - """.trimMargin(), + """.trimMargin(), LintError(9, 33, ruleId, "${BRACES_BLOCK_STRUCTURE_ERROR.warnText()} no newline before closing brace", true) ) } diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/BracesRuleWarnTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/BracesRuleWarnTest.kt index e1c04c7e35..c8dc5b66f4 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/BracesRuleWarnTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/BracesRuleWarnTest.kt @@ -23,7 +23,7 @@ class BracesRuleWarnTest : LintTestBase(::BracesInConditionalsAndLoopsRule) { | bar() | } |} - """.trimMargin() + """.trimMargin() ) } @@ -35,10 +35,10 @@ class BracesRuleWarnTest : LintTestBase(::BracesInConditionalsAndLoopsRule) { |fun foo() { | if (x > 0) | bar() - | + | | if (y < 0) baz() |} - """.trimMargin(), + """.trimMargin(), LintError(2, 5, ruleId, "${NO_BRACES_IN_CONDITIONALS_AND_LOOPS.warnText()} IF", true), LintError(5, 5, ruleId, "${NO_BRACES_IN_CONDITIONALS_AND_LOOPS.warnText()} IF", true) ) @@ -58,7 +58,7 @@ class BracesRuleWarnTest : LintTestBase(::BracesInConditionalsAndLoopsRule) { | baz() | } |} - """.trimMargin() + """.trimMargin() ) } @@ -75,7 +75,7 @@ class BracesRuleWarnTest : LintTestBase(::BracesInConditionalsAndLoopsRule) { | else | baz() |} - """.trimMargin(), + """.trimMargin(), LintError(2, 5, ruleId, "${NO_BRACES_IN_CONDITIONALS_AND_LOOPS.warnText()} IF", true), LintError(4, 10, ruleId, "${NO_BRACES_IN_CONDITIONALS_AND_LOOPS.warnText()} IF", true), LintError(6, 5, ruleId, "${NO_BRACES_IN_CONDITIONALS_AND_LOOPS.warnText()} ELSE", true) @@ -90,7 +90,7 @@ class BracesRuleWarnTest : LintTestBase(::BracesInConditionalsAndLoopsRule) { |fun foo() { | if (x > 0) bar() else baz() |} - """.trimMargin() + """.trimMargin() ) } @@ -184,7 +184,7 @@ class BracesRuleWarnTest : LintTestBase(::BracesInConditionalsAndLoopsRule) { |fun foo() { | if (a) { | bar() - | } else + | } else | c.baz(b.apply {id = 5}) |} """.trimMargin(), @@ -202,7 +202,7 @@ class BracesRuleWarnTest : LintTestBase(::BracesInConditionalsAndLoopsRule) { | bar() | } else if (x == 0) bar() else baz() |} - """.trimMargin(), + """.trimMargin(), LintError(4, 12, ruleId, "${NO_BRACES_IN_CONDITIONALS_AND_LOOPS.warnText()} IF", true), LintError(4, 30, ruleId, "${NO_BRACES_IN_CONDITIONALS_AND_LOOPS.warnText()} ELSE", true) ) @@ -218,7 +218,7 @@ class BracesRuleWarnTest : LintTestBase(::BracesInConditionalsAndLoopsRule) { | else if (x == 0) | else foo() |} - """.trimMargin(), + """.trimMargin(), LintError(2, 5, ruleId, "${NO_BRACES_IN_CONDITIONALS_AND_LOOPS.warnText()} IF", true), LintError(3, 10, ruleId, "${NO_BRACES_IN_CONDITIONALS_AND_LOOPS.warnText()} IF", true), LintError(4, 5, ruleId, "${NO_BRACES_IN_CONDITIONALS_AND_LOOPS.warnText()} ELSE", true) @@ -246,7 +246,7 @@ class BracesRuleWarnTest : LintTestBase(::BracesInConditionalsAndLoopsRule) { | } | } |} - """.trimMargin(), + """.trimMargin(), LintError(7, 21, ruleId, "${NO_BRACES_IN_CONDITIONALS_AND_LOOPS.warnText()} WHEN", true), LintError(8, 21, ruleId, "${NO_BRACES_IN_CONDITIONALS_AND_LOOPS.warnText()} WHEN", true) ) @@ -262,7 +262,7 @@ class BracesRuleWarnTest : LintTestBase(::BracesInConditionalsAndLoopsRule) { | println(i) | } |} - """.trimMargin() + """.trimMargin() ) } @@ -275,7 +275,7 @@ class BracesRuleWarnTest : LintTestBase(::BracesInConditionalsAndLoopsRule) { | for (i in 1..100) | println(i) |} - """.trimMargin(), + """.trimMargin(), LintError(2, 5, ruleId, "${NO_BRACES_IN_CONDITIONALS_AND_LOOPS.warnText()} FOR", true) ) } @@ -290,7 +290,7 @@ class BracesRuleWarnTest : LintTestBase(::BracesInConditionalsAndLoopsRule) { | println("") | } |} - """.trimMargin() + """.trimMargin() ) } @@ -303,7 +303,7 @@ class BracesRuleWarnTest : LintTestBase(::BracesInConditionalsAndLoopsRule) { | while (condition) | println("") |} - """.trimMargin(), + """.trimMargin(), LintError(2, 5, ruleId, "${NO_BRACES_IN_CONDITIONALS_AND_LOOPS.warnText()} WHILE", true) ) } @@ -318,7 +318,7 @@ class BracesRuleWarnTest : LintTestBase(::BracesInConditionalsAndLoopsRule) { | println("") | } while (condition) |} - """.trimMargin() + """.trimMargin() ) } @@ -330,7 +330,7 @@ class BracesRuleWarnTest : LintTestBase(::BracesInConditionalsAndLoopsRule) { |fun foo() { | do println(i) while (condition) |} - """.trimMargin(), + """.trimMargin(), LintError(2, 5, ruleId, "${NO_BRACES_IN_CONDITIONALS_AND_LOOPS.warnText()} DO_WHILE", true) ) } @@ -343,7 +343,7 @@ class BracesRuleWarnTest : LintTestBase(::BracesInConditionalsAndLoopsRule) { |fun foo() { | do while (condition) |} - """.trimMargin(), + """.trimMargin(), LintError(2, 5, ruleId, "${NO_BRACES_IN_CONDITIONALS_AND_LOOPS.warnText()} DO_WHILE", true) ) } diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/ClassLikeStructuresOrderRuleWarnTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/ClassLikeStructuresOrderRuleWarnTest.kt index ec08f1caed..04b73a94d7 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/ClassLikeStructuresOrderRuleWarnTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/ClassLikeStructuresOrderRuleWarnTest.kt @@ -56,7 +56,7 @@ class ClassLikeStructuresOrderRuleWarnTest : LintTestBase(::ClassLikeStructuresO | private val FOO = 42 | private val log = LoggerFactory.getLogger(Example.javaClass) |} - """.trimMargin(), + """.trimMargin(), LintError(2, 5, ruleId, "${WRONG_ORDER_IN_CLASS_LIKE_STRUCTURES.warnText()} PROPERTY: FOO", true), LintError(3, 5, ruleId, "${WRONG_ORDER_IN_CLASS_LIKE_STRUCTURES.warnText()} PROPERTY: log", true) ) @@ -73,24 +73,24 @@ class ClassLikeStructuresOrderRuleWarnTest : LintTestBase(::ClassLikeStructuresO | // logger property | private val log = LoggerFactory.getLogger(Example.javaClass) | private val FOO = 42 - | + | | // another property | private val BAR = 43 - | + | | @Annotated | private val qux = 43 - | + | | // annotated property | @Annotated | private val quux = 43 - | + | | /** | * Yet another property. | */ | private val BAZ = 44 | @Annotated private lateinit var lateFoo: Int |} - """.trimMargin()) + """.trimMargin()) } @Test @@ -114,7 +114,7 @@ class ClassLikeStructuresOrderRuleWarnTest : LintTestBase(::ClassLikeStructuresO | private val BAZ = 44 | private lateinit var lateFoo: Int |} - """.trimMargin(), + """.trimMargin(), LintError(4, 5, ruleId, "${BLANK_LINE_BETWEEN_PROPERTIES.warnText()} BAR", true), LintError(6, 5, ruleId, "${BLANK_LINE_BETWEEN_PROPERTIES.warnText()} qux", true), LintError(8, 5, ruleId, "${BLANK_LINE_BETWEEN_PROPERTIES.warnText()} quux", true), @@ -129,16 +129,16 @@ class ClassLikeStructuresOrderRuleWarnTest : LintTestBase(::ClassLikeStructuresO """class Example { | fun foo() { | val bar = 0 - | + | | val baz = 1 | } - | + | | class Nested { | val bar = 0 | val baz = 1 | } |} - """.trimMargin() + """.trimMargin() ) } @@ -150,14 +150,14 @@ class ClassLikeStructuresOrderRuleWarnTest : LintTestBase(::ClassLikeStructuresO |class Example { | private val foo | get() = 0 - | + | | private var backing = 0 - | + | | var bar | get() = backing | set(value) { backing = value } |} - """.trimMargin() + """.trimMargin() ) } @@ -174,7 +174,7 @@ class ClassLikeStructuresOrderRuleWarnTest : LintTestBase(::ClassLikeStructuresO | get() = backing | set(value) { backing = value } |} - """.trimMargin() + """.trimMargin() ) } @@ -186,9 +186,9 @@ class ClassLikeStructuresOrderRuleWarnTest : LintTestBase(::ClassLikeStructuresO class Example { companion object { val b = "q" - + // this - private const val a = 3 + private const val a = 3 } } """.trimMargin(), @@ -206,7 +206,7 @@ class ClassLikeStructuresOrderRuleWarnTest : LintTestBase(::ClassLikeStructuresO FOO, BAR, ; - + fun f() {} companion object } diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/ConsecutiveSpacesRuleWarnTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/ConsecutiveSpacesRuleWarnTest.kt index 3b84b6602c..8d01a0758b 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/ConsecutiveSpacesRuleWarnTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/ConsecutiveSpacesRuleWarnTest.kt @@ -26,7 +26,7 @@ class ConsecutiveSpacesRuleWarnTest : LintTestBase(::ConsecutiveSpacesRule) { |enum class IntArithmetics : BinaryOperator { | PLUS, ASD |} - """.trimMargin(), + """.trimMargin(), LintError(1, 5, ruleId, "${TOO_MANY_CONSECUTIVE_SPACES.warnText()} found: 7. need to be: 1", true) ) } @@ -39,7 +39,7 @@ class ConsecutiveSpacesRuleWarnTest : LintTestBase(::ConsecutiveSpacesRule) { |enum class SomeEnum { | PLUS |} - """.trimMargin() + """.trimMargin() ) } @@ -52,7 +52,7 @@ class ConsecutiveSpacesRuleWarnTest : LintTestBase(::ConsecutiveSpacesRule) { | fun testFunction(val a = 5) { | } |} - """.trimMargin() + """.trimMargin() ) } @@ -65,7 +65,7 @@ class ConsecutiveSpacesRuleWarnTest : LintTestBase(::ConsecutiveSpacesRule) { | fun testFunction(val a = 6) { | } |} - """.trimMargin(), + """.trimMargin(), LintError(2, 7, ruleId, "${TOO_MANY_CONSECUTIVE_SPACES.warnText()} found: 6. need to be: 1", true), LintError(2, 33, ruleId, "${TOO_MANY_CONSECUTIVE_SPACES.warnText()} found: 5. need to be: 1", true) ) @@ -80,7 +80,7 @@ class ConsecutiveSpacesRuleWarnTest : LintTestBase(::ConsecutiveSpacesRule) { | inner class InnerClass{ | } |} - """.trimMargin(), + """.trimMargin(), LintError(1, 6, ruleId, "${TOO_MANY_CONSECUTIVE_SPACES.warnText()} found: 5. need to be: 1", true), LintError(2, 9, ruleId, "${TOO_MANY_CONSECUTIVE_SPACES.warnText()} found: 5. need to be: 1", true) ) @@ -95,7 +95,7 @@ class ConsecutiveSpacesRuleWarnTest : LintTestBase(::ConsecutiveSpacesRule) { | inner class InnerClass{ | } |} - """.trimMargin() + """.trimMargin() ) } @@ -111,7 +111,7 @@ class ConsecutiveSpacesRuleWarnTest : LintTestBase(::ConsecutiveSpacesRule) { | val c: Int | } |} - """.trimMargin() + """.trimMargin() ) } @@ -127,7 +127,7 @@ class ConsecutiveSpacesRuleWarnTest : LintTestBase(::ConsecutiveSpacesRule) { | val c: Int | } |} - """.trimMargin(), + """.trimMargin(), LintError(3, 15, ruleId, "${TOO_MANY_CONSECUTIVE_SPACES.warnText()} found: 4. need to be: 1", true), LintError(4, 18, ruleId, "${TOO_MANY_CONSECUTIVE_SPACES.warnText()} found: 5. need to be: 1", true), LintError(5, 14, ruleId, "${TOO_MANY_CONSECUTIVE_SPACES.warnText()} found: 5. need to be: 1", true) @@ -143,7 +143,7 @@ class ConsecutiveSpacesRuleWarnTest : LintTestBase(::ConsecutiveSpacesRule) { |class Box(t: T){ | var value = t |} - """.trimMargin() + """.trimMargin() ) } @@ -155,7 +155,7 @@ class ConsecutiveSpacesRuleWarnTest : LintTestBase(::ConsecutiveSpacesRule) { |class Box< T>(t: T){ | var value = t |} - """.trimMargin(), + """.trimMargin(), LintError(1, 11, ruleId, "${TOO_MANY_CONSECUTIVE_SPACES.warnText()} found: 3. need to be: 1", true), LintError(1, 19, ruleId, "${TOO_MANY_CONSECUTIVE_SPACES.warnText()} found: 4. need to be: 1", true) ) @@ -170,7 +170,7 @@ class ConsecutiveSpacesRuleWarnTest : LintTestBase(::ConsecutiveSpacesRule) { | fun foo() | fun bar() |} - """.trimMargin() + """.trimMargin() ) } @@ -183,7 +183,7 @@ class ConsecutiveSpacesRuleWarnTest : LintTestBase(::ConsecutiveSpacesRule) { | fun foo() | fun bar() |} - """.trimMargin(), + """.trimMargin(), LintError(1, 10, ruleId, "${TOO_MANY_CONSECUTIVE_SPACES.warnText()} found: 7. need to be: 1", true) ) } @@ -198,7 +198,7 @@ class ConsecutiveSpacesRuleWarnTest : LintTestBase(::ConsecutiveSpacesRule) { | print("SomeThing") | } |} - """.trimMargin(), + """.trimMargin(), LintError(2, 8, ruleId, "${TOO_MANY_CONSECUTIVE_SPACES.warnText()} found: 5. need to be: 1", true) ) } @@ -213,7 +213,7 @@ class ConsecutiveSpacesRuleWarnTest : LintTestBase(::ConsecutiveSpacesRule) { | print("SomeThing") | } |} - """.trimMargin() + """.trimMargin() ) } @@ -227,7 +227,7 @@ class ConsecutiveSpacesRuleWarnTest : LintTestBase(::ConsecutiveSpacesRule) { | print("SomeThing") | } |} - """.trimMargin(), + """.trimMargin(), rulesConfigList = rulesConfigListNoSpaces ) } @@ -240,7 +240,7 @@ class ConsecutiveSpacesRuleWarnTest : LintTestBase(::ConsecutiveSpacesRule) { |class SomeClass{ // this is a comment | val a = 5 // this is another comment |} - """.trimMargin() + """.trimMargin() ) } } diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/EmptyBlockWarnTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/EmptyBlockWarnTest.kt index 878d0206ab..aaf3028045 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/EmptyBlockWarnTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/EmptyBlockWarnTest.kt @@ -34,7 +34,7 @@ class EmptyBlockWarnTest : LintTestBase(::EmptyBlock) { | else { | } |} - """.trimMargin(), + """.trimMargin(), LintError(5, 10, ruleId, "${EMPTY_BLOCK_STRUCTURE_ERROR.warnText()} empty blocks are forbidden unless it is function with override keyword", false) ) } @@ -50,7 +50,7 @@ class EmptyBlockWarnTest : LintTestBase(::EmptyBlock) { | } | else {} |} - """.trimMargin(), + """.trimMargin(), LintError(5, 10, ruleId, "${EMPTY_BLOCK_STRUCTURE_ERROR.warnText()} empty blocks are forbidden unless it is function with override keyword", false), rulesConfigList = rulesConfigListIgnoreEmptyBlock ) @@ -63,7 +63,7 @@ class EmptyBlockWarnTest : LintTestBase(::EmptyBlock) { """ |override fun foo() { |} - """.trimMargin() + """.trimMargin() ) } @@ -79,7 +79,7 @@ class EmptyBlockWarnTest : LintTestBase(::EmptyBlock) { | else { | } |} - """.trimMargin(), + """.trimMargin(), rulesConfigList = rulesConfigListEmptyBlockExist ) } @@ -91,7 +91,7 @@ class EmptyBlockWarnTest : LintTestBase(::EmptyBlock) { |fun foo() { | if (node.treeParent != null) return |} - """.trimMargin() + """.trimMargin() ) } @@ -102,7 +102,7 @@ class EmptyBlockWarnTest : LintTestBase(::EmptyBlock) { |fun foo() { | run { } |} - """.trimMargin(), + """.trimMargin(), rulesConfigList = rulesConfigListEmptyBlockExist ) } @@ -114,7 +114,7 @@ class EmptyBlockWarnTest : LintTestBase(::EmptyBlock) { |fun foo() { | if (node.treeParent != null) return else println(true) |} - """.trimMargin() + """.trimMargin() ) } @@ -128,7 +128,7 @@ class EmptyBlockWarnTest : LintTestBase(::EmptyBlock) { | while (x > 0) | --x |} - """.trimMargin() + """.trimMargin() ) } @@ -138,9 +138,9 @@ class EmptyBlockWarnTest : LintTestBase(::EmptyBlock) { lintMethod( """ |fun foo() { - | val y = listOf().map { - | - | } + | val y = listOf().map { + | + | } |} """.trimMargin(), LintError(2, 30, ruleId, "${EMPTY_BLOCK_STRUCTURE_ERROR.warnText()} do not put newlines in empty lambda", true), @@ -153,9 +153,9 @@ class EmptyBlockWarnTest : LintTestBase(::EmptyBlock) { lintMethod( """ |fun foo() { - | val y = listOf().map { } + | val y = listOf().map { } |} - """.trimMargin(), + """.trimMargin(), LintError(2, 30, ruleId, "${EMPTY_BLOCK_STRUCTURE_ERROR.warnText()} empty blocks are forbidden unless it is function with override keyword", false) ) } diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/EnumsSeparatedWarnTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/EnumsSeparatedWarnTest.kt index 435f67c01f..2faa7e28da 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/EnumsSeparatedWarnTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/EnumsSeparatedWarnTest.kt @@ -24,7 +24,7 @@ class EnumsSeparatedWarnTest : LintTestBase(::EnumsSeparated) { | C, | ; |} - """.trimMargin() + """.trimMargin() ) } @@ -39,7 +39,7 @@ class EnumsSeparatedWarnTest : LintTestBase(::EnumsSeparated) { | C, | ; |} - """.trimMargin() + """.trimMargin() ) } @@ -52,7 +52,7 @@ class EnumsSeparatedWarnTest : LintTestBase(::EnumsSeparated) { | A, B, C; | fun foo() {} |} - """.trimMargin(), + """.trimMargin(), LintError(2, 4, ruleId, "${ENUMS_SEPARATED.warnText()} enum entries must end with a line break", true), LintError(2, 7, ruleId, "${ENUMS_SEPARATED.warnText()} enum entries must end with a line break", true), LintError(2, 10, ruleId, "${ENUMS_SEPARATED.warnText()} semicolon must be on a new line", true), @@ -68,7 +68,7 @@ class EnumsSeparatedWarnTest : LintTestBase(::EnumsSeparated) { |enum class ENUM { | A, B, C |} - """.trimMargin() + """.trimMargin() ) } @@ -78,10 +78,10 @@ class EnumsSeparatedWarnTest : LintTestBase(::EnumsSeparated) { lintMethod( """ |enum class ENUM { - | A, B, + | A, B, | C |} - """.trimMargin(), + """.trimMargin(), LintError(2, 4, ruleId, "${ENUMS_SEPARATED.warnText()} enum entries must end with a line break", true), LintError(3, 4, ruleId, "${ENUMS_SEPARATED.warnText()} enums must end with semicolon", true), LintError(3, 4, ruleId, "${ENUMS_SEPARATED.warnText()} last enum entry must end with a comma", true) @@ -94,10 +94,10 @@ class EnumsSeparatedWarnTest : LintTestBase(::EnumsSeparated) { lintMethod( """ |enum class ENUM { - | A, B, + | A, B, | C, ; |} - """.trimMargin(), + """.trimMargin(), LintError(2, 4, ruleId, "${ENUMS_SEPARATED.warnText()} enum entries must end with a line break", true), LintError(3, 4, ruleId, "${ENUMS_SEPARATED.warnText()} semicolon must be on a new line", true) ) @@ -114,7 +114,7 @@ class EnumsSeparatedWarnTest : LintTestBase(::EnumsSeparated) { | BLUE(0x0000FF), | ; |} - """.trimMargin() + """.trimMargin() ) } @@ -129,7 +129,7 @@ class EnumsSeparatedWarnTest : LintTestBase(::EnumsSeparated) { | BLUE(0x0000FF) | ; |} - """.trimMargin(), + """.trimMargin(), LintError(4, 4, ruleId, "${ENUMS_SEPARATED.warnText()} last enum entry must end with a comma", true) ) } @@ -142,14 +142,14 @@ class EnumsSeparatedWarnTest : LintTestBase(::EnumsSeparated) { |enum class Warnings { | WAITING { | override fun signal() = TALKING - | }, + | }, | TALKING { | override fun signal() = TALKING | }, | ; | abstract fun signal(): ProtocolState |} - """.trimMargin() + """.trimMargin() ) } @@ -161,13 +161,13 @@ class EnumsSeparatedWarnTest : LintTestBase(::EnumsSeparated) { |enum class Warnings { | WAITING { | override fun signal() = TALKING - | }, + | }, | TALKING { | override fun signal() = TALKING | }; | abstract fun signal(): ProtocolState |} - """.trimMargin(), + """.trimMargin(), LintError(5, 4, ruleId, "${ENUMS_SEPARATED.warnText()} semicolon must be on a new line", true), LintError(5, 4, ruleId, "${ENUMS_SEPARATED.warnText()} last enum entry must end with a comma", true) ) @@ -186,7 +186,7 @@ class EnumsSeparatedWarnTest : LintTestBase(::EnumsSeparated) { | override fun signal() = TALKING | } |} - """.trimMargin(), + """.trimMargin(), LintError(5, 4, ruleId, "${ENUMS_SEPARATED.warnText()} enums must end with semicolon", true), LintError(5, 4, ruleId, "${ENUMS_SEPARATED.warnText()} last enum entry must end with a comma", true) diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/LineLengthWarnTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/LineLengthWarnTest.kt index 144d3656a7..fb92dec786 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/LineLengthWarnTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/LineLengthWarnTest.kt @@ -53,7 +53,7 @@ class LineLengthWarnTest : LintTestBase(::LineLength) { | fun foo() { | } |} - """.trimMargin(), + """.trimMargin(), rulesConfigList = shortLineLength ) } @@ -82,7 +82,7 @@ class LineLengthWarnTest : LintTestBase(::LineLength) { | fun foo() { | } |} - """.trimMargin(), + """.trimMargin(), LintError(8, 1, ruleId, "${LONG_LINE.warnText()} max line length 120, but was 163", false) ) } @@ -110,7 +110,7 @@ class LineLengthWarnTest : LintTestBase(::LineLength) { | fun foo() { | } |} - """.trimMargin(), + """.trimMargin(), rulesConfigList = rulesConfigListLineLength ) } @@ -140,7 +140,7 @@ class LineLengthWarnTest : LintTestBase(::LineLength) { | val str = "sdjhkjdfhkjsdhfkshfkjshkfhsdkjfhskjdfhkshdfkjsdhfkjsdhfkshdkfhsdkjfhskdjfhkjsdfhkjsdhfjksdhfkjsdhfjkhsdkjfhskdjfhksdfhskdhf" | } |} - """.trimMargin(), + """.trimMargin(), LintError(14, 1, ruleId, "${LONG_LINE.warnText()} max line length 120, but was 143", true), LintError(18, 1, ruleId, "${LONG_LINE.warnText()} max line length 120, but was 142", true) ) @@ -157,7 +157,7 @@ class LineLengthWarnTest : LintTestBase(::LineLength) { |import org.cqfn.diktat.util.lintMethod | |/** - | * This is very important URL https://www.google.com/search?q=djfhvkdfhvkdh+gthtdj%3Bb&rlz=1C1GCEU_enRU909RU909&oq=posible+gthtdj%3Bb&aqs=chrome..69i57j0l3.2680j1j7&sourceid=chrome&ie=UTF-8 + | * This is very important URL https://www.google.com/search?q=djfhvkdfhvkdh+gthtdj%3Bb&rlz=1C1GCEU_enRU909RU909&oq=posible+gthtdj%3Bb&aqs=chrome..69i57j0l3.2680j1j7&sourceid=chrome&ie=UTF-8 | * https://www.google.com/search?q=djfhvkdfhvkdh+gthtdj%3Bb&rlz=1C1GCEU_enRU909RU909&oq=posible+gthtdj%3Bb&aqs=chrome..69i57j0l3.2680j1j7&sourceid=chrome&ie=UTF-8 | * $correctUrl this text can be on another line | * @param a @@ -171,7 +171,7 @@ class LineLengthWarnTest : LintTestBase(::LineLength) { | val str = "sdjhkjdfhkjsdhfkshfkjshkfhsdkjfhskjdfhkshdfkjsdhfkjsdhfkshdkfhsdkjfhskdjfhkjsdfhkjsdhfjksdhfkjsdhfjkhsdkjfhskdjfhksdfhskdhf" | } |} - """.trimMargin(), + """.trimMargin(), LintError(9, 1, ruleId, "${LONG_LINE.warnText()} max line length 163, but was 195", false), rulesConfigList = rulesConfigListLineLength ) @@ -200,7 +200,7 @@ class LineLengthWarnTest : LintTestBase(::LineLength) { | println(123) | } |} - """.trimMargin() + """.trimMargin() ) } @@ -221,7 +221,7 @@ class LineLengthWarnTest : LintTestBase(::LineLength) { | println("dhfgkjdhfgkjhdkfjghdkjfghdkjfhgkdfhgdkghkghdkjfhgdkghfkdjhfgkjdhfgjkdhfgkjddhfgkdhfgjkdh") | } |} - """.trimMargin(), + """.trimMargin(), LintError(8, 1, ruleId, "${LONG_LINE.warnText()} max line length 120, but was 130", false), LintError(9, 1, ruleId, "${LONG_LINE.warnText()} max line length 120, but was 123", true) 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 99d7a96159..a89837437b 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 @@ -30,7 +30,7 @@ class LocalVariablesWarnTest : LintTestBase(::LocalVariablesRule) { |class Example { | val bar = 0 |} - """.trimMargin() + """.trimMargin() ) } @@ -47,7 +47,7 @@ class LocalVariablesWarnTest : LintTestBase(::LocalVariablesRule) { | println() | } |} - """.trimMargin() + """.trimMargin() ) } @@ -59,12 +59,12 @@ class LocalVariablesWarnTest : LintTestBase(::LocalVariablesRule) { |class Example { | fun foo() { | val bar = 0 - | + | | baz(bar) | println() | } |} - """.trimMargin() + """.trimMargin() ) } @@ -81,7 +81,7 @@ class LocalVariablesWarnTest : LintTestBase(::LocalVariablesRule) { | println() | } |} - """.trimMargin() + """.trimMargin() ) } @@ -95,7 +95,7 @@ class LocalVariablesWarnTest : LintTestBase(::LocalVariablesRule) { | baz(bar) | println() |} - """.trimMargin() + """.trimMargin() ) } @@ -110,7 +110,7 @@ class LocalVariablesWarnTest : LintTestBase(::LocalVariablesRule) { | ?.baz(bar) | println() |} - """.trimMargin() + """.trimMargin() ) } @@ -124,7 +124,7 @@ class LocalVariablesWarnTest : LintTestBase(::LocalVariablesRule) { | println() | baz(bar) |} - """.trimMargin(), + """.trimMargin(), LintError(2, 5, ruleId, "${Warnings.LOCAL_VARIABLE_EARLY_DECLARATION.warnText()} ${warnMessage("bar", 2, 4)}", false) ) } @@ -139,7 +139,7 @@ class LocalVariablesWarnTest : LintTestBase(::LocalVariablesRule) { | .foo() | baz(bar) |} - """.trimMargin() + """.trimMargin() ) } @@ -149,12 +149,12 @@ class LocalVariablesWarnTest : LintTestBase(::LocalVariablesRule) { lintMethod( """ |fun foo() { - | val bar = 1 + + | val bar = 1 + | 2 | println() | baz(bar) |} - """.trimMargin(), + """.trimMargin(), LintError(2, 5, ruleId, "${Warnings.LOCAL_VARIABLE_EARLY_DECLARATION.warnText()} ${warnMessage("bar", 2, 5)}", false) ) } @@ -170,7 +170,7 @@ class LocalVariablesWarnTest : LintTestBase(::LocalVariablesRule) { | println() | baz(bar) |} - """.trimMargin(), + """.trimMargin(), LintError(2, 5, ruleId, "${Warnings.LOCAL_VARIABLE_EARLY_DECLARATION.warnText()} ${warnMessage("bar", 2, 5)}", false) ) } @@ -186,7 +186,7 @@ class LocalVariablesWarnTest : LintTestBase(::LocalVariablesRule) { | println() | baz(bar) |} - """.trimMargin(), + """.trimMargin(), LintError(2, 5, ruleId, "${Warnings.LOCAL_VARIABLE_EARLY_DECLARATION.warnText()} ${warnMessage("bar", 2, 5)}", false) ) } @@ -205,7 +205,7 @@ class LocalVariablesWarnTest : LintTestBase(::LocalVariablesRule) { | println() | } |} - """.trimMargin(), + """.trimMargin(), LintError(2, 5, ruleId, "${Warnings.LOCAL_VARIABLE_EARLY_DECLARATION.warnText()} val bar = 0", false) ) } @@ -224,7 +224,7 @@ class LocalVariablesWarnTest : LintTestBase(::LocalVariablesRule) { | qux(bar) | } |} - """.trimMargin() + """.trimMargin() ) } @@ -247,7 +247,7 @@ class LocalVariablesWarnTest : LintTestBase(::LocalVariablesRule) { | println() | } |} - """.trimMargin(), + """.trimMargin(), LintError(2, 5, ruleId, "${Warnings.LOCAL_VARIABLE_EARLY_DECLARATION.warnText()} val bar = 0", false) ) } @@ -263,7 +263,7 @@ class LocalVariablesWarnTest : LintTestBase(::LocalVariablesRule) { | bar() | } |} - """.trimMargin() + """.trimMargin() ) } @@ -282,7 +282,7 @@ class LocalVariablesWarnTest : LintTestBase(::LocalVariablesRule) { | offset += it.length | } |} - """.trimMargin() + """.trimMargin() ) } @@ -298,7 +298,7 @@ class LocalVariablesWarnTest : LintTestBase(::LocalVariablesRule) { | } | return offset |} - """.trimMargin() + """.trimMargin() ) } @@ -317,7 +317,7 @@ class LocalVariablesWarnTest : LintTestBase(::LocalVariablesRule) { | offset += it.length | } |} - """.trimMargin() + """.trimMargin() ) } @@ -335,7 +335,7 @@ class LocalVariablesWarnTest : LintTestBase(::LocalVariablesRule) { | return Bar(x) | } |} - """.trimMargin() + """.trimMargin() ) } @@ -352,7 +352,7 @@ class LocalVariablesWarnTest : LintTestBase(::LocalVariablesRule) { | val y = bar() | qux(y) |} - """.trimMargin() + """.trimMargin() ) } @@ -368,7 +368,7 @@ class LocalVariablesWarnTest : LintTestBase(::LocalVariablesRule) { | bar(x) | } |} - """.trimMargin() + """.trimMargin() ) } @@ -383,7 +383,7 @@ class LocalVariablesWarnTest : LintTestBase(::LocalVariablesRule) { | bar(x) | } |} - """.trimMargin() + """.trimMargin() ) } @@ -399,7 +399,7 @@ class LocalVariablesWarnTest : LintTestBase(::LocalVariablesRule) { | bar(x) | } |} - """.trimMargin(), + """.trimMargin(), LintError(2, 5, ruleId, "${Warnings.LOCAL_VARIABLE_EARLY_DECLARATION.warnText()} ${warnMessage("x", 2, 5)}", false) ) } @@ -417,7 +417,7 @@ class LocalVariablesWarnTest : LintTestBase(::LocalVariablesRule) { | bar(x) | } |} - """.trimMargin(), + """.trimMargin(), LintError(2, 5, ruleId, "${Warnings.LOCAL_VARIABLE_EARLY_DECLARATION.warnText()} ${warnMessage("x", 2, 6)}", false) ) } @@ -434,7 +434,7 @@ class LocalVariablesWarnTest : LintTestBase(::LocalVariablesRule) { | foo.baz(it) | } |} - """.trimMargin(), + """.trimMargin(), LintError(3, 9, ruleId, "${Warnings.LOCAL_VARIABLE_EARLY_DECLARATION.warnText()} ${warnMessage("foo", 3, 5)}", false) ) } @@ -449,7 +449,7 @@ class LocalVariablesWarnTest : LintTestBase(::LocalVariablesRule) { | val y = 1 | foo(x, y) |} - """.trimMargin() + """.trimMargin() ) } @@ -465,7 +465,7 @@ class LocalVariablesWarnTest : LintTestBase(::LocalVariablesRule) { | val z = 2 | foo(x, y, z) |} - """.trimMargin() + """.trimMargin() ) } @@ -483,7 +483,7 @@ class LocalVariablesWarnTest : LintTestBase(::LocalVariablesRule) { | foo(a, b, c) | } |} - """.trimMargin() + """.trimMargin() ) } @@ -499,7 +499,7 @@ class LocalVariablesWarnTest : LintTestBase(::LocalVariablesRule) { | resOption.isRequired = isRequired | return resOption |} - """.trimMargin() + """.trimMargin() ) } @@ -513,7 +513,7 @@ class LocalVariablesWarnTest : LintTestBase(::LocalVariablesRule) { | println() | bar(list) |} - """.trimMargin(), + """.trimMargin(), LintError(2, 5, ruleId, "${Warnings.LOCAL_VARIABLE_EARLY_DECLARATION.warnText()} ${warnMessage("list", 2, 4)}", false) ) } @@ -532,7 +532,7 @@ class LocalVariablesWarnTest : LintTestBase(::LocalVariablesRule) { | ) | Assertions.assertThat(res).isEmpty() |} - """.trimMargin() + """.trimMargin() ) } @@ -548,7 +548,7 @@ class LocalVariablesWarnTest : LintTestBase(::LocalVariablesRule) { | listOf().forEach { a -> println(a) } | } |} - """.trimMargin() + """.trimMargin() ) } @@ -564,11 +564,11 @@ class LocalVariablesWarnTest : LintTestBase(::LocalVariablesRule) { | fun for() : String { | } | } - | ${"\"\"\""}.trimIndent() + | ${"\"\"\""}.trimIndent() | bar(code) | } |} - """.trimMargin() + """.trimMargin() ) } @@ -581,7 +581,7 @@ class LocalVariablesWarnTest : LintTestBase(::LocalVariablesRule) { | val extensionFunctionList = node.findAllNodesWithSpecificType(FUN).filter { it.hasChildOfType(TYPE_REFERENCE) && it.hasChildOfType(DOT) } | val distinctFunctionSignatures = mutableMapOf() // maps function signatures on node it is used by | val extensionFunctionsPairs = mutableListOf>() // pairs extension functions with same signature - | + | | extensionFunctionList.forEach { func -> | if (distinctFunctionSignatures.contains(signature)) { | val secondFuncClassName = distinctFunctionSignatures[signature]!!.findChildBefore(DOT, TYPE_REFERENCE)!!.text @@ -594,7 +594,7 @@ class LocalVariablesWarnTest : LintTestBase(::LocalVariablesRule) { | } | return extensionFunctionsPairs | } - """.trimMargin() + """.trimMargin() ) } @@ -609,13 +609,13 @@ class LocalVariablesWarnTest : LintTestBase(::LocalVariablesRule) { | var prevNode: ASTNode | do { | prevNode = node - | node = node.treeParent - | if (node.elementType == ElementType.PARENTHESIZED) { + | node = node.treeParent + | if (node.elementType == ElementType.PARENTHESIZED) { | text += getTextFromParenthesized(node) | } | } while (node.elementType != BINARY_EXPRESSION) | } - """.trimMargin() + """.trimMargin() ) } @@ -639,7 +639,7 @@ class LocalVariablesWarnTest : LintTestBase(::LocalVariablesRule) { | .toList() | .reversed() | } - """.trimMargin() + """.trimMargin() ) } @@ -654,7 +654,7 @@ class LocalVariablesWarnTest : LintTestBase(::LocalVariablesRule) { | var prevNode: ASTNode | some(text, node, prevNode) | } - """.trimMargin() + """.trimMargin() ) } @@ -670,7 +670,7 @@ class LocalVariablesWarnTest : LintTestBase(::LocalVariablesRule) { | val prevNode: ASTNode = astNode | some(text, node, prevNode) | } - """.trimMargin() + """.trimMargin() ) } diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/LongNumericalValuesSeparatedWarnTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/LongNumericalValuesSeparatedWarnTest.kt index 3e7650d209..0c5dee6dc6 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/LongNumericalValuesSeparatedWarnTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/LongNumericalValuesSeparatedWarnTest.kt @@ -34,7 +34,7 @@ class LongNumericalValuesSeparatedWarnTest : LintTestBase(::LongNumericalValuesS | val flo2 = 192.31234134134435_5345 | val hundred = 100 |} - """.trimMargin(), + """.trimMargin(), LintError(2, 21, ruleId, "${Warnings.LONG_NUMERICAL_VALUES_SEPARATED.warnText()} 100000000000", true), LintError(3, 27, ruleId, "${Warnings.LONG_NUMERICAL_VALUES_SEPARATED.warnText()} 1234567890123456L", true), LintError(4, 31, ruleId, "${Warnings.LONG_NUMERICAL_VALUES_SEPARATED.warnText()} 999999999L", true), @@ -64,7 +64,7 @@ class LongNumericalValuesSeparatedWarnTest : LintTestBase(::LongNumericalValuesS | val flo = 192.312_341_341_345 | val ten = 10 |} - """.trimMargin() + """.trimMargin() ) } @@ -81,7 +81,7 @@ class LongNumericalValuesSeparatedWarnTest : LintTestBase(::LongNumericalValuesS | val bytes = 0b110100 | val flo = 192.312 |} - """.trimMargin(), + """.trimMargin(), LintError(2, 21, ruleId, "${Warnings.LONG_NUMERICAL_VALUES_SEPARATED.warnText()} 100", true), LintError(3, 27, ruleId, "${Warnings.LONG_NUMERICAL_VALUES_SEPARATED.warnText()} 1234566L", true), LintError(4, 31, ruleId, "${Warnings.LONG_NUMERICAL_VALUES_SEPARATED.warnText()} 999L", true), @@ -98,9 +98,9 @@ class LongNumericalValuesSeparatedWarnTest : LintTestBase(::LongNumericalValuesS lintMethod( """ |fun foo(val one = 100_000_000) { - | + | |} - """.trimMargin() + """.trimMargin() ) } @@ -110,9 +110,9 @@ class LongNumericalValuesSeparatedWarnTest : LintTestBase(::LongNumericalValuesS lintMethod( """ |fun foo(val one = 100000000) { - | + | |} - """.trimMargin(), + """.trimMargin(), LintError(1, 19, ruleId, "${Warnings.LONG_NUMERICAL_VALUES_SEPARATED.warnText()} 100000000", true) ) } diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/MagicNumberRuleWarnTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/MagicNumberRuleWarnTest.kt index aa3886cab7..f20990bcde 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/MagicNumberRuleWarnTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/MagicNumberRuleWarnTest.kt @@ -49,7 +49,7 @@ class MagicNumberRuleWarnTest : LintTestBase(::MagicNumberRule) { | val f = "qwe\$\{12\}hhe" |} | - |@Override + |@Override |fun hashCode(): Int { | return 32 |} @@ -59,7 +59,7 @@ class MagicNumberRuleWarnTest : LintTestBase(::MagicNumberRule) { | private const val AA = 4 | } |} - """.trimMargin(), + """.trimMargin(), LintError(2, 18, ruleId, "${MAGIC_NUMBER.warnText()} 4", false), LintError(3, 12, ruleId, "${MAGIC_NUMBER.warnText()} 128L", false), LintError(4, 12, ruleId, "${MAGIC_NUMBER.warnText()} 3.4f", false), @@ -84,11 +84,11 @@ class MagicNumberRuleWarnTest : LintTestBase(::MagicNumberRule) { | B(50), | C(3), |} - |@Override + |@Override |fun hashCode(): Int { | return 32 |} - """.trimMargin(), + """.trimMargin(), LintError(2, 13, ruleId, "${MAGIC_NUMBER.warnText()} -1", false), LintError(3, 18, ruleId, "${MAGIC_NUMBER.warnText()} 4", false), LintError(4, 12, ruleId, "${MAGIC_NUMBER.warnText()} 0xff", false), @@ -102,13 +102,13 @@ class MagicNumberRuleWarnTest : LintTestBase(::MagicNumberRule) { fun `check ignore top level constants`() { lintMethod( """ - |const val topLevel = 31 - | - |val shouldTrigger = 32 - | - |fun some() { - | - |} + |const val topLevel = 31 + | + |val shouldTrigger = 32 + | + |fun some() { + | + |} """.trimMargin(), LintError(3, 21, ruleId, "${MAGIC_NUMBER.warnText()} 32", false), ) @@ -142,7 +142,7 @@ class MagicNumberRuleWarnTest : LintTestBase(::MagicNumberRule) { |} | |fun Int.foo() = 2 - """.trimMargin(), rulesConfigList = rulesConfigMagicNumber + """.trimMargin(), rulesConfigList = rulesConfigMagicNumber ) } @@ -200,7 +200,7 @@ class MagicNumberRuleWarnTest : LintTestBase(::MagicNumberRule) { | B(50), | C(3), |} - |@Override + |@Override |fun hashCode(): Int { | return 32 |} diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/MultipleModifiersSequenceWarnTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/MultipleModifiersSequenceWarnTest.kt index 051c092007..518318a9aa 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/MultipleModifiersSequenceWarnTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/MultipleModifiersSequenceWarnTest.kt @@ -20,9 +20,9 @@ class MultipleModifiersSequenceWarnTest : LintTestBase(::MultipleModifiersSequen """ |@Annotation |final public fun foo() { - | lateinit open protected var a: List + | lateinit open protected var a: List |} - """.trimMargin(), + """.trimMargin(), LintError(2, 1, ruleId, "${WRONG_MULTIPLE_MODIFIERS_ORDER.warnText()} final should be on position 2, but is on position 1", true), LintError(2, 7, ruleId, "${WRONG_MULTIPLE_MODIFIERS_ORDER.warnText()} public should be on position 1, but is on position 2", true), LintError(3, 4, ruleId, "${WRONG_MULTIPLE_MODIFIERS_ORDER.warnText()} lateinit should be on position 3, but is on position 1", true), @@ -36,13 +36,13 @@ class MultipleModifiersSequenceWarnTest : LintTestBase(::MultipleModifiersSequen lintMethod( """ |public final fun foo() { - | protected open lateinit var a: List + | protected open lateinit var a: List |} | |fun goo() { | |} - """.trimMargin() + """.trimMargin() ) } @@ -56,7 +56,7 @@ class MultipleModifiersSequenceWarnTest : LintTestBase(::MultipleModifiersSequen |inline suspend fun f(crossinline body: () -> Unit) {} | |inline fun < reified T> membersOf() = T::class.members - """.trimMargin(), + """.trimMargin(), LintError(1, 1, ruleId, "${WRONG_MULTIPLE_MODIFIERS_ORDER.warnText()} inline should be on position 3, but is on position 1", true), LintError(1, 16, ruleId, "${WRONG_MULTIPLE_MODIFIERS_ORDER.warnText()} public should be on position 1, but is on position 3", true), LintError(3, 1, ruleId, "${WRONG_MULTIPLE_MODIFIERS_ORDER.warnText()} inline should be on position 2, but is on position 1", true), @@ -73,10 +73,10 @@ class MultipleModifiersSequenceWarnTest : LintTestBase(::MultipleModifiersSequen | |data protected class Counter(val dayIndex: Int) { | operator suspend fun plus(increment: Int): Counter { - | return Counter(dayIndex + increment) + | return Counter(dayIndex + increment) | } |} - """.trimMargin(), + """.trimMargin(), LintError(1, 1, ruleId, "${WRONG_MULTIPLE_MODIFIERS_ORDER.warnText()} enum should be on position 2, but is on position 1", true), LintError(1, 6, ruleId, "${WRONG_MULTIPLE_MODIFIERS_ORDER.warnText()} public should be on position 1, but is on position 2", true), LintError(3, 1, ruleId, "${WRONG_MULTIPLE_MODIFIERS_ORDER.warnText()} data should be on position 2, but is on position 1", true), @@ -93,7 +93,7 @@ class MultipleModifiersSequenceWarnTest : LintTestBase(::MultipleModifiersSequen """ |public @Annotation final fun foo() { |} - """.trimMargin(), + """.trimMargin(), LintError(1, 8, ruleId, "${WRONG_MULTIPLE_MODIFIERS_ORDER.warnText()} @Annotation annotation should be before all modifiers", true) ) } @@ -105,7 +105,7 @@ class MultipleModifiersSequenceWarnTest : LintTestBase(::MultipleModifiersSequen """ |public value class Foo() { |} - """.trimMargin(), + """.trimMargin(), ) } } diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/NullableTypeRuleWarnTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/NullableTypeRuleWarnTest.kt index 5ac0e9e713..3054c07f7d 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/NullableTypeRuleWarnTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/NullableTypeRuleWarnTest.kt @@ -23,7 +23,7 @@ class NullableTypeRuleWarnTest : LintTestBase(::NullableTypeRule) { |val b: Double? = null |val c: String? = null |val a: MutableList? = null - """.trimMargin(), + """.trimMargin(), LintError(1, 21, ruleId, "${NULLABLE_PROPERTY_TYPE.warnText()} initialize explicitly", true), LintError(2, 15, ruleId, "${NULLABLE_PROPERTY_TYPE.warnText()} initialize explicitly", true), LintError(3, 18, ruleId, "${NULLABLE_PROPERTY_TYPE.warnText()} initialize explicitly", true), @@ -44,7 +44,7 @@ class NullableTypeRuleWarnTest : LintTestBase(::NullableTypeRule) { | val c: Boolean? = true | } |} - """.trimMargin(), + """.trimMargin(), LintError(3, 22, ruleId, "${NULLABLE_PROPERTY_TYPE.warnText()} initialize explicitly", true), LintError(4, 15, ruleId, "${NULLABLE_PROPERTY_TYPE.warnText()} don't use nullable type", false), LintError(5, 15, ruleId, "${NULLABLE_PROPERTY_TYPE.warnText()} don't use nullable type", false) @@ -63,7 +63,7 @@ class NullableTypeRuleWarnTest : LintTestBase(::NullableTypeRule) { | val c: Boolean? = false | } |} - """.trimMargin(), + """.trimMargin(), LintError(3, 15, ruleId, "${NULLABLE_PROPERTY_TYPE.warnText()} don't use nullable type", false), LintError(4, 22, ruleId, "${NULLABLE_PROPERTY_TYPE.warnText()} initialize explicitly", true), LintError(5, 15, ruleId, "${NULLABLE_PROPERTY_TYPE.warnText()} don't use nullable type", false) @@ -80,7 +80,7 @@ class NullableTypeRuleWarnTest : LintTestBase(::NullableTypeRule) { | val q: Int? = foo() | val e: A.Q? = null |} - """.trimMargin(), + """.trimMargin(), LintError(4, 18, ruleId, "${NULLABLE_PROPERTY_TYPE.warnText()} initialize explicitly", false) ) } @@ -92,9 +92,9 @@ class NullableTypeRuleWarnTest : LintTestBase(::NullableTypeRule) { """ | val q: List? = emptyList() | val w: List> = emptyList>() - | val c: Set? = setOf() + | val c: Set? = setOf() | val d: List = emptyList() - """.trimMargin(), + """.trimMargin(), LintError(1, 9, ruleId, "${NULLABLE_PROPERTY_TYPE.warnText()} don't use nullable type", false), LintError(3, 9, ruleId, "${NULLABLE_PROPERTY_TYPE.warnText()} don't use nullable type", false) ) @@ -109,8 +109,8 @@ class NullableTypeRuleWarnTest : LintTestBase(::NullableTypeRule) { | .getFirstChildWithType(ElementType.SUPER_TYPE_LIST) | ?.findLeafWithSpecificType(TYPE_REFERENCE) | ?.text - | + | | private val rulesConfigList: List? = rulesConfigList ?: RulesConfigReader(javaClass.classLoader).readResource("diktat-analysis.yml") - """.trimMargin()) + """.trimMargin()) } } diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/RangeConventionalRuleWarnTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/RangeConventionalRuleWarnTest.kt index 7bf3f9e19a..57d278cdda 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/RangeConventionalRuleWarnTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/RangeConventionalRuleWarnTest.kt @@ -21,7 +21,7 @@ class RangeConventionalRuleWarnTest : LintTestBase(::RangeConventionalRule) { fun `check simple examples with until`() { lintMethod( """ - |fun foo() { + |fun foo() { | for (i in 1..(4 - 1)) print(i) | for (i in 1..(b - 1)) print(i) | for (i in ((1 .. ((4 - 1))))) print(i) @@ -32,7 +32,7 @@ class RangeConventionalRuleWarnTest : LintTestBase(::RangeConventionalRule) { | if (6 in (1..10) && true) {} | for (i in 1..(4 - 1) step 3) print(i) |} - """.trimMargin(), + """.trimMargin(), LintError(2, 15, ruleId, "${Warnings.CONVENTIONAL_RANGE.warnText()} replace `..` with `until`: 1..(4 - 1)", true), LintError(3, 15, ruleId, "${Warnings.CONVENTIONAL_RANGE.warnText()} replace `..` with `until`: 1..(b - 1)", true), LintError(4, 17, ruleId, "${Warnings.CONVENTIONAL_RANGE.warnText()} replace `..` with `until`: 1 .. ((4 - 1))", true), @@ -44,13 +44,13 @@ class RangeConventionalRuleWarnTest : LintTestBase(::RangeConventionalRule) { fun `check simple examples with rangeTo`() { lintMethod( """ - |fun foo() { + |fun foo() { | val num = 1 | val w = num.rangeTo(num, num) | val q = 1..5 | val w = num.rangeTo(num) |} - """.trimMargin(), + """.trimMargin(), LintError(5, 13, ruleId, "${Warnings.CONVENTIONAL_RANGE.warnText()} replace `rangeTo` with `..`: num.rangeTo(num)", true) ) } @@ -59,11 +59,11 @@ class RangeConventionalRuleWarnTest : LintTestBase(::RangeConventionalRule) { fun `check simple examples with rangeTo with config`() { lintMethod( """ - |fun foo() { + |fun foo() { | val w = num.rangeTo(num, num) | val w = num.rangeTo(num) |} - """.trimMargin(), + """.trimMargin(), rulesConfigList = rulesConfigRangeRule ) } diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/SingleLineStatementsRuleWarnTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/SingleLineStatementsRuleWarnTest.kt index 8a7a154638..3a065a2209 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/SingleLineStatementsRuleWarnTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/SingleLineStatementsRuleWarnTest.kt @@ -26,7 +26,7 @@ class SingleLineStatementsRuleWarnTest : LintTestBase(::SingleLineStatementsRule | } | else { | } - | + | | when(x) { | 1 -> println(1) | else -> println("3;5") @@ -34,7 +34,7 @@ class SingleLineStatementsRuleWarnTest : LintTestBase(::SingleLineStatementsRule | val a = 5; val b = 10 | println(1); println(1) |} - """.trimMargin(), + """.trimMargin(), LintError(1, 40, ruleId, "${MORE_THAN_ONE_STATEMENT_PER_LINE.warnText()} import com.pinterest.ktlint.core.KtLint; import com.pinterest.ktlint.core.LintError", true), LintError(5, 13, ruleId, "${MORE_THAN_ONE_STATEMENT_PER_LINE.warnText()} goo(); hoo()", true), LintError(14, 14, ruleId, "${MORE_THAN_ONE_STATEMENT_PER_LINE.warnText()} val a = 5; val b = 10", true), @@ -51,7 +51,7 @@ class SingleLineStatementsRuleWarnTest : LintTestBase(::SingleLineStatementsRule | val a = 5;val b = 10 | println(1);println(1) |} - """.trimMargin(), + """.trimMargin(), LintError(2, 14, ruleId, "${MORE_THAN_ONE_STATEMENT_PER_LINE.warnText()} val a = 5;val b = 10", true), LintError(3, 15, ruleId, "${MORE_THAN_ONE_STATEMENT_PER_LINE.warnText()} println(1);println(1)", true) ) @@ -67,7 +67,7 @@ class SingleLineStatementsRuleWarnTest : LintTestBase(::SingleLineStatementsRule | goo() | }; else { print(123) } |} - """.trimMargin(), + """.trimMargin(), LintError(4, 5, ruleId, "${MORE_THAN_ONE_STATEMENT_PER_LINE.warnText()} }; else { print(123) }", true) ) } @@ -85,7 +85,7 @@ class SingleLineStatementsRuleWarnTest : LintTestBase(::SingleLineStatementsRule | } | else { | } - | + | | when(x) { | 1 -> println(1) | else -> println("3;5") @@ -93,7 +93,7 @@ class SingleLineStatementsRuleWarnTest : LintTestBase(::SingleLineStatementsRule | val a = 5 | println(1) |} - """.trimMargin() + """.trimMargin() ) } @@ -110,7 +110,7 @@ class SingleLineStatementsRuleWarnTest : LintTestBase(::SingleLineStatementsRule | override fun signal() = WAITING | }; abstract fun signal(): ProtocolState |} - """.trimMargin(), + """.trimMargin(), LintError(7, 5, ruleId, "${MORE_THAN_ONE_STATEMENT_PER_LINE.warnText()} }; abstract fun signal(): ProtocolState", true) ) } @@ -127,7 +127,7 @@ class SingleLineStatementsRuleWarnTest : LintTestBase(::SingleLineStatementsRule | }; gt() | }; gr() |} - """.trimMargin(), + """.trimMargin(), LintError(5, 9, ruleId, "${MORE_THAN_ONE_STATEMENT_PER_LINE.warnText()} }; gt()", true), LintError(6, 5, ruleId, "${MORE_THAN_ONE_STATEMENT_PER_LINE.warnText()} }; gr()", true) ) @@ -141,7 +141,7 @@ class SingleLineStatementsRuleWarnTest : LintTestBase(::SingleLineStatementsRule |fun foo() { | ; grr() |} - """.trimMargin(), + """.trimMargin(), LintError(2, 4, ruleId, "${MORE_THAN_ONE_STATEMENT_PER_LINE.warnText()} ; grr()", true) ) } diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/SortRuleWarnTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/SortRuleWarnTest.kt index 2196e421a4..782949ddab 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/SortRuleWarnTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/SortRuleWarnTest.kt @@ -38,7 +38,7 @@ class SortRuleWarnTest : LintTestBase(::SortRule) { | D, | ; |} - """.trimMargin() + """.trimMargin() ) } @@ -54,7 +54,7 @@ class SortRuleWarnTest : LintTestBase(::SortRule) { | B, | ; |} - """.trimMargin(), + """.trimMargin(), LintError(1, 17, ruleId, "${WRONG_DECLARATIONS_ORDER.warnText()} enum entries order is incorrect", true) ) } @@ -70,7 +70,7 @@ class SortRuleWarnTest : LintTestBase(::SortRule) { | RED(0xFF0000), | ; |} - """.trimMargin() + """.trimMargin() ) } @@ -84,7 +84,7 @@ class SortRuleWarnTest : LintTestBase(::SortRule) { | RED(0xFF0000), | BLUE(0x0000FF), |} - """.trimMargin(), + """.trimMargin(), LintError(1, 17, ruleId, "${WRONG_DECLARATIONS_ORDER.warnText()} enum entries order is incorrect", true) ) } @@ -99,7 +99,7 @@ class SortRuleWarnTest : LintTestBase(::SortRule) { | RED(0xFF0000), | BLUE(0x0000FF) |} - """.trimMargin(), + """.trimMargin(), LintError(1, 17, ruleId, "${WRONG_DECLARATIONS_ORDER.warnText()} enum entries order is incorrect", true) ) } @@ -114,7 +114,7 @@ class SortRuleWarnTest : LintTestBase(::SortRule) { | GREEN(0x00FF00), | RED(0xFF0000), |} - """.trimMargin() + """.trimMargin() ) } @@ -126,14 +126,14 @@ class SortRuleWarnTest : LintTestBase(::SortRule) { |enum class Warnings { | WAITING { | override fun signal() = TALKING - | }, + | }, | TALKING { | override fun signal() = TALKING | }, | ; | abstract fun signal(): ProtocolState |} - """.trimMargin(), + """.trimMargin(), LintError(1, 21, ruleId, "${WRONG_DECLARATIONS_ORDER.warnText()} enum entries order is incorrect", true) ) } @@ -146,14 +146,14 @@ class SortRuleWarnTest : LintTestBase(::SortRule) { |enum class Warnings { | WAITING { | override fun signal() = TALKING - | }, + | }, | TALKING { | override fun signal() = TALKING | }, | ; | abstract fun signal(): ProtocolState |} - """.trimMargin(), rulesConfigList = rulesConfigNotSortEnum + """.trimMargin(), rulesConfigList = rulesConfigNotSortEnum ) } @@ -171,7 +171,7 @@ class SortRuleWarnTest : LintTestBase(::SortRule) { | private const val A = 5 | } |} - """.trimMargin(), + """.trimMargin(), LintError(4, 8, ruleId, "${WRONG_DECLARATIONS_ORDER.warnText()} constant properties inside companion object order is incorrect", true) ) } @@ -192,7 +192,7 @@ class SortRuleWarnTest : LintTestBase(::SortRule) { | private const val Db = 5 | } |} - """.trimMargin(), + """.trimMargin(), LintError(4, 8, ruleId, "${WRONG_DECLARATIONS_ORDER.warnText()} constant properties inside companion object order is incorrect", true), LintError(7, 8, ruleId, "${WRONG_DECLARATIONS_ORDER.warnText()} constant properties inside companion object order is incorrect", true) ) @@ -214,7 +214,7 @@ class SortRuleWarnTest : LintTestBase(::SortRule) { | private const val Db = 5 | } |} - """.trimMargin(), + """.trimMargin(), LintError(7, 8, ruleId, "${WRONG_DECLARATIONS_ORDER.warnText()} constant properties inside companion object order is incorrect", true) ) } @@ -235,7 +235,7 @@ class SortRuleWarnTest : LintTestBase(::SortRule) { | private const val Db = 5 | } |} - """.trimMargin(), rulesConfigList = rulesConfigNotSortProperty + """.trimMargin(), rulesConfigList = rulesConfigNotSortProperty ) } @@ -258,14 +258,14 @@ class SortRuleWarnTest : LintTestBase(::SortRule) { |enum class Warnings { | WAITING { | override fun signal() = TALKING - | }, + | }, | TALKING { | override fun signal() = TALKING | }, | ; | abstract fun signal(): ProtocolState |} - """.trimMargin(), rulesConfigList = rulesConfigNotSortBoth + """.trimMargin(), rulesConfigList = rulesConfigNotSortBoth ) } @@ -280,7 +280,7 @@ class SortRuleWarnTest : LintTestBase(::SortRule) { | private const val B = 4 | } |} - """.trimMargin() + """.trimMargin() ) } @@ -299,7 +299,7 @@ class SortRuleWarnTest : LintTestBase(::SortRule) { | private val SIMPLE_VALUE = listOf(IDENTIFIER, WHITE_SPACE, COMMA, SEMICOLON) | } |} - """.trimMargin() + """.trimMargin() ) } } diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/StringConcatenationWarnTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/StringConcatenationWarnTest.kt index fd5c9a8b91..94fe33df76 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/StringConcatenationWarnTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/StringConcatenationWarnTest.kt @@ -21,7 +21,7 @@ class StringConcatenationWarnTest : LintTestBase(::StringConcatenationRule) { """ | val a = "my string" + "string" + value + "other value" | - """.trimMargin(), + """.trimMargin(), LintError(1, 10, ruleId, Warnings.STRING_CONCATENATION.warnText() + " \"my string\" + \"string\" + value + \"other value\"", canBeAutoCorrected) ) @@ -34,7 +34,7 @@ class StringConcatenationWarnTest : LintTestBase(::StringConcatenationRule) { """ | val a = "my string" + 1 + 2 + 3 | - """.trimMargin(), + """.trimMargin(), LintError(1, 10, ruleId, Warnings.STRING_CONCATENATION.warnText() + " \"my string\" + 1 + 2 + 3", canBeAutoCorrected) ) @@ -48,7 +48,7 @@ class StringConcatenationWarnTest : LintTestBase(::StringConcatenationRule) { """ | val a = (1 + 2).toString() + "my string" + 3 | - """.trimMargin(), + """.trimMargin(), LintError(1, 10, ruleId, Warnings.STRING_CONCATENATION.warnText() + " (1 + 2).toString() + \"my string\" + 3", canBeAutoCorrected) ) @@ -62,7 +62,7 @@ class StringConcatenationWarnTest : LintTestBase(::StringConcatenationRule) { | val myObject = 12 | val a = (1 + 2).toString() + "my string" + 3 + "string" + myObject + myObject | - """.trimMargin(), + """.trimMargin(), LintError(2, 10, ruleId, Warnings.STRING_CONCATENATION.warnText() + " (1 + 2).toString() + \"my string\" + 3 + \"string\" + myObject + myObject", canBeAutoCorrected) ) @@ -76,7 +76,7 @@ class StringConcatenationWarnTest : LintTestBase(::StringConcatenationRule) { | val myObject = 12 | val a = (1 + 2).toString() + "my string" + ("string" + myObject) + myObject | - """.trimMargin(), + """.trimMargin(), LintError(2, 10, ruleId, Warnings.STRING_CONCATENATION.warnText() + " (1 + 2).toString() + \"my string\" + (\"string\" + myObject) + myObject", canBeAutoCorrected) ) @@ -90,7 +90,7 @@ class StringConcatenationWarnTest : LintTestBase(::StringConcatenationRule) { | fun foo1(){ | foo("my string" + "other string" + (1 + 2 + 3)) | } - """.trimMargin(), + """.trimMargin(), LintError(2, 10, ruleId, Warnings.STRING_CONCATENATION.warnText() + " \"my string\" + \"other string\" + (1 + 2 + 3)", canBeAutoCorrected) ) @@ -104,7 +104,7 @@ class StringConcatenationWarnTest : LintTestBase(::StringConcatenationRule) { | val myObject = 12 | val a = "my string" + "other string" + (1 + 2 + 3) | - """.trimMargin(), + """.trimMargin(), LintError(2, 10, ruleId, Warnings.STRING_CONCATENATION.warnText() + " \"my string\" + \"other string\" + (1 + 2 + 3)", canBeAutoCorrected) ) @@ -118,7 +118,7 @@ class StringConcatenationWarnTest : LintTestBase(::StringConcatenationRule) { | val myObject = 12 | val a = "my string" + (1 + 2 + 3) + ("other string" + 3) + (1 + 2 + 3) | - """.trimMargin(), + """.trimMargin(), LintError(2, 10, ruleId, Warnings.STRING_CONCATENATION.warnText() + " \"my string\" + (1 + 2 + 3) + (\"other string\" + 3) + (1 + 2 + 3)", canBeAutoCorrected) ) @@ -131,7 +131,7 @@ class StringConcatenationWarnTest : LintTestBase(::StringConcatenationRule) { """ | val a = "my string" + (1 + 2 + 3) + ("other string" + 3) + (1 + (2 + 3)) + ("third string" + ("str" + 5)) | - """.trimMargin(), + """.trimMargin(), LintError(1, 10, ruleId, Warnings.STRING_CONCATENATION.warnText() + " \"my string\" + (1 + 2 + 3) + (\"other string\" + 3) + (1 + (2 + 3)) +" + " (\"third string\" + (\"str\" + 5))", canBeAutoCorrected) @@ -143,9 +143,9 @@ class StringConcatenationWarnTest : LintTestBase(::StringConcatenationRule) { fun `string concatenation - other binary operators`() { lintMethod( """ - | val a = "my string" + ("third string" + ("str" + 5 * 12 / 100)) + | val a = "my string" + ("third string" + ("str" + 5 * 12 / 100)) | - """.trimMargin(), + """.trimMargin(), LintError(1, 10, ruleId, Warnings.STRING_CONCATENATION.warnText() + " \"my string\" + (\"third string\" + (\"str\" + 5 * 12 / 100))", canBeAutoCorrected) ) @@ -160,7 +160,7 @@ class StringConcatenationWarnTest : LintTestBase(::StringConcatenationRule) { | "string" + value + | other + value | - """.trimMargin() + """.trimMargin() ) } @@ -172,7 +172,7 @@ class StringConcatenationWarnTest : LintTestBase(::StringConcatenationRule) { | val a = "my string" + | "string" + value | - """.trimMargin() + """.trimMargin() ) } } diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/StringTemplateRuleWarnTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/StringTemplateRuleWarnTest.kt index a877bcd355..464f588431 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/StringTemplateRuleWarnTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/StringTemplateRuleWarnTest.kt @@ -19,11 +19,11 @@ class StringTemplateRuleWarnTest : LintTestBase(::StringTemplateFormatRule) { fun `long string template good example`() { lintMethod( """ - |class Some { + |class Some { | val template = "${'$'}{::String} ${'$'}{asd.moo()}" | val some = "${'$'}{foo as Foo}" |} - """.trimMargin() + """.trimMargin() ) } @@ -32,14 +32,14 @@ class StringTemplateRuleWarnTest : LintTestBase(::StringTemplateFormatRule) { fun `long string template bad example`() { lintMethod( """ - |class Some { + |class Some { | val template = "${'$'}{a} ${'$'}{asd.moo()}" | val some = "${'$'}{1.0}" | val another = "${'$'}{1}" | val singleLetterCase = "${'$'}{ref}" | val digitsWithLetters = "${'$'}{1.0}asd" |} - """.trimMargin(), + """.trimMargin(), LintError(2, 20, ruleId, "${Warnings.STRING_TEMPLATE_CURLY_BRACES.warnText()} ${'$'}{a}", true), LintError(3, 16, ruleId, "${Warnings.STRING_TEMPLATE_CURLY_BRACES.warnText()} ${'$'}{1.0}", true), LintError(4, 19, ruleId, "${Warnings.STRING_TEMPLATE_CURLY_BRACES.warnText()} ${'$'}{1}", true), @@ -53,11 +53,11 @@ class StringTemplateRuleWarnTest : LintTestBase(::StringTemplateFormatRule) { fun `short string template bad example`() { lintMethod( """ - |class Some { + |class Some { | val template = "${'$'}a" | val z = a |} - """.trimMargin(), + """.trimMargin(), LintError(2, 20, ruleId, "${Warnings.STRING_TEMPLATE_QUOTES.warnText()} ${'$'}a", true) ) } @@ -73,7 +73,7 @@ class StringTemplateRuleWarnTest : LintTestBase(::StringTemplateFormatRule) { | println("${'$'}{s}.length is ${'$'}{s.length}") | } |} - """.trimMargin(), + """.trimMargin(), LintError(4, 17, ruleId, "${Warnings.STRING_TEMPLATE_CURLY_BRACES.warnText()} ${'$'}{s}", true) ) } @@ -91,7 +91,7 @@ class StringTemplateRuleWarnTest : LintTestBase(::StringTemplateFormatRule) { | val some = "${'$'}{index + 1}" | } |} - """.trimMargin() + """.trimMargin() ) } @@ -105,7 +105,7 @@ class StringTemplateRuleWarnTest : LintTestBase(::StringTemplateFormatRule) { | val copyTestFile = File("${'$'}{testFile()} copy ${'$'}{testFile}_copy") | } |} - """.trimMargin() + """.trimMargin() ) } @@ -119,7 +119,7 @@ class StringTemplateRuleWarnTest : LintTestBase(::StringTemplateFormatRule) { | val copyTestFile = "${'$'}{arr[0]}" | } |} - """.trimMargin() + """.trimMargin() ) } } diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/TrailingCommaWarnTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/TrailingCommaWarnTest.kt index c1bd3623f5..d69136d7b8 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/TrailingCommaWarnTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/TrailingCommaWarnTest.kt @@ -25,19 +25,19 @@ class TrailingCommaWarnTest : LintTestBase(::TrailingCommaRule) { fun `check value arguments`() { lintMethod( """ - fun shift(x: Int, y: Int) { + fun shift(x: Int, y: Int) { shift( 25, 20 // trailing comma ) - + val colors = listOf( "red", "green", "blue" // trailing comma ) } - """.trimMargin(), + """.trimMargin(), LintError(4, 25, ruleId, "${TRAILING_COMMA.warnText()} after VALUE_ARGUMENT: 20", true), LintError(10, 25, ruleId, "${TRAILING_COMMA.warnText()} after VALUE_ARGUMENT: \"blue\"", true), rulesConfigList = getRulesConfig("valueArgument") @@ -53,12 +53,12 @@ class TrailingCommaWarnTest : LintTestBase(::TrailingCommaRule) { val name: String, val lastName: String // trailing comma ) - + class Customer( val name: String, lastName: String // trailing comma ) - """.trimMargin(), + """.trimMargin(), LintError(3, 21, ruleId, "${TRAILING_COMMA.warnText()} after VALUE_PARAMETER: val lastName: String // trailing comma", true), LintError(8, 21, ruleId, "${TRAILING_COMMA.warnText()} after VALUE_PARAMETER: lastName: String // trailing comma", true), rulesConfigList = getRulesConfig("valueParameter") @@ -71,25 +71,25 @@ class TrailingCommaWarnTest : LintTestBase(::TrailingCommaRule) { lintMethod( """ class A { - + fun foo() {} - + fun powerOf( - number: Int, + number: Int, exponent: Int, // trailing comma ) { /*...*/ } - + constructor( x: Comparable, y: Iterable ) {} - + fun print( vararg quantity: Int, description: String ) {} } - """.trimMargin(), + """.trimMargin(), LintError(12, 25, ruleId, "${TRAILING_COMMA.warnText()} after VALUE_PARAMETER: y: Iterable", true), LintError(17, 25, ruleId, "${TRAILING_COMMA.warnText()} after VALUE_PARAMETER: description: String", true), rulesConfigList = getRulesConfig("valueParameter") @@ -111,7 +111,7 @@ class TrailingCommaWarnTest : LintTestBase(::TrailingCommaRule) { } println(sum(8, 8, 8)) } - """.trimMargin(), + """.trimMargin(), LintError(5, 25, ruleId, "${TRAILING_COMMA.warnText()} after VALUE_PARAMETER: z // trailing comma", true), rulesConfigList = getRulesConfig("valueParameter") ) @@ -130,7 +130,7 @@ class TrailingCommaWarnTest : LintTestBase(::TrailingCommaRule) { xValue, yValue // trailing comma ] - """.trimMargin(), + """.trimMargin(), LintError(7, 25, ruleId, "${TRAILING_COMMA.warnText()} after REFERENCE_EXPRESSION: yValue", true), rulesConfigList = getRulesConfig("referenceExpression") ) @@ -144,13 +144,13 @@ class TrailingCommaWarnTest : LintTestBase(::TrailingCommaRule) { fun main() { val x = { x: Comparable, - y: Iterable + y: Iterable -> println("1",) } - + println(x,) } - """.trimMargin(), + """.trimMargin(), rulesConfigList = getRulesConfig("valueParameter") ) } @@ -167,7 +167,7 @@ class TrailingCommaWarnTest : LintTestBase(::TrailingCommaRule) { -> true else -> false } - + fun someFun() { when (x) { is Int, @@ -176,18 +176,18 @@ class TrailingCommaWarnTest : LintTestBase(::TrailingCommaRule) { is Long, -> x as Int } } - + fun someFun() { when (x) { in 1..2 -> foo() } } - + fun someFun() { when (x) {} } - """.trimMargin(), + """.trimMargin(), LintError(4, 21, ruleId, "${TRAILING_COMMA.warnText()} after WHEN_CONDITION_WITH_EXPRESSION: String::class", true), LintError(12, 24, ruleId, "${TRAILING_COMMA.warnText()} after WHEN_CONDITION_IS_PATTERN: is String", true), LintError(20, 24, ruleId, "${TRAILING_COMMA.warnText()} after WHEN_CONDITION_IN_RANGE: in 1..2", true), @@ -201,7 +201,7 @@ class TrailingCommaWarnTest : LintTestBase(::TrailingCommaRule) { lintMethod( """ annotation class ApplicableFor(val services: Array) - + @ApplicableFor([ "serializer", "balancer", @@ -209,7 +209,7 @@ class TrailingCommaWarnTest : LintTestBase(::TrailingCommaRule) { "inMemoryCache" // trailing comma ],) fun foo() {} - """.trimMargin(), + """.trimMargin(), LintError(7, 21, ruleId, "${TRAILING_COMMA.warnText()} after STRING_TEMPLATE: \"inMemoryCache\"", true), rulesConfigList = getRulesConfig("collectionLiteral") ) @@ -221,7 +221,7 @@ class TrailingCommaWarnTest : LintTestBase(::TrailingCommaRule) { lintMethod( """ fun foo() {} - + fun main() { foo< Comparable, @@ -229,7 +229,7 @@ class TrailingCommaWarnTest : LintTestBase(::TrailingCommaRule) { > // trailing comma >() } - """.trimMargin(), + """.trimMargin(), LintError(6, 29, ruleId, "${TRAILING_COMMA.warnText()} after TYPE_PROJECTION: Iterable {} - """.trimMargin(), + """.trimMargin(), LintError(3, 25, ruleId, "${TRAILING_COMMA.warnText()} after TYPE_PARAMETER: MyValue", true), rulesConfigList = getRulesConfig("typeParameter") ) @@ -259,13 +259,13 @@ class TrailingCommaWarnTest : LintTestBase(::TrailingCommaRule) { fun foo() { data class Car(val manufacturer: String, val model: String, val year: Int) val myCar = Car("Tesla", "Y", 2019) - + val ( manufacturer, model, year // trailing comma ) = myCar - + val cars = listOf() fun printMeanValue() { var meanValue: Int = 0 @@ -280,7 +280,7 @@ class TrailingCommaWarnTest : LintTestBase(::TrailingCommaRule) { } printMeanValue() } - """.trimMargin(), + """.trimMargin(), LintError(8, 25, ruleId, "${TRAILING_COMMA.warnText()} after DESTRUCTURING_DECLARATION_ENTRY: year", true), LintError(17, 29, ruleId, "${TRAILING_COMMA.warnText()} after DESTRUCTURING_DECLARATION_ENTRY: year", true), rulesConfigList = getRulesConfig("destructuringDeclaration") diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/WhenMustHaveElseWarnTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/WhenMustHaveElseWarnTest.kt index 67be03a09d..b1060056b2 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/WhenMustHaveElseWarnTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/WhenMustHaveElseWarnTest.kt @@ -24,7 +24,7 @@ class WhenMustHaveElseWarnTest : LintTestBase(::WhenMustHaveElseRule) { | else -> {} | } |} - """.trimMargin() + """.trimMargin() ) } @@ -39,7 +39,7 @@ class WhenMustHaveElseWarnTest : LintTestBase(::WhenMustHaveElseRule) { | } |} | - """.trimMargin(), + """.trimMargin(), LintError(2, 5, ruleId, "${Warnings.WHEN_WITHOUT_ELSE.warnText()} else was not found", true) ) } @@ -54,7 +54,7 @@ class WhenMustHaveElseWarnTest : LintTestBase(::WhenMustHaveElseRule) { | 1 -> print("x is neither 1 nor 2") | } |} - """.trimMargin() + """.trimMargin() ) } @@ -70,7 +70,7 @@ class WhenMustHaveElseWarnTest : LintTestBase(::WhenMustHaveElseRule) { | } | } |} - """.trimMargin() + """.trimMargin() ) } @@ -87,7 +87,7 @@ class WhenMustHaveElseWarnTest : LintTestBase(::WhenMustHaveElseRule) { | } | } |} - """.trimMargin() + """.trimMargin() ) } diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/files/BlankLinesWarnTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/files/BlankLinesWarnTest.kt index e79fde7a0e..190508eb80 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/files/BlankLinesWarnTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/files/BlankLinesWarnTest.kt @@ -23,10 +23,10 @@ class BlankLinesWarnTest : LintTestBase(::BlankLinesRule) { """ |class Example { | fun foo() { - | + | | } |} - """.trimMargin() + """.trimMargin() ) } @@ -36,11 +36,11 @@ class BlankLinesWarnTest : LintTestBase(::BlankLinesRule) { lintMethod( """ |fun foo() { - | run { - | + | run { + | | } |} - """.trimMargin() + """.trimMargin() ) } @@ -53,11 +53,11 @@ class BlankLinesWarnTest : LintTestBase(::BlankLinesRule) { | | | val foo = 0 - | - | + | + | | fun bar() { } |} - """.trimMargin(), + """.trimMargin(), LintError(1, 16, ruleId, consecutiveLinesWarn, true), LintError(4, 16, ruleId, consecutiveLinesWarn, true) ) @@ -71,12 +71,12 @@ class BlankLinesWarnTest : LintTestBase(::BlankLinesRule) { |class Example { | | fun foo() { - | + | | bar() - | + | | } |} - """.trimMargin(), + """.trimMargin(), LintError(1, 16, ruleId, blankLinesInBlockWarn(true), true), LintError(3, 16, ruleId, blankLinesInBlockWarn(true), true), LintError(5, 14, ruleId, blankLinesInBlockWarn(false), true) @@ -91,11 +91,11 @@ class BlankLinesWarnTest : LintTestBase(::BlankLinesRule) { |class Example { | fun foo() { | bar() - | + | | } - | + | |} - """.trimMargin(), + """.trimMargin(), LintError(3, 14, ruleId, blankLinesInBlockWarn(false), true), LintError(5, 6, ruleId, blankLinesInBlockWarn(false), true) ) diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/spaces/IndentationRuleFixTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/spaces/IndentationRuleFixTest.kt index beded1e4e4..405fe4026a 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/spaces/IndentationRuleFixTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/spaces/IndentationRuleFixTest.kt @@ -53,6 +53,12 @@ class IndentationRuleFixTest : FixTestBase("test/paragraph3/indentation", fixAndCompare("ConstructorExpected.kt", "ConstructorTest.kt") } + @Test + @Tag(WarningNames.WRONG_INDENTATION) + fun `multiline string`() { + fixAndCompare("MultilionStringExpected.kt", "MultilionStringTest.kt") + } + /** * This test has a counterpart under [IndentationRuleWarnTest]. * diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/spaces/IndentationRuleWarnTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/spaces/IndentationRuleWarnTest.kt index a50da08e14..3ccfa3658c 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/spaces/IndentationRuleWarnTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/spaces/IndentationRuleWarnTest.kt @@ -53,7 +53,7 @@ class IndentationRuleWarnTest : LintTestBase(::IndentationRule), IndentationRule |${"\t"}val zero = 0 |} | - """.trimMargin(), + """.trimMargin(), LintError(2, 1, ruleId, "${WRONG_INDENTATION.warnText()} tabs are not allowed for indentation", true) ) } @@ -67,7 +67,7 @@ class IndentationRuleWarnTest : LintTestBase(::IndentationRule), IndentationRule | val zero = 0 |} | - """.trimMargin(), + """.trimMargin(), LintError(2, 1, ruleId, warnText(4, 3), true) ) } @@ -80,7 +80,7 @@ class IndentationRuleWarnTest : LintTestBase(::IndentationRule), IndentationRule |class Example { | val zero = 0 |} - """.trimMargin(), + """.trimMargin(), LintError(3, 1, ruleId, "${WRONG_INDENTATION.warnText()} no newline at the end of file TestFileName.kt", true) ) } @@ -90,11 +90,11 @@ class IndentationRuleWarnTest : LintTestBase(::IndentationRule), IndentationRule fun `should warn if no new line at the end of file, last child whitespace`() { lintMethod( """ - |class Example { - | val zero = 0 - |} - """.trimMargin(), - LintError(3, 2, ruleId, "${WRONG_INDENTATION.warnText()} no newline at the end of file TestFileName.kt", true) + |class Example { + | val zero = 0 + |} + """.trimMargin(), + LintError(3, 1, ruleId, "${WRONG_INDENTATION.warnText()} no newline at the end of file TestFileName.kt", true) ) } @@ -108,7 +108,7 @@ class IndentationRuleWarnTest : LintTestBase(::IndentationRule), IndentationRule |} | | - """.trimMargin(), + """.trimMargin(), LintError(5, 1, ruleId, "${WRONG_INDENTATION.warnText()} too many blank lines at the end of file TestFileName.kt", true) ) } @@ -133,7 +133,7 @@ class IndentationRuleWarnTest : LintTestBase(::IndentationRule), IndentationRule | } |} | - """.trimMargin() + """.trimMargin() ) } @@ -152,13 +152,13 @@ class IndentationRuleWarnTest : LintTestBase(::IndentationRule), IndentationRule | t2, | t3 | ) - | + | | val e2 = Example(t1, t2, | t3 | ) |} | - """.trimMargin(), + """.trimMargin(), rulesConfigList = rulesConfigList ) } @@ -173,7 +173,7 @@ class IndentationRuleWarnTest : LintTestBase(::IndentationRule), IndentationRule | val field3: Type3) { |} | - """.trimMargin(), + """.trimMargin(), rulesConfigList = rulesConfigList ) } @@ -189,7 +189,7 @@ class IndentationRuleWarnTest : LintTestBase(::IndentationRule), IndentationRule | val field3: Type3) { |} | - """.trimMargin(), + """.trimMargin(), LintError(2, 1, ruleId, warnText(8, 14), true), LintError(3, 1, ruleId, warnText(8, 14), true), LintError(4, 1, ruleId, warnText(8, 14), true), @@ -207,7 +207,7 @@ class IndentationRuleWarnTest : LintTestBase(::IndentationRule), IndentationRule | b |} | - """.trimMargin(), + """.trimMargin(), rulesConfigList = rulesConfigList ) } @@ -223,7 +223,7 @@ class IndentationRuleWarnTest : LintTestBase(::IndentationRule), IndentationRule |class Example { |} | - """.trimMargin() + """.trimMargin() ) } @@ -238,12 +238,12 @@ class IndentationRuleWarnTest : LintTestBase(::IndentationRule), IndentationRule | } | | val b = - | list.filter { + | list.filter { | predicate(it) | } |} | - """.trimMargin() + """.trimMargin() ) } @@ -263,7 +263,7 @@ class IndentationRuleWarnTest : LintTestBase(::IndentationRule), IndentationRule | } |} | - """.trimMargin() + """.trimMargin() ) } @@ -278,7 +278,7 @@ class IndentationRuleWarnTest : LintTestBase(::IndentationRule), IndentationRule |class Example { |} | - """.trimMargin(), + """.trimMargin(), LintError(2, 1, ruleId, warnText(1, 0), true), LintError(3, 1, ruleId, warnText(1, 0), true) ) @@ -305,7 +305,7 @@ class IndentationRuleWarnTest : LintTestBase(::IndentationRule), IndentationRule | as? Baz |} | - """.trimMargin() + """.trimMargin() ) } @@ -317,18 +317,18 @@ class IndentationRuleWarnTest : LintTestBase(::IndentationRule), IndentationRule |fun foo() { | for (i in 1..100) | println(i) - | + | | do | println() | while (condition) - | + | | if (condition) | bar() | else | baz() |} | - """.trimMargin() + """.trimMargin() ) } @@ -340,18 +340,18 @@ class IndentationRuleWarnTest : LintTestBase(::IndentationRule), IndentationRule |fun foo() { | for (i in 1..100) | println(i) - | + | | do | println() | while (condition) - | + | | if (condition) | bar() | else | baz() |} | - """.trimMargin(), + """.trimMargin(), LintError(3, 1, ruleId, warnText(8, 4), true), LintError(6, 1, ruleId, warnText(8, 4), true), LintError(10, 1, ruleId, warnText(8, 4), true), @@ -369,20 +369,20 @@ class IndentationRuleWarnTest : LintTestBase(::IndentationRule), IndentationRule | bar() | } else | baz() - | + | | if (condition) | bar() | else { | baz() | } - | + | | if (condition) | bar() | else if (condition2) { | baz() | } else | qux() - | + | | if (condition) | bar() | else if (condition2) @@ -392,7 +392,7 @@ class IndentationRuleWarnTest : LintTestBase(::IndentationRule), IndentationRule | } |} | - """.trimMargin() + """.trimMargin() ) } @@ -419,7 +419,7 @@ class IndentationRuleWarnTest : LintTestBase(::IndentationRule), IndentationRule | ) |} | - """.trimMargin() + """.trimMargin() ) } @@ -436,7 +436,7 @@ class IndentationRuleWarnTest : LintTestBase(::IndentationRule), IndentationRule | ) |} | - """.trimMargin(), + """.trimMargin(), rulesConfigList = disabledOptionsRulesConfigList ) } @@ -449,15 +449,15 @@ class IndentationRuleWarnTest : LintTestBase(::IndentationRule), IndentationRule |class Example { | private val foo | get() = 0 - | + | | private var backing = 0 - | + | | var bar | get() = backing | set(value) { backing = value } |} | - """.trimMargin() + """.trimMargin() ) } @@ -469,15 +469,15 @@ class IndentationRuleWarnTest : LintTestBase(::IndentationRule), IndentationRule |class Example { | private val foo | get() = 0 - | + | | private var backing = 0 - | + | | var bar | get() = backing | set(value) { backing = value } |} | - """.trimMargin(), + """.trimMargin(), LintError(3, 1, ruleId, warnText(8, 12), true), LintError(8, 1, ruleId, warnText(8, 4), true), LintError(9, 1, ruleId, warnText(8, 4), true) @@ -503,7 +503,7 @@ class IndentationRuleWarnTest : LintTestBase(::IndentationRule), IndentationRule | ) |} | - """.trimMargin() + """.trimMargin() ) } @@ -528,7 +528,7 @@ class IndentationRuleWarnTest : LintTestBase(::IndentationRule), IndentationRule | } |} | - """.trimMargin(), + """.trimMargin(), rulesConfigList = listOf( RulesConfig(WRONG_INDENTATION.name, true, mapOf( @@ -558,7 +558,7 @@ class IndentationRuleWarnTest : LintTestBase(::IndentationRule), IndentationRule | } |} | - """.trimMargin() + """.trimMargin() ) } @@ -580,7 +580,7 @@ class IndentationRuleWarnTest : LintTestBase(::IndentationRule), IndentationRule | } |} | - """.trimMargin(), + """.trimMargin(), LintError(4, 1, ruleId, warnText(12, 8), true), LintError(7, 1, ruleId, warnText(12, 8), true), LintError(10, 1, ruleId, warnText(12, 8), true) @@ -619,7 +619,7 @@ class IndentationRuleWarnTest : LintTestBase(::IndentationRule), IndentationRule | } |} | - """.trimMargin() + """.trimMargin() ) } @@ -651,7 +651,7 @@ class IndentationRuleWarnTest : LintTestBase(::IndentationRule), IndentationRule | ) |} | - """.trimMargin() + """.trimMargin() ) } @@ -668,7 +668,7 @@ class IndentationRuleWarnTest : LintTestBase(::IndentationRule), IndentationRule | .bar() | }" | } - | + | | val b = "${'$'}{ foo().bar() }" |} | 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 a2a120d045..107489b267 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 @@ -47,7 +47,7 @@ class WhiteSpaceRuleWarnTest : LintTestBase(::WhiteSpaceRule) { | when (expression) { } | } |} - """.trimMargin() + """.trimMargin() ) } @@ -63,7 +63,7 @@ class WhiteSpaceRuleWarnTest : LintTestBase(::WhiteSpaceRule) { | when(expression) { } | } |} - """.trimMargin(), + """.trimMargin(), LintError(3, 11, ruleId, keywordWarn("if", "("), true), LintError(4, 14, ruleId, keywordWarn("for", "("), true), LintError(5, 13, ruleId, keywordWarn("when", "("), true) @@ -78,7 +78,7 @@ class WhiteSpaceRuleWarnTest : LintTestBase(::WhiteSpaceRule) { |class Example { | constructor (val a: Int) |} - """.trimMargin(), + """.trimMargin(), LintError(2, 5, ruleId, "${WRONG_WHITESPACE.warnText()} keyword 'constructor' should not be separated from '(' with a whitespace", true) ) } @@ -96,7 +96,7 @@ class WhiteSpaceRuleWarnTest : LintTestBase(::WhiteSpaceRule) { | finally{ } | } |} - """.trimMargin(), + """.trimMargin(), LintError(4, 14, ruleId, keywordWarn("else", "{"), true), LintError(5, 13, ruleId, keywordWarn("try", "{"), true), LintError(6, 17, ruleId, keywordWarn("finally", "{"), true) @@ -113,10 +113,10 @@ class WhiteSpaceRuleWarnTest : LintTestBase(::WhiteSpaceRule) { | bar() | else | baz() - | + | | if (condition) bar() else baz() |} - """.trimMargin(), + """.trimMargin(), LintError(7, 33, ruleId, keywordWarn("else", "baz"), true) ) } @@ -133,7 +133,7 @@ class WhiteSpaceRuleWarnTest : LintTestBase(::WhiteSpaceRule) { | } | } |} - """.trimMargin(), + """.trimMargin(), LintError(1, 14, ruleId, lbraceWarn, true), LintError(2, 14, ruleId, lbraceWarn, true), LintError(3, 17, ruleId, lbraceWarn, true), @@ -155,7 +155,7 @@ class WhiteSpaceRuleWarnTest : LintTestBase(::WhiteSpaceRule) { |} | |val lambda = { x: Int -> 2 * x } - """.trimMargin(), + """.trimMargin(), LintError(6, 10, ruleId, "${WRONG_WHITESPACE.warnText()} there should be no whitespace before '{' of lambda inside argument list", true) ) } @@ -167,12 +167,12 @@ class WhiteSpaceRuleWarnTest : LintTestBase(::WhiteSpaceRule) { """ |class Example where T : UpperType { | fun foo(t: T) = t + 1 - | + | | fun bar() { | listOf().map(this::foo).filter { elem -> predicate(elem) } | } |} - """.trimMargin() + """.trimMargin() ) } @@ -186,7 +186,7 @@ class WhiteSpaceRuleWarnTest : LintTestBase(::WhiteSpaceRule) { | UpperType { | fun foo(t: T) = | t + 1 - | + | | fun bar() { | listOf() | .map(this @@ -196,7 +196,7 @@ class WhiteSpaceRuleWarnTest : LintTestBase(::WhiteSpaceRule) { | } | } |} - """.trimMargin() + """.trimMargin() ) } @@ -210,7 +210,7 @@ class WhiteSpaceRuleWarnTest : LintTestBase(::WhiteSpaceRule) { | UpperType { | fun foo(t: T) = // another comment | t + 1 - | + | | fun bar() { | listOf() | .map(this // lorem ipsum @@ -220,7 +220,7 @@ class WhiteSpaceRuleWarnTest : LintTestBase(::WhiteSpaceRule) { | } | } |} - """.trimMargin() + """.trimMargin() ) } @@ -234,14 +234,14 @@ class WhiteSpaceRuleWarnTest : LintTestBase(::WhiteSpaceRule) { | fun foo(t: T) = t+ 1 | fun foo2(t: T) = t+1 | fun foo3(t: T) = t +1 - | + | | fun bar() { | listOf() .map(this ::foo) ?.filter { elem ->predicate(elem) } !!.first() | listOf() . map(this :: foo) ?. filter { elem->predicate(elem) } !! .first() | listOf(). map(this:: foo)?. filter { elem-> predicate(elem) }!!. first() | } |} - """.trimMargin(), + """.trimMargin(), LintError(1, 31, ruleId, tokenWarn(":", 0, 0, 1, 1), true), LintError(1, 44, ruleId, tokenWarn(":", 0, null, 1, 1), true), LintError(1, 59, ruleId, tokenWarn(":", null, 0, 1, 1), true), @@ -276,15 +276,15 @@ class WhiteSpaceRuleWarnTest : LintTestBase(::WhiteSpaceRule) { | fun foo(t1: T, t2: T) { | println(); println() | } - | + | | fun bar(t: T, | d: T) { | println(); | } - | + | | val x: Int |} - """.trimMargin() + """.trimMargin() ) } @@ -294,14 +294,14 @@ class WhiteSpaceRuleWarnTest : LintTestBase(::WhiteSpaceRule) { lintMethod( """ |class Example {${" "} - | fun foo(t1 :T ,t2:T) {${" "} + | fun foo(t1 :T ,t2:T) {${" "} | println();println() | println() ; println() | } - | + | | val x : Int |} - """.trimMargin(), + """.trimMargin(), LintError(1, 19, ruleId, eolSpaceWarn, true), LintError(2, 16, ruleId, tokenWarn(":", 1, 0, 0, 1), true), LintError(2, 19, ruleId, tokenWarn(",", 1, 0, 0, 1), true), @@ -325,7 +325,7 @@ class WhiteSpaceRuleWarnTest : LintTestBase(::WhiteSpaceRule) { | | val x = object : IFoo { /*...*/ } |} - """.trimMargin() + """.trimMargin() ) } @@ -341,7 +341,7 @@ class WhiteSpaceRuleWarnTest : LintTestBase(::WhiteSpaceRule) { | | val x = object: IFoo { /*...*/ } |} - """.trimMargin(), + """.trimMargin(), LintError(1, 25, ruleId, tokenWarn(":", 0, null, 1, 1), true), LintError(1, 31, ruleId, tokenWarn(":", 0, null, 1, 1), true), LintError(3, 14, ruleId, tokenWarn(":", 0, null, 1, 1), true), @@ -359,7 +359,7 @@ class WhiteSpaceRuleWarnTest : LintTestBase(::WhiteSpaceRule) { | lateinit var x: Int? | lateinit var x: Int ? |} - """.trimMargin(), + """.trimMargin(), LintError(3, 25, ruleId, tokenWarn("?", 1, null, 0, null), true) ) } @@ -371,7 +371,7 @@ class WhiteSpaceRuleWarnTest : LintTestBase(::WhiteSpaceRule) { """ |val x = list[0] |val y = list [0] - """.trimMargin(), + """.trimMargin(), LintError(2, 14, ruleId, tokenWarn("[", 1, null, 0, 0), true) ) } @@ -383,13 +383,13 @@ class WhiteSpaceRuleWarnTest : LintTestBase(::WhiteSpaceRule) { """ |class Example(val x: Int) { | constructor() : this(0) - | + | | fun foo(y: Int): AnotherExample { | bar(x) | return AnotherExample(y) | } |} - """.trimMargin() + """.trimMargin() ) } @@ -406,7 +406,7 @@ class WhiteSpaceRuleWarnTest : LintTestBase(::WhiteSpaceRule) { | return AnotherExample (y) | } |} - """.trimMargin(), + """.trimMargin(), LintError(1, 15, ruleId, tokenWarn("(", 1, null, 0, 0), true), LintError(2, 26, ruleId, tokenWarn("(", 1, null, 0, 0), true), LintError(4, 13, ruleId, tokenWarn("(", 1, null, 0, 0), true), @@ -423,7 +423,7 @@ class WhiteSpaceRuleWarnTest : LintTestBase(::WhiteSpaceRule) { |fun foo(): String = "lorem" |fun bar() : String = "ipsum" |fun baz() :String = "dolor" - """.trimMargin(), + """.trimMargin(), LintError(2, 11, ruleId, tokenWarn(":", 1, null, 0, 1), true), LintError(3, 11, ruleId, tokenWarn(":", 1, 0, 0, 1), true) ) @@ -437,11 +437,11 @@ class WhiteSpaceRuleWarnTest : LintTestBase(::WhiteSpaceRule) { |class Example(@field:Anno val foo: Type, | @get:Anno val bar: Type, | @param:Anno val baz: Type) - | + | |class Example2(@field: Anno val foo: Type, | @get :Anno val bar: Type, | @param : Anno val baz: Type) - """.trimMargin(), + """.trimMargin(), LintError(5, 22, ruleId, tokenWarn(":", null, 1, 0, 0), true), LintError(6, 21, ruleId, tokenWarn(":", 1, null, 0, 0), true), LintError(7, 23, ruleId, tokenWarn(":", 1, 1, 0, 0), true) @@ -456,7 +456,7 @@ class WhiteSpaceRuleWarnTest : LintTestBase(::WhiteSpaceRule) { |fun foo() { | val codeFix = CodeFix(codeForm.initialCode!! ,codeFormHtml.ruleSet[0]) |} - """.trimMargin(), + """.trimMargin(), LintError(2, 50, ruleId, tokenWarn(",", 1, 0, 0, 1), true) ) } @@ -470,7 +470,7 @@ class WhiteSpaceRuleWarnTest : LintTestBase(::WhiteSpaceRule) { |fun foo() { | |} - """.trimMargin(), + """.trimMargin(), LintError(1, 13, ruleId, tokenWarn("(\"Text\")", 1, null, 0, null), true) ) } @@ -479,13 +479,13 @@ class WhiteSpaceRuleWarnTest : LintTestBase(::WhiteSpaceRule) { @Tag(WarningNames.WRONG_WHITESPACE) fun `check space on both sides of equals`() { lintMethod( - """ + """ |fun foo() { | val q=10 | var w = 10 | w=q |} - """.trimMargin(), + """.trimMargin(), LintError(2, 9, ruleId, tokenWarn("=", 0, 0, 1, 1), true), LintError(4, 5, ruleId, tokenWarn("=", 0, 0, 1, 1), true) ) @@ -495,11 +495,11 @@ class WhiteSpaceRuleWarnTest : LintTestBase(::WhiteSpaceRule) { @Tag(WarningNames.WRONG_WHITESPACE) fun `check eq in other cases`() { lintMethod( - """ + """ |fun foo()=10 | |val q =goo(text=ty) - """.trimMargin(), + """.trimMargin(), LintError(1, 10, ruleId, tokenWarn("=", 0, 0, 1, 1), true), LintError(3, 7, ruleId, tokenWarn("=", null, 0, 1, 1), true), LintError(3, 16, ruleId, tokenWarn("=", 0, 0, 1, 1), true) @@ -510,11 +510,11 @@ class WhiteSpaceRuleWarnTest : LintTestBase(::WhiteSpaceRule) { @Tag(WarningNames.WRONG_WHITESPACE) fun `singe space after open brace`() { lintMethod( - """ + """ |fun foo() { | "${"$"}{foo()}" |} - """.trimMargin() + """.trimMargin() ) } @@ -522,12 +522,12 @@ class WhiteSpaceRuleWarnTest : LintTestBase(::WhiteSpaceRule) { @Tag(WarningNames.WRONG_WHITESPACE) fun `array initializers in annotations`() { lintMethod( - """ + """ |@RequestMapping(value =["/"], method = [RequestMethod.GET]) |fun foo() { | a[0] |} - """.trimMargin(), + """.trimMargin(), LintError(1, 23, ruleId, tokenWarn("=", null, 0, 1, 1), true), LintError(1, 24, ruleId, tokenWarn("[", 0, null, 1, 0), true) ) @@ -541,7 +541,7 @@ class WhiteSpaceRuleWarnTest : LintTestBase(::WhiteSpaceRule) { |fun foo() { | Example(cb = { _, _ -> Unit }) |} - """.trimMargin() + """.trimMargin() ) } @@ -553,7 +553,7 @@ class WhiteSpaceRuleWarnTest : LintTestBase(::WhiteSpaceRule) { |val q = foo(bar, { it.baz() }) |val q = foo({ it.baz() }) |val q = foo( { it.baz() }) - """.trimMargin(), + """.trimMargin(), LintError(3, 14, ruleId, "${WRONG_WHITESPACE.warnText()} there should be no whitespace before '{' of lambda inside argument list", true) ) @@ -570,7 +570,7 @@ class WhiteSpaceRuleWarnTest : LintTestBase(::WhiteSpaceRule) { | bar(param1, param2 = ::ClassName) | list.map(::operationReference) |} - """.trimMargin() + """.trimMargin() ) } @@ -585,7 +585,7 @@ class WhiteSpaceRuleWarnTest : LintTestBase(::WhiteSpaceRule) { | bar(param1, param2 = :: ClassName) | list.map(:: operationReference) |} - """.trimMargin(), + """.trimMargin(), LintError(2, 12, ruleId, tokenWarn("(", null, 1, 0, 0), true), LintError(2, 14, ruleId, tokenWarn("::", null, 1, null, 0), true), LintError(3, 15, ruleId, tokenWarn(",", null, 2, 0, 1), true), diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter4/AccurateCalculationsWarnTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter4/AccurateCalculationsWarnTest.kt index 989ad647fa..ec7d3014e4 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter4/AccurateCalculationsWarnTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter4/AccurateCalculationsWarnTest.kt @@ -28,7 +28,7 @@ class AccurateCalculationsWarnTest : LintTestBase(::AccurateCalculationsRule) { | 1.0.equals(x) | } |} - """.trimMargin(), + """.trimMargin(), LintError(3, 9, ruleId, warnText("1.0", "x == 1.0"), false), LintError(4, 9, ruleId, warnText("1.0", "1.0 == x"), false), LintError(5, 9, ruleId, warnText("1.0", "x.equals(1.0)"), false), @@ -49,7 +49,7 @@ class AccurateCalculationsWarnTest : LintTestBase(::AccurateCalculationsRule) { | 1.0.compareTo(x) | } |} - """.trimMargin(), + """.trimMargin(), LintError(3, 9, ruleId, warnText("1.0", "x > 1.0"), false), LintError(4, 9, ruleId, warnText("1.0", "1.0 > x"), false), LintError(5, 9, ruleId, warnText("1.0", "x.compareTo(1.0)"), false), @@ -68,7 +68,7 @@ class AccurateCalculationsWarnTest : LintTestBase(::AccurateCalculationsRule) { | x == 1 | } |} - """.trimMargin(), + """.trimMargin(), LintError(4, 9, ruleId, warnText("x", "x == 1"), false) ) } @@ -87,7 +87,7 @@ class AccurateCalculationsWarnTest : LintTestBase(::AccurateCalculationsRule) { | } | } |} - """.trimMargin(), + """.trimMargin(), LintError(6, 13, ruleId, warnText("x", "x == 1"), false) ) } @@ -108,7 +108,7 @@ class AccurateCalculationsWarnTest : LintTestBase(::AccurateCalculationsRule) { | } | } |} - """.trimMargin() + """.trimMargin() ) } @@ -135,7 +135,7 @@ class AccurateCalculationsWarnTest : LintTestBase(::AccurateCalculationsRule) { | x %= 2 | } |} - """.trimMargin(), + """.trimMargin(), LintError(4, 9, ruleId, warnText("x", "x == 1"), false), LintError(5, 9, ruleId, warnText("x", "x + 2"), false), // LintError(6, 9, ruleId, warnText("x", "x++"), false), @@ -163,22 +163,22 @@ class AccurateCalculationsWarnTest : LintTestBase(::AccurateCalculationsRule) { | if (abs(1.0 - 0.999) < 1e-6) { | println("Comparison with tolerance") | } - | + | | 1e-6 > abs(1.0 - 0.999) | abs(1.0 - 0.999).compareTo(1e-6) < 0 | 1e-6.compareTo(abs(1.0 - 0.999)) < 0 | abs(1.0 - 0.999) == 1e-6 - | + | | abs(1.0 - 0.999) < eps | eps > abs(1.0 - 0.999) - | + | | val x = 1.0 | val y = 0.999 | abs(x - y) < eps | eps > abs(x - y) | abs(1.0 - 0.999) == eps |} - """.trimMargin(), + """.trimMargin(), LintError(11, 5, ruleId, warnText("1e-6", "abs(1.0 - 0.999) == 1e-6"), false), LintError(11, 9, ruleId, warnText("1.0", "1.0 - 0.999"), false), LintError(20, 9, ruleId, warnText("1.0", "1.0 - 0.999"), false) diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter4/NoVarRuleWarnTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter4/NoVarRuleWarnTest.kt index bb756ba525..a443c8772f 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter4/NoVarRuleWarnTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter4/NoVarRuleWarnTest.kt @@ -18,13 +18,13 @@ class NoVarRuleWarnTest : LintTestBase(::ImmutableValNoVarRule) { fun `valid case where x is used in while loop as some counter`() { lintMethod( """ - | fun foo() { + | fun foo() { | var x = 0 | while (x < 10) { | x++ | } | } - """.trimMargin(), + """.trimMargin(), ) } @@ -33,7 +33,7 @@ class NoVarRuleWarnTest : LintTestBase(::ImmutableValNoVarRule) { fun `valid case where y is used in for each loop as some counter, but a is not`() { lintMethod( """ - | fun foo() { + | fun foo() { | var a = emptyList() | a = 15 | var y = 0 @@ -41,7 +41,7 @@ class NoVarRuleWarnTest : LintTestBase(::ImmutableValNoVarRule) { | y = x + 1 | } | } - """.trimMargin(), + """.trimMargin(), LintError(2, 6, ruleId, "${Warnings.SAY_NO_TO_VAR.warnText()} var a = emptyList()", false) ) } @@ -51,10 +51,10 @@ class NoVarRuleWarnTest : LintTestBase(::ImmutableValNoVarRule) { fun `For loop with internal counter`() { lintMethod( """ - | fun foo() { + | fun foo() { | for (x in 0..10) println(x) | } - """.trimMargin() + """.trimMargin() ) } @@ -63,10 +63,10 @@ class NoVarRuleWarnTest : LintTestBase(::ImmutableValNoVarRule) { fun `var in class`() { lintMethod( """ - | class A { + | class A { | var a = 0 | } - """.trimMargin() + """.trimMargin() ) } @@ -81,7 +81,7 @@ class NoVarRuleWarnTest : LintTestBase(::ImmutableValNoVarRule) { | a = a + 56 | return a | } - """.trimMargin(), + """.trimMargin(), LintError(2, 6, ruleId, "${Warnings.SAY_NO_TO_VAR.warnText()} var a = 0", false) ) } diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter4/NullChecksRuleWarnTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter4/NullChecksRuleWarnTest.kt index 467fcc8225..679bef21e3 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter4/NullChecksRuleWarnTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter4/NullChecksRuleWarnTest.kt @@ -25,7 +25,7 @@ class NullChecksRuleWarnTest : LintTestBase(::NullChecksRule) { | return | } | } - """.trimMargin(), + """.trimMargin(), LintError(3, 10, ruleId, "${Warnings.AVOID_NULL_CHECKS.warnText()} use '.let/.also/?:/e.t.c' instead of myVar == null", true), ) } @@ -41,11 +41,11 @@ class NullChecksRuleWarnTest : LintTestBase(::NullChecksRule) { | println("null") | return | } - | myVar ?: kotlin.run { + | myVar ?: kotlin.run { | println("null") | } | } - """.trimMargin(), + """.trimMargin(), LintError(3, 11, ruleId, Warnings.AVOID_NULL_CHECKS.warnText() + " use '.let/.also/?:/e.t.c' instead of myVar == null", true), ) @@ -62,7 +62,7 @@ class NullChecksRuleWarnTest : LintTestBase(::NullChecksRule) { | return | } | } - """.trimMargin(), + """.trimMargin(), LintError(2, 10, ruleId, Warnings.AVOID_NULL_CHECKS.warnText() + " use '.let/.also/?:/e.t.c' instead of myVar != null", true), ) @@ -81,7 +81,7 @@ class NullChecksRuleWarnTest : LintTestBase(::NullChecksRule) { | 2 | } | } - """.trimMargin(), + """.trimMargin(), LintError(2, 27, ruleId, Warnings.AVOID_NULL_CHECKS.warnText() + " use '.let/.also/?:/e.t.c' instead of myVar != null", true), ) @@ -99,7 +99,7 @@ class NullChecksRuleWarnTest : LintTestBase(::NullChecksRule) { | println("null") | } | } - """.trimMargin(), + """.trimMargin(), LintError(2, 10, ruleId, Warnings.AVOID_NULL_CHECKS.warnText() + " use '.let/.also/?:/e.t.c' instead of myVar !== null", true), ) @@ -120,7 +120,7 @@ class NullChecksRuleWarnTest : LintTestBase(::NullChecksRule) { | } | } | } - """.trimMargin(), + """.trimMargin(), ) } @@ -136,7 +136,7 @@ class NullChecksRuleWarnTest : LintTestBase(::NullChecksRule) { | println() | } | } - """.trimMargin() + """.trimMargin() ) } @@ -152,7 +152,7 @@ class NullChecksRuleWarnTest : LintTestBase(::NullChecksRule) { | println() | } | } - """.trimMargin() + """.trimMargin() ) } @@ -170,7 +170,7 @@ class NullChecksRuleWarnTest : LintTestBase(::NullChecksRule) { | } | } | } - """.trimMargin(), + """.trimMargin(), LintError(2, 10, ruleId, "${Warnings.AVOID_NULL_CHECKS.warnText()} use '.let/.also/?:/e.t.c'" + " instead of myVar != null", true), ) @@ -184,7 +184,7 @@ class NullChecksRuleWarnTest : LintTestBase(::NullChecksRule) { | fun foo0(myVar: String?) { | require(myVar != null) | } - """.trimMargin(), + """.trimMargin(), LintError(2, 14, ruleId, Warnings.AVOID_NULL_CHECKS.warnText() + " use 'requireNotNull' instead of require(myVar != null)", true), ) @@ -195,11 +195,11 @@ class NullChecksRuleWarnTest : LintTestBase(::NullChecksRule) { fun `null check in lambda which is in if-statement is ok`() { lintMethod( """ - |fun foo() { - | if (leftSide?.any { it == null } == true) { - | return - | } - |} + |fun foo() { + | if (leftSide?.any { it == null } == true) { + | return + | } + |} """.trimMargin() ) } @@ -209,9 +209,9 @@ class NullChecksRuleWarnTest : LintTestBase(::NullChecksRule) { fun `null check in lambda which is in require is ok`() { lintMethod( """ - |fun foo() { - | require(leftSide?.any { it == null }) - |} + |fun foo() { + | require(leftSide?.any { it == null }) + |} """.trimMargin() ) } diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter4/SmartCastRuleWarnTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter4/SmartCastRuleWarnTest.kt index 3c3891d9b3..2475a0d824 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter4/SmartCastRuleWarnTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter4/SmartCastRuleWarnTest.kt @@ -27,7 +27,7 @@ class SmartCastRuleWarnTest : LintTestBase(::SmartCastRule) { | } | } |} - """.trimMargin() + """.trimMargin() ) } @@ -44,7 +44,7 @@ class SmartCastRuleWarnTest : LintTestBase(::SmartCastRule) { | } | } |} - """.trimMargin(), + """.trimMargin(), LintError(5, 21, ruleId, "${Warnings.SMART_CAST_NEEDED.warnText()} x as String", true) ) } @@ -65,7 +65,7 @@ class SmartCastRuleWarnTest : LintTestBase(::SmartCastRule) { | } | } |} - """.trimMargin() + """.trimMargin() ) } @@ -85,7 +85,7 @@ class SmartCastRuleWarnTest : LintTestBase(::SmartCastRule) { | } | } |} - """.trimMargin(), + """.trimMargin(), LintError(7, 25, ruleId, "${Warnings.SMART_CAST_NEEDED.warnText()} x as Int", true) ) } @@ -105,7 +105,7 @@ class SmartCastRuleWarnTest : LintTestBase(::SmartCastRule) { | } | } |} - """.trimMargin(), + """.trimMargin(), LintError(7, 21, ruleId, "${Warnings.SMART_CAST_NEEDED.warnText()} x as String", true) ) } @@ -122,7 +122,7 @@ class SmartCastRuleWarnTest : LintTestBase(::SmartCastRule) { | print((x as String).length) | } |} - """.trimMargin(), + """.trimMargin(), LintError(5, 19, ruleId, "${Warnings.SMART_CAST_NEEDED.warnText()} x as String", true) ) } @@ -139,7 +139,7 @@ class SmartCastRuleWarnTest : LintTestBase(::SmartCastRule) { | print(x.length) | } |} - """.trimMargin() + """.trimMargin() ) } @@ -158,7 +158,7 @@ class SmartCastRuleWarnTest : LintTestBase(::SmartCastRule) { | print((x as String).length) | } |} - """.trimMargin(), + """.trimMargin(), LintError(8, 19, ruleId, "${Warnings.SMART_CAST_NEEDED.warnText()} x as String", true) ) } @@ -178,14 +178,14 @@ class SmartCastRuleWarnTest : LintTestBase(::SmartCastRule) { | print((x as String).length) | val a = "" | if (a !is String) { - | + | | } else { | print((a as String).length) | } | } | } |} - """.trimMargin(), + """.trimMargin(), LintError(8, 19, ruleId, "${Warnings.SMART_CAST_NEEDED.warnText()} x as String", true), LintError(13, 23, ruleId, "${Warnings.SMART_CAST_NEEDED.warnText()} a as String", true) ) @@ -207,7 +207,7 @@ class SmartCastRuleWarnTest : LintTestBase(::SmartCastRule) { | } | } |} - """.trimMargin(), + """.trimMargin(), LintError(5, 29, ruleId, "${Warnings.SMART_CAST_NEEDED.warnText()} x as Int", true) ) } @@ -226,7 +226,7 @@ class SmartCastRuleWarnTest : LintTestBase(::SmartCastRule) { | } | } |} - """.trimMargin() + """.trimMargin() ) } @@ -235,10 +235,10 @@ class SmartCastRuleWarnTest : LintTestBase(::SmartCastRule) { fun `smart cast in when good 2`() { lintMethod( """ - |fun SomeClass.foo() = when (mutableProperty) { - | is Foo -> (mutableProperty as Foo).fooFoo() // smart cast is required 'because 'mutableProperty' is a property that has open or custom getter' - | else -> println("ok") - |} + |fun SomeClass.foo() = when (mutableProperty) { + | is Foo -> (mutableProperty as Foo).fooFoo() // smart cast is required 'because 'mutableProperty' is a property that has open or custom getter' + | else -> println("ok") + |} """.trimMargin() ) } @@ -258,7 +258,7 @@ class SmartCastRuleWarnTest : LintTestBase(::SmartCastRule) { | } | } |} - """.trimMargin() + """.trimMargin() ) } @@ -277,7 +277,7 @@ class SmartCastRuleWarnTest : LintTestBase(::SmartCastRule) { | } | } |} - """.trimMargin(), + """.trimMargin(), LintError(6, 21, ruleId, "${Warnings.SMART_CAST_NEEDED.warnText()} x as String", true), LintError(7, 21, ruleId, "${Warnings.SMART_CAST_NEEDED.warnText()} y as Int", true) ) @@ -298,7 +298,7 @@ class SmartCastRuleWarnTest : LintTestBase(::SmartCastRule) { | } | } |} - """.trimMargin() + """.trimMargin() ) } @@ -316,7 +316,7 @@ class SmartCastRuleWarnTest : LintTestBase(::SmartCastRule) { | } | } |} - """.trimMargin() + """.trimMargin() ) } @@ -337,7 +337,7 @@ class SmartCastRuleWarnTest : LintTestBase(::SmartCastRule) { | } | } |} - """.trimMargin(), + """.trimMargin(), LintError(8, 25, ruleId, "${Warnings.SMART_CAST_NEEDED.warnText()} x as Int", true) ) } @@ -356,7 +356,7 @@ class SmartCastRuleWarnTest : LintTestBase(::SmartCastRule) { | } | } |} - """.trimMargin(), + """.trimMargin(), LintError(6, 21, ruleId, "${Warnings.SMART_CAST_NEEDED.warnText()} x as Int", true) ) } diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter4/TypeAliasRuleWarnTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter4/TypeAliasRuleWarnTest.kt index 5b5a023d18..5d15adcde1 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter4/TypeAliasRuleWarnTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter4/TypeAliasRuleWarnTest.kt @@ -25,7 +25,7 @@ class TypeAliasRuleWarnTest : LintTestBase(::TypeAliasRule) { """ | val b: MutableMap> | val b = listof() - """.trimMargin(), + """.trimMargin(), LintError(1, 9, ruleId, "${TYPE_ALIAS.warnText()} too long type reference", false) ) } @@ -37,7 +37,7 @@ class TypeAliasRuleWarnTest : LintTestBase(::TypeAliasRule) { """ | var emitWarn: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit | var emitWarn: (offset: Int, (T) -> Boolean) -> Unit - """.trimMargin(), + """.trimMargin(), LintError(1, 16, ruleId, "${TYPE_ALIAS.warnText()} too long type reference", false), LintError(2, 16, ruleId, "${TYPE_ALIAS.warnText()} too long type reference", false) ) @@ -50,11 +50,11 @@ class TypeAliasRuleWarnTest : LintTestBase(::TypeAliasRule) { """ | var emitWarn: Int | val b = mutableMapOf>() - | + | | fun foo(): MutableMap> { | } - | - """.trimMargin(), + | + """.trimMargin(), LintError(4, 13, ruleId, "${TYPE_ALIAS.warnText()} too long type reference", false) ) } @@ -67,8 +67,8 @@ class TypeAliasRuleWarnTest : LintTestBase(::TypeAliasRule) { | var emitWarn: Int | val flag: (T) -> Boolean | val list: List> - | - """.trimMargin(), + | + """.trimMargin(), LintError(3, 12, ruleId, "${TYPE_ALIAS.warnText()} too long type reference", false), rulesConfigList = rulesConfigListShortType ) @@ -86,7 +86,7 @@ class TypeAliasRuleWarnTest : LintTestBase(::TypeAliasRule) { | class B : JsonResourceConfigReader> {} | } | } - """.trimMargin(), + """.trimMargin(), LintError(2, 16, ruleId, "${TYPE_ALIAS.warnText()} too long type reference", false), LintError(3, 11, ruleId, "${TYPE_ALIAS.warnText()} too long type reference", false) ) @@ -97,16 +97,16 @@ class TypeAliasRuleWarnTest : LintTestBase(::TypeAliasRule) { fun `check correct examle`() { lintMethod( """ - |typealias jsonType = JsonResourceConfigReader> + |typealias jsonType = JsonResourceConfigReader> |class A : JsonResourceConfigReader>() { - | + | | fun foo() : jsonType {} | val q: jsonType? = null | fun goo() { | class B : JsonResourceConfigReader> {} | } |} - """.trimMargin() + """.trimMargin() ) } @@ -120,7 +120,7 @@ class TypeAliasRuleWarnTest : LintTestBase(::TypeAliasRule) { | emptyList>() | } |} - """.trimMargin(), + """.trimMargin(), LintError(2, 11, ruleId, "${TYPE_ALIAS.warnText()} too long type reference", false), rulesConfigList = rulesConfigListShortType ) diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter4/VariableGenericTypeDeclarationRuleWarnTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter4/VariableGenericTypeDeclarationRuleWarnTest.kt index 0ac0056245..7a7a1cb6a4 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter4/VariableGenericTypeDeclarationRuleWarnTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter4/VariableGenericTypeDeclarationRuleWarnTest.kt @@ -28,7 +28,7 @@ class VariableGenericTypeDeclarationRuleWarnTest : LintTestBase(::VariableGeneri | val str = someMethod("mapOf") | val x = foo.bar().baz() |} - """.trimMargin() + """.trimMargin() ) } @@ -42,7 +42,7 @@ class VariableGenericTypeDeclarationRuleWarnTest : LintTestBase(::VariableGeneri | val any = Array(3) { "" } | val x = foo.bar().baz() |} - """.trimMargin(), + """.trimMargin(), LintError(2, 4, ruleId, "${Warnings.GENERIC_VARIABLE_WRONG_DECLARATION.warnText()} type arguments are unnecessary in emptyMap()", true), LintError(3, 4, ruleId, @@ -59,10 +59,10 @@ class VariableGenericTypeDeclarationRuleWarnTest : LintTestBase(::VariableGeneri """ |class SomeClass { | private fun someFunc(myVariable: Map = emptyMap()) { - | + | | } |} - """.trimMargin() + """.trimMargin() ) } @@ -73,10 +73,10 @@ class VariableGenericTypeDeclarationRuleWarnTest : LintTestBase(::VariableGeneri """ |class SomeClass { | private fun someFunc(myVariable: List<*> = emptyList()) { - | + | | } |} - """.trimMargin() + """.trimMargin() ) } @@ -87,10 +87,10 @@ class VariableGenericTypeDeclarationRuleWarnTest : LintTestBase(::VariableGeneri """ |class SomeClass { | private fun someFunc(myVariable: Map<*, String> = emptyMap()) { - | + | | } |} - """.trimMargin() + """.trimMargin() ) } @@ -101,10 +101,10 @@ class VariableGenericTypeDeclarationRuleWarnTest : LintTestBase(::VariableGeneri """ |class SomeClass { | private fun someFunc(myVariable: Map = emptyMap()) { - | + | | } |} - """.trimMargin(), + """.trimMargin(), LintError(2, 25, ruleId, "${Warnings.GENERIC_VARIABLE_WRONG_DECLARATION.warnText()} type arguments are unnecessary in emptyMap()", true) ) @@ -120,7 +120,7 @@ class VariableGenericTypeDeclarationRuleWarnTest : LintTestBase(::VariableGeneri | val myVariable: Map = emptyMap() | } |} - """.trimMargin() + """.trimMargin() ) } @@ -134,7 +134,7 @@ class VariableGenericTypeDeclarationRuleWarnTest : LintTestBase(::VariableGeneri | val myVariable: List<*> = emptyList() | } |} - """.trimMargin() + """.trimMargin() ) } @@ -148,7 +148,7 @@ class VariableGenericTypeDeclarationRuleWarnTest : LintTestBase(::VariableGeneri | val myVariable: Map = emptyMap() | } |} - """.trimMargin(), + """.trimMargin(), LintError(3, 8, ruleId, "${Warnings.GENERIC_VARIABLE_WRONG_DECLARATION.warnText()} type arguments are unnecessary in emptyMap()", true) ) @@ -162,7 +162,7 @@ class VariableGenericTypeDeclarationRuleWarnTest : LintTestBase(::VariableGeneri |class SomeClass(val myVariable: Map = emptyMap()) { | |} - """.trimMargin() + """.trimMargin() ) } @@ -174,7 +174,7 @@ class VariableGenericTypeDeclarationRuleWarnTest : LintTestBase(::VariableGeneri |class SomeClass(val myVariable: List<*> = emptyList()) { | |} - """.trimMargin() + """.trimMargin() ) } @@ -186,7 +186,7 @@ class VariableGenericTypeDeclarationRuleWarnTest : LintTestBase(::VariableGeneri |class SomeClass(val myVariable: Map = emptyMap()) { | |} - """.trimMargin(), + """.trimMargin(), LintError(1, 17, ruleId, "${Warnings.GENERIC_VARIABLE_WRONG_DECLARATION.warnText()} type arguments are unnecessary in emptyMap()", true) ) @@ -202,7 +202,7 @@ class VariableGenericTypeDeclarationRuleWarnTest : LintTestBase(::VariableGeneri | val myVariable: Map> = emptyMap>() | } |} - """.trimMargin(), + """.trimMargin(), LintError(3, 8, ruleId, "${Warnings.GENERIC_VARIABLE_WRONG_DECLARATION.warnText()} type arguments are unnecessary in emptyMap>()", true) ) @@ -218,7 +218,7 @@ class VariableGenericTypeDeclarationRuleWarnTest : LintTestBase(::VariableGeneri | var myVariable: Map = emptyMap() | } |} - """.trimMargin() + """.trimMargin() ) } } diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter5/AvoidNestedFunctionsWarnTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter5/AvoidNestedFunctionsWarnTest.kt index bdedc76de3..4635395199 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter5/AvoidNestedFunctionsWarnTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter5/AvoidNestedFunctionsWarnTest.kt @@ -31,7 +31,7 @@ class AvoidNestedFunctionsWarnTest : LintTestBase(::AvoidNestedFunctionsRule) { | } | |} - """.trimMargin(), + """.trimMargin(), LintError(3, 4, ruleId, "${Warnings.AVOID_NESTED_FUNCTIONS.warnText()} fun bar", false) ) } @@ -63,7 +63,7 @@ class AvoidNestedFunctionsWarnTest : LintTestBase(::AvoidNestedFunctionsRule) { | } | |} - """.trimMargin(), + """.trimMargin(), LintError(3, 4, ruleId, "${Warnings.AVOID_NESTED_FUNCTIONS.warnText()} fun bar", true), LintError(4, 8, ruleId, "${Warnings.AVOID_NESTED_FUNCTIONS.warnText()} fun baz", true) ) @@ -76,12 +76,12 @@ class AvoidNestedFunctionsWarnTest : LintTestBase(::AvoidNestedFunctionsRule) { """ |class SomeClass { | fun someFunc() {} - | + | | fun anotherFunc() {} - | + | | fun moreFunction() {} |} - """.trimMargin() + """.trimMargin() ) } @@ -102,7 +102,7 @@ class AvoidNestedFunctionsWarnTest : LintTestBase(::AvoidNestedFunctionsRule) { | })) | } |} - """.trimMargin() + """.trimMargin() ) } } diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter5/FunctionArgumentsSizeWarnTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter5/FunctionArgumentsSizeWarnTest.kt index 1ef07f404f..7a6c6b28c7 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter5/FunctionArgumentsSizeWarnTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter5/FunctionArgumentsSizeWarnTest.kt @@ -28,7 +28,7 @@ class FunctionArgumentsSizeWarnTest : LintTestBase(::FunctionArgumentsSize) { |fun foo(a: Int, b: Int, c: Int, d: Int, myLambda: () -> Unit) {} |fun foo(a: Int, b: Int, c: Int, d: Int, e: Int, myLambda: () -> Unit) = 10 |abstract fun foo(a: Int, b: Int, c: Int, d: Int, e: Int, f: Int) - """.trimMargin(), + """.trimMargin(), LintError(1, 1, ruleId, "${TOO_MANY_PARAMETERS.warnText()} foo has 6, but allowed 5", false), LintError(2, 1, ruleId, "${TOO_MANY_PARAMETERS.warnText()} foo has 6, but allowed 5", false), LintError(4, 1, ruleId, "${TOO_MANY_PARAMETERS.warnText()} foo has 6, but allowed 5", false), @@ -42,7 +42,7 @@ class FunctionArgumentsSizeWarnTest : LintTestBase(::FunctionArgumentsSize) { lintMethod( """ |fun foo(a: Int, b: Int) {} - """.trimMargin(), + """.trimMargin(), LintError(1, 1, ruleId, "${TOO_MANY_PARAMETERS.warnText()} foo has 2, but allowed 1", false), rulesConfigList = rulesConfigList ) diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter5/FunctionLengthWarnTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter5/FunctionLengthWarnTest.kt index 10c1cefd34..d19d0e9975 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter5/FunctionLengthWarnTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter5/FunctionLengthWarnTest.kt @@ -34,11 +34,11 @@ class FunctionLengthWarnTest : LintTestBase(::FunctionLength) { |fun foo() { | | //dkfgvdf - | + | | /* | * jkgh | */ - | + | | /** | * dfkjvbhdfkjb | */ @@ -50,7 +50,7 @@ class FunctionLengthWarnTest : LintTestBase(::FunctionLength) { | println(x) | |} - """.trimMargin(), + """.trimMargin(), LintError(1, 1, ruleId, "${TOO_LONG_FUNCTION.warnText()} max length is 5, but you have 7", false), rulesConfigList = rulesConfigList ) @@ -73,7 +73,7 @@ class FunctionLengthWarnTest : LintTestBase(::FunctionLength) { | println(x) | |} - """.trimMargin(), + """.trimMargin(), rulesConfigList = rulesConfigList ) } @@ -88,9 +88,9 @@ class FunctionLengthWarnTest : LintTestBase(::FunctionLength) { | println() |} | - |fun goo() = + |fun goo() = | 10 - """.trimMargin(), + """.trimMargin(), LintError(1, 1, ruleId, "${TOO_LONG_FUNCTION.warnText()} max length is 2, but you have 4", false), rulesConfigList = shortRulesConfigList ) @@ -104,7 +104,7 @@ class FunctionLengthWarnTest : LintTestBase(::FunctionLength) { |class A() { | val x = 10 | val y = 11 - | + | | fun foo() { | if(true) { | while(true) { @@ -115,7 +115,7 @@ class FunctionLengthWarnTest : LintTestBase(::FunctionLength) { | } | |} - """.trimMargin(), + """.trimMargin(), LintError(5, 4, ruleId, "${TOO_LONG_FUNCTION.warnText()} max length is 2, but you have 8", false), rulesConfigList = shortRulesConfigList ) @@ -130,8 +130,8 @@ class FunctionLengthWarnTest : LintTestBase(::FunctionLength) { |class A() { | val x = 10 | val y = 11 - | - | + | + | | fun foo() { | if(true) { | while(true) { @@ -142,7 +142,7 @@ class FunctionLengthWarnTest : LintTestBase(::FunctionLength) { | } | |} - """.trimMargin(), + """.trimMargin(), rulesConfigList = shortRulesConfigList ) } @@ -153,12 +153,12 @@ class FunctionLengthWarnTest : LintTestBase(::FunctionLength) { lintMethod( """ |fun foo(list: List) { - | - | - | - | + | + | + | + | |} - """.trimMargin(), + """.trimMargin(), rulesConfigList = shortRulesConfigList ) } @@ -171,8 +171,8 @@ class FunctionLengthWarnTest : LintTestBase(::FunctionLength) { |class A() { | val x = 10 | val y = 11 - | - | fun foo() + | + | fun foo() | { | println(123) | } @@ -182,7 +182,7 @@ class FunctionLengthWarnTest : LintTestBase(::FunctionLength) { |abstract class B { | abstract fun foo() |} - """.trimMargin(), + """.trimMargin(), rulesConfigList = shortRulesWithoutHeaderConfigList ) } diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter5/LambdaLengthWarnTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter5/LambdaLengthWarnTest.kt index 8a646d7dd1..13edc70d27 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter5/LambdaLengthWarnTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter5/LambdaLengthWarnTest.kt @@ -29,7 +29,7 @@ class LambdaLengthWarnTest : LintTestBase(::LambdaLengthRule) { | val list = listOf(1, 2, 3, 4, 5) | .map {element -> element + x} |} - """.trimMargin(), + """.trimMargin(), rulesConfigList = rulesConfigList ) } @@ -46,7 +46,7 @@ class LambdaLengthWarnTest : LintTestBase(::LambdaLengthRule) { | ?.let { File(it.file) } | } |} - """.trimMargin(), + """.trimMargin(), rulesConfigList = rulesConfigList ) } @@ -63,7 +63,7 @@ class LambdaLengthWarnTest : LintTestBase(::LambdaLengthRule) { | .removeAt(1) | } |} - """.trimMargin(), + """.trimMargin(), rulesConfigList = rulesConfigList ) } @@ -78,7 +78,7 @@ class LambdaLengthWarnTest : LintTestBase(::LambdaLengthRule) { | val list = listOf(1, 2, 3, 4, 5) | .map {it + x} |} - """.trimMargin(), + """.trimMargin(), rulesConfigList = rulesConfigList ) } @@ -98,7 +98,7 @@ class LambdaLengthWarnTest : LintTestBase(::LambdaLengthRule) { | } | } |} - """.trimMargin(), + """.trimMargin(), rulesConfigList = rulesConfigList ) } @@ -115,13 +115,13 @@ class LambdaLengthWarnTest : LintTestBase(::LambdaLengthRule) { | val y = x + 1 | val z = y + 1 | it + z - | - | - | - | + | + | + | + | | } |} - """.trimMargin(), + """.trimMargin(), LintError(3, 13, ruleId, "${Warnings.TOO_MANY_LINES_IN_LAMBDA.warnText()} max length lambda without arguments is 3, but you have 6", false), rulesConfigList = rulesConfigList ) @@ -140,13 +140,13 @@ class LambdaLengthWarnTest : LintTestBase(::LambdaLengthRule) { | val y = x + 1 | val z = y + 1 | it + z - | - | - | - | + | + | + | + | | } |} - """.trimMargin(), + """.trimMargin(), LintError(4, 13, ruleId, "${Warnings.TOO_MANY_LINES_IN_LAMBDA.warnText()} max length lambda without arguments is 3, but you have 6", false), rulesConfigList = rulesConfigList ) @@ -167,7 +167,7 @@ class LambdaLengthWarnTest : LintTestBase(::LambdaLengthRule) { | } | } | } - """.trimMargin(), + """.trimMargin(), LintError(3, 25, ruleId, "${Warnings.TOO_MANY_LINES_IN_LAMBDA.warnText()} max length lambda without arguments is 3, but you have 6", false), rulesConfigList = rulesConfigList ) diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter5/LambdaParameterOrderWarnTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter5/LambdaParameterOrderWarnTest.kt index cdfb8da91d..ae4284d47b 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter5/LambdaParameterOrderWarnTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter5/LambdaParameterOrderWarnTest.kt @@ -30,7 +30,7 @@ class LambdaParameterOrderWarnTest : LintTestBase(::LambdaParameterOrder) { |fun foo(a: Int? = null, myLambdab: () -> Unit, myLambda: () -> Unit) | |fun foo(lambda1: () -> Unit, lambda2: (() -> Unit)?) {} - """.trimMargin(), + """.trimMargin(), LintError(1, 17, ruleId, "${LAMBDA_IS_NOT_LAST_PARAMETER.warnText()} foo", false) ) } diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter5/NestedFunctionBlockWarnTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter5/NestedFunctionBlockWarnTest.kt index 0cc6569878..a031349938 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter5/NestedFunctionBlockWarnTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter5/NestedFunctionBlockWarnTest.kt @@ -26,7 +26,7 @@ class NestedFunctionBlockWarnTest : LintTestBase(::NestedFunctionBlock) { | while(true) { | println() | } - | + | | when(x) { | 10 -> {10} | else -> { @@ -35,22 +35,22 @@ class NestedFunctionBlockWarnTest : LintTestBase(::NestedFunctionBlock) { | } | } | } - | + | | val x = { | if (true) { | if (false) { | while(false) { - | 10 - | } - | } - | } + | 10 + | } + | } + | } | } - | + | | for(x in 1..2){ | println(x) | } |} - """.trimMargin() + """.trimMargin() ) } @@ -73,7 +73,7 @@ class NestedFunctionBlockWarnTest : LintTestBase(::NestedFunctionBlock) { | println("dscsds") | } |} - """.trimMargin(), + """.trimMargin(), LintError(1, 1, ruleId, "${NESTED_BLOCK.warnText()} foo", false) ) } @@ -90,7 +90,7 @@ class NestedFunctionBlockWarnTest : LintTestBase(::NestedFunctionBlock) { | try { | try{ | try{ - | + | | } catch(ex: Exception){ | try{ | println("hi") @@ -103,7 +103,7 @@ class NestedFunctionBlockWarnTest : LintTestBase(::NestedFunctionBlock) { | println("dscsds") | } |} - """.trimMargin(), + """.trimMargin(), LintError(1, 1, ruleId, "${NESTED_BLOCK.warnText()} foo", false) ) } @@ -119,7 +119,7 @@ class NestedFunctionBlockWarnTest : LintTestBase(::NestedFunctionBlock) { | if (false) { | fun goo() { | if(true) { - | + | | } | } | } @@ -127,7 +127,7 @@ class NestedFunctionBlockWarnTest : LintTestBase(::NestedFunctionBlock) { | println("dscsds") | } |} - """.trimMargin() + """.trimMargin() ) } @@ -159,7 +159,7 @@ class NestedFunctionBlockWarnTest : LintTestBase(::NestedFunctionBlock) { | } | } |} - """.trimMargin(), + """.trimMargin(), LintError(3, 8, ruleId, "${NESTED_BLOCK.warnText()} goo", false) ) } @@ -187,7 +187,7 @@ class NestedFunctionBlockWarnTest : LintTestBase(::NestedFunctionBlock) { } return result } - """.trimMargin() + """.trimMargin() ) } @@ -196,9 +196,9 @@ class NestedFunctionBlockWarnTest : LintTestBase(::NestedFunctionBlock) { fun `check with anonymous class`() { lintMethod( """ - + val q = list.filter {it == 0} - + val keyListener = KeyAdapter { keyEvent -> if (true) { } else if (false) { @@ -209,12 +209,12 @@ class NestedFunctionBlockWarnTest : LintTestBase(::NestedFunctionBlock) { } } } - - val keyListener = object : KeyAdapter() { + + val keyListener = object : KeyAdapter() { override fun keyPressed(keyEvent : KeyEvent) { } - } - """.trimMargin(), + } + """.trimMargin(), LintError(4, 50, ruleId, "${NESTED_BLOCK.warnText()} { keyEvent ->...", false), rulesConfigList = rulesConfigList ) @@ -236,17 +236,17 @@ class NestedFunctionBlockWarnTest : LintTestBase(::NestedFunctionBlock) { | } | } | } - | + | | fun goo() { | if(true){ | if(false){ - | if(true){ + | if(true){ | } | } | } | } |} - """.trimMargin(), + """.trimMargin(), LintError(2, 4, ruleId, "${NESTED_BLOCK.warnText()} foo", false) ) } diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter5/OverloadingArgumentsFunctionWarnTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter5/OverloadingArgumentsFunctionWarnTest.kt index 2eeeed9ba8..0f8b5e2975 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter5/OverloadingArgumentsFunctionWarnTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter5/OverloadingArgumentsFunctionWarnTest.kt @@ -41,10 +41,10 @@ class OverloadingArgumentsFunctionWarnTest : LintTestBase(::OverloadingArguments | |abstract class B { | abstract fun foo(a: Int) - | + | | fun foo(){} |} - """.trimMargin(), + """.trimMargin(), LintError(1, 1, ruleId, "${WRONG_OVERLOADING_FUNCTION_ARGUMENTS.warnText()} foo", false), LintError(16, 1, ruleId, "${WRONG_OVERLOADING_FUNCTION_ARGUMENTS.warnText()} goo", false), LintError(25, 4, ruleId, "${WRONG_OVERLOADING_FUNCTION_ARGUMENTS.warnText()} foo", false) @@ -70,7 +70,7 @@ class OverloadingArgumentsFunctionWarnTest : LintTestBase(::OverloadingArguments ?.getReferencedName() ?.equals("abs") ?: false - + private fun KtBinaryExpression.isComparisonWithAbs(a: Int) = takeIf { it.operationToken in comparisonOperators } ?.run { left as? KtCallExpression ?: right as? KtCallExpression } @@ -78,16 +78,16 @@ class OverloadingArgumentsFunctionWarnTest : LintTestBase(::OverloadingArguments ?.getReferencedName() ?.equals("abs") ?: false - + private fun KtBinaryExpression.isComparisonWithAbs(a: Int): Boolean { return takeIf { it.operationToken in comparisonOperators } ?.run { left as? KtCallExpression ?: right as? KtCallExpression } ?.run { calleeExpression as? KtNameReferenceExpression } ?.getReferencedName() ?.equals("abs") - ?: false + ?: false } - """.trimMargin(), + """.trimMargin(), LintError(8, 21, ruleId, "${WRONG_OVERLOADING_FUNCTION_ARGUMENTS.warnText()} isComparisonWithAbs", false) ) } @@ -103,21 +103,21 @@ class OverloadingArgumentsFunctionWarnTest : LintTestBase(::OverloadingArguments ?.run { calleeExpression as? KtNameReferenceExpression } ?.getReferencedName() ?.equals("abs") - ?: false + ?: false } - + private fun KtBinaryExpression.isComparisonWithAbs(a: Int): Int { val q = takeIf { it.operationToken in comparisonOperators } ?.run { left as? KtCallExpression ?: right as? KtCallExpression } ?.run { calleeExpression as? KtNameReferenceExpression } ?.getReferencedName() ?.equals("abs") - ?: false - + ?: false + if (q) return 10 return 11 } - """.trimMargin() + """.trimMargin() ) } } diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter5/ParameterNameInOuterLambdaRuleWarnTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter5/ParameterNameInOuterLambdaRuleWarnTest.kt index 7c05cbf9a8..5bd632d61e 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter5/ParameterNameInOuterLambdaRuleWarnTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter5/ParameterNameInOuterLambdaRuleWarnTest.kt @@ -32,7 +32,7 @@ class ParameterNameInOuterLambdaRuleWarnTest : LintTestBase(::ParameterNameInOut | println(s) | } |} - """.trimMargin(), + """.trimMargin(), rulesConfigList = rulesConfigList ) } @@ -51,7 +51,7 @@ class ParameterNameInOuterLambdaRuleWarnTest : LintTestBase(::ParameterNameInOut | println(it) | } |} - """.trimMargin(), + """.trimMargin(), rulesConfigList = rulesConfigList ) } @@ -76,7 +76,7 @@ class ParameterNameInOuterLambdaRuleWarnTest : LintTestBase(::ParameterNameInOut | } | } |} - """.trimMargin(), + """.trimMargin(), rulesConfigList = rulesConfigList ) } @@ -101,7 +101,7 @@ class ParameterNameInOuterLambdaRuleWarnTest : LintTestBase(::ParameterNameInOut | } | } |} - """.trimMargin(), + """.trimMargin(), rulesConfigList = rulesConfigList ) } @@ -126,7 +126,7 @@ class ParameterNameInOuterLambdaRuleWarnTest : LintTestBase(::ParameterNameInOut | } | } |} - """.trimMargin(), + """.trimMargin(), LintError(10, 8, ruleId, "${Warnings.PARAMETER_NAME_IN_OUTER_LAMBDA.warnText()} lambda without arguments has inner lambda", false), rulesConfigList = rulesConfigList ) @@ -152,7 +152,7 @@ class ParameterNameInOuterLambdaRuleWarnTest : LintTestBase(::ParameterNameInOut | } | } |} - """.trimMargin(), + """.trimMargin(), rulesConfigList = rulesConfigList ) } @@ -177,7 +177,7 @@ class ParameterNameInOuterLambdaRuleWarnTest : LintTestBase(::ParameterNameInOut | } | } |} - """.trimMargin(), + """.trimMargin(), rulesConfigList = rulesConfigList ) } diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter6/AvoidUtilityClassWarnTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter6/AvoidUtilityClassWarnTest.kt index 87ac112af4..570736ed16 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter6/AvoidUtilityClassWarnTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter6/AvoidUtilityClassWarnTest.kt @@ -22,7 +22,7 @@ class AvoidUtilityClassWarnTest : LintTestBase(::AvoidUtilityClass) { | fun stringInfo(myString: String): Int { | return myString.count{ "something".contains(it) } | } - |} + |} | |class A() { | fun foo() { } @@ -40,7 +40,7 @@ class AvoidUtilityClassWarnTest : LintTestBase(::AvoidUtilityClass) { | return myString.count{ "something".contains(it) } | } |} - """.trimMargin(), + """.trimMargin(), LintError(1, 1, ruleId, "${AVOID_USING_UTILITY_CLASS.warnText()} StringUtil"), LintError(11, 1, ruleId, "${AVOID_USING_UTILITY_CLASS.warnText()} StringUtils") ) @@ -76,7 +76,7 @@ class AvoidUtilityClassWarnTest : LintTestBase(::AvoidUtilityClass) { | return myString.count{ "something".contains(it) } | } |} - """.trimMargin(), + """.trimMargin(), LintError(2, 1, ruleId, "${AVOID_USING_UTILITY_CLASS.warnText()} StringUtils") ) } @@ -89,11 +89,11 @@ class AvoidUtilityClassWarnTest : LintTestBase(::AvoidUtilityClass) { fun foo() { window.addMouseListener(object : MouseAdapter() { override fun mouseClicked(e: MouseEvent) { /*...*/ } - + override fun mouseEntered(e: MouseEvent) { /*...*/ } }) } - """.trimMargin() + """.trimMargin() ) } @@ -107,7 +107,7 @@ class AvoidUtilityClassWarnTest : LintTestBase(::AvoidUtilityClass) { | return myString.count{ "something".contains(it) } | } |} - """.trimMargin(), + """.trimMargin(), LintError(1, 1, ruleId, "${AVOID_USING_UTILITY_CLASS.warnText()} StringUtils"), fileName = "src/main/kotlin/org/cqfn/diktat/Example.kt", ) @@ -119,7 +119,7 @@ class AvoidUtilityClassWarnTest : LintTestBase(::AvoidUtilityClass) { | return myString.count{ "something".contains(it) } | } |} - """.trimMargin(), + """.trimMargin(), fileName = "src/test/kotlin/org/cqfn/diktat/Example.kt" ) lintMethod( @@ -129,7 +129,7 @@ class AvoidUtilityClassWarnTest : LintTestBase(::AvoidUtilityClass) { | return myString.count{ "something".contains(it) } | } |} - """.trimMargin(), + """.trimMargin(), fileName = "src/test/kotlin/org/cqfn/diktat/UtilTest.kt" ) } diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter6/CustomGetterSetterWarnTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter6/CustomGetterSetterWarnTest.kt index 67a42f0ff4..61808208ab 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter6/CustomGetterSetterWarnTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter6/CustomGetterSetterWarnTest.kt @@ -26,7 +26,7 @@ class CustomGetterSetterWarnTest : LintTestBase(::CustomGetterSetterRule) { | } | get() = this.hashCode() * 2 |} - """.trimMargin(), + """.trimMargin(), LintError(3, 9, ruleId, "${Warnings.CUSTOM_GETTERS_SETTERS.warnText()} set"), LintError(7, 9, ruleId, "${Warnings.CUSTOM_GETTERS_SETTERS.warnText()} get"), ) @@ -38,14 +38,14 @@ class CustomGetterSetterWarnTest : LintTestBase(::CustomGetterSetterRule) { lintMethod( """ |class A { - | + | | fun set(value) { | println("Side effect") | } - | + | | fun get() = 47 |} - """.trimMargin(), + """.trimMargin(), ) } @@ -62,7 +62,7 @@ class CustomGetterSetterWarnTest : LintTestBase(::CustomGetterSetterRule) { | } | get() = this.hashCode() * 2 |} - """.trimMargin(), + """.trimMargin(), LintError(7, 9, ruleId, "${Warnings.CUSTOM_GETTERS_SETTERS.warnText()} get"), ) } @@ -80,7 +80,7 @@ class CustomGetterSetterWarnTest : LintTestBase(::CustomGetterSetterRule) { | } | get() = this.hashCode() * 2 |} - """.trimMargin(), + """.trimMargin(), LintError(3, 19, ruleId, "${Warnings.CUSTOM_GETTERS_SETTERS.warnText()} set"), LintError(7, 9, ruleId, "${Warnings.CUSTOM_GETTERS_SETTERS.warnText()} get"), ) diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter6/DataClassesRuleWarnTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter6/DataClassesRuleWarnTest.kt index 2861688e03..841b447d28 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter6/DataClassesRuleWarnTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter6/DataClassesRuleWarnTest.kt @@ -21,7 +21,7 @@ class DataClassesRuleWarnTest : LintTestBase(::DataClassesRule) { |class Some(val a: Int = 5) { | |} - """.trimMargin(), + """.trimMargin(), LintError(1, 1, ruleId, "${Warnings.USE_DATA_CLASS.warnText()} Some") ) } @@ -36,7 +36,7 @@ class DataClassesRuleWarnTest : LintTestBase(::DataClassesRule) { | get() = field | set(value: Int) { field = value} |} - """.trimMargin(), + """.trimMargin(), LintError(1, 1, ruleId, "${Warnings.USE_DATA_CLASS.warnText()} Test") ) } @@ -49,12 +49,12 @@ class DataClassesRuleWarnTest : LintTestBase(::DataClassesRule) { |class Test { | var a: Int = 0 | get() = field - | set(value: Int) { + | set(value: Int) { | field = value | someFun(value) | } |} - """.trimMargin() + """.trimMargin() ) } @@ -80,7 +80,7 @@ class DataClassesRuleWarnTest : LintTestBase(::DataClassesRule) { |enum class Num { | |} - """.trimMargin() + """.trimMargin() ) } @@ -93,7 +93,7 @@ class DataClassesRuleWarnTest : LintTestBase(::DataClassesRule) { | val prop = 5 | private fun someFunc() {} |} - """.trimMargin() + """.trimMargin() ) } @@ -108,7 +108,7 @@ class DataClassesRuleWarnTest : LintTestBase(::DataClassesRule) { | |class A(val map: Map) {} | - """.trimMargin(), + """.trimMargin(), LintError(5, 1, ruleId, "${Warnings.USE_DATA_CLASS.warnText()} A") ) } @@ -122,7 +122,7 @@ class DataClassesRuleWarnTest : LintTestBase(::DataClassesRule) { | |class Ab{} | - """.trimMargin() + """.trimMargin() ) } @@ -136,7 +136,7 @@ class DataClassesRuleWarnTest : LintTestBase(::DataClassesRule) { |} | |class Ab { - | val qw = 10 + | val qw = 10 |} | |class Ba { @@ -157,10 +157,10 @@ class DataClassesRuleWarnTest : LintTestBase(::DataClassesRule) { |class Credentials(auth: String) { | val gitHubUserName: String | val gitHubAuthToken: String - | + | | init { | auth.let { - | + | | } | } |} @@ -176,7 +176,7 @@ class DataClassesRuleWarnTest : LintTestBase(::DataClassesRule) { |class Credentials(auth: String, second: Int?, third: Double) { | val gitHubUserName: String | val gitHubAuthToken: String - | + | | init { | if (second != null) { | } @@ -194,7 +194,7 @@ class DataClassesRuleWarnTest : LintTestBase(::DataClassesRule) { |class Credentials(auth: String, second: Int?, third: Double) { | val gitHubUserName: String | val gitHubAuthToken: String - | + | | init { | foo(third) | } @@ -211,15 +211,15 @@ class DataClassesRuleWarnTest : LintTestBase(::DataClassesRule) { |class Credentials(auth: String, second: Int?, third: Double) { | val gitHubUserName: String | val gitHubAuthToken: String - | + | | init { | auth.let { - | + | | } - | + | | if (second != null) { | } - | + | | foo(third) | } |} @@ -249,7 +249,7 @@ class DataClassesRuleWarnTest : LintTestBase(::DataClassesRule) { |class Credentials(auth: String) { | val gitHubUserName: String = auth.toUpperCase() | val gitHubAuthToken: String = auth.toLowerCase() - | + | | init { | // some logic | } @@ -267,7 +267,7 @@ class DataClassesRuleWarnTest : LintTestBase(::DataClassesRule) { |class Credentials(auth: String, some: Int?) { | val gitHubUserName: String = auth.toUpperCase() | val gitHubAuthToken: String = auth.toLowerCase() - | + | | init { | val a = auth | } diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter6/EmptyPrimaryConstructorWarnTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter6/EmptyPrimaryConstructorWarnTest.kt index 594d3cafad..2a2665c0cd 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter6/EmptyPrimaryConstructorWarnTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter6/EmptyPrimaryConstructorWarnTest.kt @@ -40,7 +40,7 @@ class EmptyPrimaryConstructorWarnTest : LintTestBase(::AvoidEmptyPrimaryConstruc |class Some3 private constructor () { | |} - """.trimMargin(), + """.trimMargin(), LintError(1, 1, ruleId, "${EMPTY_PRIMARY_CONSTRUCTOR.warnText()} Some", true), LintError(8, 1, ruleId, "${EMPTY_PRIMARY_CONSTRUCTOR.warnText()} Some1", true) ) @@ -57,7 +57,7 @@ class EmptyPrimaryConstructorWarnTest : LintTestBase(::AvoidEmptyPrimaryConstruc | |class Some2 @Inject constructor() { |} - """.trimMargin() + """.trimMargin() ) } } diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter6/ImplicitBackingPropertyWarnTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter6/ImplicitBackingPropertyWarnTest.kt index b5ce245dc2..7980a0487a 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter6/ImplicitBackingPropertyWarnTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter6/ImplicitBackingPropertyWarnTest.kt @@ -29,7 +29,7 @@ class ImplicitBackingPropertyWarnTest : LintTestBase(::ImplicitBackingPropertyRu | } | set(value) { field = value } |} - """.trimMargin() + """.trimMargin() ) } @@ -49,7 +49,7 @@ class ImplicitBackingPropertyWarnTest : LintTestBase(::ImplicitBackingPropertyRu | } | set(value) { field = value } |} - """.trimMargin(), + """.trimMargin(), LintError(3, 4, ruleId, "${Warnings.NO_CORRESPONDING_PROPERTY.warnText()} table has no corresponding property with name _table") ) } @@ -63,7 +63,7 @@ class ImplicitBackingPropertyWarnTest : LintTestBase(::ImplicitBackingPropertyRu | private var _a: Map? = null | private val _some:Int? = null |} - """.trimMargin() + """.trimMargin() ) } @@ -77,7 +77,7 @@ class ImplicitBackingPropertyWarnTest : LintTestBase(::ImplicitBackingPropertyRu | private val some:Int? = null | private val _prop: String? = null |} - """.trimMargin() + """.trimMargin() ) } @@ -94,7 +94,7 @@ class ImplicitBackingPropertyWarnTest : LintTestBase(::ImplicitBackingPropertyRu | val some: Int | get() = 3 |} - """.trimMargin() + """.trimMargin() ) } @@ -110,7 +110,7 @@ class ImplicitBackingPropertyWarnTest : LintTestBase(::ImplicitBackingPropertyRu | } | set(value) { field = value } |} - """.trimMargin() + """.trimMargin() ) } @@ -127,7 +127,7 @@ class ImplicitBackingPropertyWarnTest : LintTestBase(::ImplicitBackingPropertyRu | } | set(value) { field = value } |} - """.trimMargin() + """.trimMargin() ) } @@ -143,7 +143,7 @@ class ImplicitBackingPropertyWarnTest : LintTestBase(::ImplicitBackingPropertyRu | field = value | } |} - """.trimMargin() + """.trimMargin() ) } @@ -159,7 +159,7 @@ class ImplicitBackingPropertyWarnTest : LintTestBase(::ImplicitBackingPropertyRu | a = value | } |} - """.trimMargin(), + """.trimMargin(), LintError(2, 4, ruleId, "${Warnings.NO_CORRESPONDING_PROPERTY.warnText()} foo has no corresponding property with name _foo") ) } diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter6/PropertyAccessorFieldsWarnTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter6/PropertyAccessorFieldsWarnTest.kt index c732de01b3..9610a85a96 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter6/PropertyAccessorFieldsWarnTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter6/PropertyAccessorFieldsWarnTest.kt @@ -26,7 +26,7 @@ class PropertyAccessorFieldsWarnTest : LintTestBase(::PropertyAccessorFields) { | field = value | } | get() = field - | + | | var isNotEmpty: Boolean = true | set(value) { | val q = isEmpty.and(true) @@ -37,7 +37,7 @@ class PropertyAccessorFieldsWarnTest : LintTestBase(::PropertyAccessorFields) { | return field | } |} - """.trimMargin() + """.trimMargin() ) } @@ -53,7 +53,7 @@ class PropertyAccessorFieldsWarnTest : LintTestBase(::PropertyAccessorFields) { | println("Side effect") | isEmpty = values | } - | + | | var isNotEmpty: Boolean = true | set(value) { | val q = isNotEmpty.and(true) @@ -63,13 +63,13 @@ class PropertyAccessorFieldsWarnTest : LintTestBase(::PropertyAccessorFields) { | println(12345) | return isNotEmpty | } - | + | | var isNotOk: Boolean = false | set(values) { | this.isNotOk = values | } |} - """.trimMargin(), + """.trimMargin(), LintError(4, 4, ruleId, "${WRONG_NAME_OF_VARIABLE_INSIDE_ACCESSOR.warnText()} set(values) {..."), LintError(14, 4, ruleId, "${WRONG_NAME_OF_VARIABLE_INSIDE_ACCESSOR.warnText()} get() {..."), LintError(20, 4, ruleId, "${WRONG_NAME_OF_VARIABLE_INSIDE_ACCESSOR.warnText()} set(values) {...") @@ -91,19 +91,19 @@ class PropertyAccessorFieldsWarnTest : LintTestBase(::PropertyAccessorFields) { | } | isEmpty = values | } - | + | | var isNotOk: Boolean = false | set(valuess) { | var isNotOk = true | isNotOk = valuess | } - | + | | var isOk: Boolean = false | set(valuess) { | isOk = valuess | var isOk = true | } - | + | | var isNotEmpty: Boolean = true | set(value) { | val q = isNotEmpty @@ -111,7 +111,7 @@ class PropertyAccessorFieldsWarnTest : LintTestBase(::PropertyAccessorFields) { | } | get() = field |} - """.trimMargin(), + """.trimMargin(), LintError(4, 4, ruleId, "${WRONG_NAME_OF_VARIABLE_INSIDE_ACCESSOR.warnText()} set(values) {..."), LintError(18, 4, ruleId, "${WRONG_NAME_OF_VARIABLE_INSIDE_ACCESSOR.warnText()} set(valuess) {..."), LintError(24, 4, ruleId, "${WRONG_NAME_OF_VARIABLE_INSIDE_ACCESSOR.warnText()} set(value) {...") @@ -127,11 +127,11 @@ class PropertyAccessorFieldsWarnTest : LintTestBase(::PropertyAccessorFields) { | | val blaBla: String | get() = "bla".blaBla("bla") - | + | | fun blaBla(string: String): String = this + string | |} - """.trimMargin() + """.trimMargin() ) } @@ -147,7 +147,7 @@ class PropertyAccessorFieldsWarnTest : LintTestBase(::PropertyAccessorFields) { | get() = foo | |} - """.trimMargin() + """.trimMargin() ) } } diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter6/StatelessClassesRuleWarnTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter6/StatelessClassesRuleWarnTest.kt index d4d5e13ffc..ca32b442ac 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter6/StatelessClassesRuleWarnTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter6/StatelessClassesRuleWarnTest.kt @@ -18,9 +18,9 @@ class StatelessClassesRuleWarnTest : LintTestBase(::StatelessClassesRule) { fun `should not trigger on class not extending any interface`() { lintMethod( """ - |class Some : I() { - | override fun some() - |} + |class Some : I() { + | override fun some() + |} """.trimMargin() ) } @@ -30,13 +30,13 @@ class StatelessClassesRuleWarnTest : LintTestBase(::StatelessClassesRule) { fun `should trigger on class extending interface`() { lintMethod( """ - |class Some : I { - | override fun some() - |} - | - |interface I { - | fun some() - |} + |class Some : I { + | override fun some() + |} + | + |interface I { + | fun some() + |} """.trimMargin(), LintError(1, 1, ruleId, "${Warnings.OBJECT_IS_PREFERRED.warnText()} class Some", true) ) @@ -47,10 +47,10 @@ class StatelessClassesRuleWarnTest : LintTestBase(::StatelessClassesRule) { fun `should not trigger on class with constructor`() { lintMethod( """ - |class Some(b: Int) : I { - | - | override fun some() - |} + |class Some(b: Int) : I { + | + | override fun some() + |} """.trimMargin() ) } @@ -60,10 +60,10 @@ class StatelessClassesRuleWarnTest : LintTestBase(::StatelessClassesRule) { fun `should not trigger on class with no interface in this file`() { lintMethod( """ - |class Some : I { - | - | override fun some() - |} + |class Some : I { + | + | override fun some() + |} """.trimMargin() ) } @@ -73,10 +73,10 @@ class StatelessClassesRuleWarnTest : LintTestBase(::StatelessClassesRule) { fun `should not trigger on class with state`() { lintMethod( """ - |class Some : I { - | val a = 5 - | override fun some() - |} + |class Some : I { + | val a = 5 + | override fun some() + |} """.trimMargin() ) } diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter6/TrivialPropertyAccessorsWarnTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter6/TrivialPropertyAccessorsWarnTest.kt index 816cdb1273..863467bbec 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter6/TrivialPropertyAccessorsWarnTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter6/TrivialPropertyAccessorsWarnTest.kt @@ -23,7 +23,7 @@ class TrivialPropertyAccessorsWarnTest : LintTestBase(::TrivialPropertyAccessors | get() { return field } | set(value) { field = value } |} - """.trimMargin(), + """.trimMargin(), LintError(3, 8, ruleId, "${Warnings.TRIVIAL_ACCESSORS_ARE_NOT_RECOMMENDED.warnText()} get() { return field }", true), LintError(4, 8, ruleId, "${Warnings.TRIVIAL_ACCESSORS_ARE_NOT_RECOMMENDED.warnText()} set(value) { field = value }", true) ) @@ -38,7 +38,7 @@ class TrivialPropertyAccessorsWarnTest : LintTestBase(::TrivialPropertyAccessors | val prop: Int = 0 | get() = field |} - """.trimMargin(), + """.trimMargin(), LintError(3, 8, ruleId, "${Warnings.TRIVIAL_ACCESSORS_ARE_NOT_RECOMMENDED.warnText()} get() = field", true) ) } @@ -50,16 +50,16 @@ class TrivialPropertyAccessorsWarnTest : LintTestBase(::TrivialPropertyAccessors """ |class Test { | val prop: Int = 0 - | get() { + | get() { | val b = someLogic(field) | return b | } - | set(value) { + | set(value) { | val res = func(value) | field = res | } |} - """.trimMargin() + """.trimMargin() ) } @@ -72,7 +72,7 @@ class TrivialPropertyAccessorsWarnTest : LintTestBase(::TrivialPropertyAccessors | var testName: String? = null | private set |} - """.trimMargin() + """.trimMargin() ) } @@ -85,7 +85,7 @@ class TrivialPropertyAccessorsWarnTest : LintTestBase(::TrivialPropertyAccessors | val testName = 0 | get |} - """.trimMargin(), + """.trimMargin(), LintError(3, 8, ruleId, "${Warnings.TRIVIAL_ACCESSORS_ARE_NOT_RECOMMENDED.warnText()} get", true) ) } diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter6/UseLastIndexWarnTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter6/UseLastIndexWarnTest.kt index 7325f9d889..875ccf1d13 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter6/UseLastIndexWarnTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter6/UseLastIndexWarnTest.kt @@ -21,7 +21,7 @@ class UseLastIndexWarnTest : LintTestBase(::UseLastIndex) { |val A = "AAAAAAAA" |val D = A.B.C.length - 1 | - """.trimMargin(), + """.trimMargin(), LintError(2, 9, ruleId, "${Warnings.USE_LAST_INDEX.warnText()} A.B.C.length - 1", true) ) } @@ -37,7 +37,7 @@ class UseLastIndexWarnTest : LintTestBase(::UseLastIndex) { | - | 1 |} - """.trimMargin() + """.trimMargin() ) } @@ -50,7 +50,7 @@ class UseLastIndexWarnTest : LintTestBase(::UseLastIndex) { |var B = A.length - 1 + 214 |var C = A.length - 19 | - """.trimMargin(), + """.trimMargin(), LintError(2, 12, ruleId, "${Warnings.USE_LAST_INDEX.warnText() } A.length - 1", true) ) } @@ -63,7 +63,7 @@ class UseLastIndexWarnTest : LintTestBase(::UseLastIndex) { |val A : String = "AAAA" |var B = A.length-1 | - """.trimMargin(), + """.trimMargin(), LintError(2, 9, ruleId, "${Warnings.USE_LAST_INDEX.warnText()} A.length-1", true) ) } @@ -78,7 +78,7 @@ class UseLastIndexWarnTest : LintTestBase(::UseLastIndex) { |val C = 6 + 121 |var D = B + C |var E = A.length + 1 - """.trimMargin() + """.trimMargin() ) } @@ -94,7 +94,7 @@ class UseLastIndexWarnTest : LintTestBase(::UseLastIndex) { | |val M = "ASDFG".length | - """.trimMargin(), + """.trimMargin(), LintError(4, 9, ruleId, "${Warnings.USE_LAST_INDEX.warnText()} \"AAAA\".length - 1", true) ) } diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter6/UselessSupertypeWarnTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter6/UselessSupertypeWarnTest.kt index 4b20a5383f..03e47e26f4 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter6/UselessSupertypeWarnTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter6/UselessSupertypeWarnTest.kt @@ -22,7 +22,7 @@ class UselessSupertypeWarnTest : LintTestBase(::UselessSupertype) { open class Rectangle { open fun draw() { /* ... */ } } - + class Square() : Rectangle() { override fun draw() { /** @@ -32,7 +32,7 @@ class UselessSupertypeWarnTest : LintTestBase(::UselessSupertype) { super.draw() } } - + class Square2() : Rectangle() { override fun draw() { //hehe @@ -42,19 +42,19 @@ class UselessSupertypeWarnTest : LintTestBase(::UselessSupertype) { super.draw() } } - + class Square2() : Rectangle() { override fun draw() { val q = super.draw() } } - + class A: Runnable { override fun run() { - + } } - """.trimMargin(), + """.trimMargin(), LintError(11, 35, ruleId, "${USELESS_SUPERTYPE.warnText()} Rectangle", true), LintError(21, 35, ruleId, "${USELESS_SUPERTYPE.warnText()} Rectangle", true) ) @@ -68,24 +68,24 @@ class UselessSupertypeWarnTest : LintTestBase(::UselessSupertype) { open class Rectangle { open fun draw() { /* ... */ } } - + interface KK { fun draw() {} fun kk() {} } - + class Square2() : Rectangle(), KK { override fun draw() { super.draw() super.draw() } - + private fun goo() { super.kk() } } - """.trimMargin(), + """.trimMargin(), LintError(17, 35, ruleId, "${USELESS_SUPERTYPE.warnText()} KK", true) ) } diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/utils/SuppressTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/utils/SuppressTest.kt index 3d3a8d73ae..349251d49e 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/utils/SuppressTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/utils/SuppressTest.kt @@ -35,18 +35,18 @@ class SuppressTest : LintTestBase(::IdentifierNaming) { | | @Suppress("FUNCTION_NAME_INCORRECT_CASE") | fun /* */ methODTREE(): String { - | + | | fun soMEMETHOD() { - | + | | } | | } - | + | | fun /* */ methODTREEASA(): String { | | } |} - """.trimMargin(), + """.trimMargin(), LintError(12, 14, ruleId, "${Warnings.FUNCTION_NAME_INCORRECT_CASE.warnText()} methODTREEASA", true) ) @@ -64,7 +64,7 @@ class SuppressTest : LintTestBase(::IdentifierNaming) { | var SOMEvar = 5 | } |} - """.trimMargin() + """.trimMargin() ) } @@ -103,7 +103,7 @@ class SuppressTest : LintTestBase(::IdentifierNaming) { class SomeClass() { @set:[Suppress("IDENTIFIER_LENGTH") Inject] val a = 5 - + fun /* */ method(): String { } @@ -124,7 +124,7 @@ class SuppressTest : LintTestBase(::IdentifierNaming) { | B, | ; |} - """.trimMargin() + """.trimMargin() ) } diff --git a/diktat-rules/src/test/resources/test/paragraph3/indentation/MultilionStringExpected.kt b/diktat-rules/src/test/resources/test/paragraph3/indentation/MultilionStringExpected.kt new file mode 100644 index 0000000000..d4007dd98c --- /dev/null +++ b/diktat-rules/src/test/resources/test/paragraph3/indentation/MultilionStringExpected.kt @@ -0,0 +1,46 @@ +package test.paragraph3.indentation + +//test of correct opening quotation mark and incorrect closing quotation mark +fun multilionString() { + lintMethod( + """ + |val q = 1 + | + """.trimMargin(), + fileName = "src/main/kotlin/org/cqfn/diktat/Example.kts" + ) +} + +//test of incorrect opening quotation mark and incorrect closing quotation mark1 +fun multilionString() { + lintMethod( + """ + |val q = 1 + | + """.trimMargin(), + fileName = "src/main/kotlin/org/cqfn/diktat/Example.kts" + ) +} + +//test of incorrect opening quotation mark and incorrect closing quotation mark2 +fun multilionString() { + lintMethod( + """ + |val q = 1 + | + """.trimMargin(), + fileName = "src/main/kotlin/org/cqfn/diktat/Example.kts" + ) +} + +//test of incorrect opening quotation mark and incorrect closing quotation mark with incorrect shift +fun multilionString() { + lintMethod( + """ + |val q = 1 + | + """.trimMargin(), + fileName = "src/main/kotlin/org/cqfn/diktat/Example.kts" + ) +} + diff --git a/diktat-rules/src/test/resources/test/paragraph3/indentation/MultilionStringTest.kt b/diktat-rules/src/test/resources/test/paragraph3/indentation/MultilionStringTest.kt new file mode 100644 index 0000000000..6274177be1 --- /dev/null +++ b/diktat-rules/src/test/resources/test/paragraph3/indentation/MultilionStringTest.kt @@ -0,0 +1,46 @@ +package test.paragraph3.indentation + +//test of correct opening quotation mark and incorrect closing quotation mark +fun multilionString() { + lintMethod( + """ + |val q = 1 + | + """.trimMargin(), + fileName = "src/main/kotlin/org/cqfn/diktat/Example.kts" + ) +} + +//test of incorrect opening quotation mark and incorrect closing quotation mark1 +fun multilionString() { + lintMethod( + """ + |val q = 1 + | + """.trimMargin(), + fileName = "src/main/kotlin/org/cqfn/diktat/Example.kts" + ) +} + +//test of incorrect opening quotation mark and incorrect closing quotation mark2 +fun multilionString() { + lintMethod( + """ + |val q = 1 + | + """.trimMargin(), + fileName = "src/main/kotlin/org/cqfn/diktat/Example.kts" + ) +} + +//test of incorrect opening quotation mark and incorrect closing quotation mark with incorrect shift +fun multilionString() { + lintMethod( + """ + |val q = 1 + | + """.trimMargin(), + fileName = "src/main/kotlin/org/cqfn/diktat/Example.kts" + ) +} +