From 01ca0156a64407295068319a10e8e5af87045ca2 Mon Sep 17 00:00:00 2001 From: aktsay6 Date: Tue, 17 Nov 2020 10:50:56 +0300 Subject: [PATCH 1/4] bugfix/false-positive-local-variable-early-declaration(#488) ### What's done: * Fixed bugs --- .../ruleset/chapter3/LocalVariablesWarnTest.kt | 15 +++++++++++++++ .../resources/test/funcTest/FunctionalTestFile.kt | 12 +++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) 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 9de6f71e15..d4ab378f5c 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 @@ -549,4 +549,19 @@ class LocalVariablesWarnTest : LintTestBase(::LocalVariablesRule) { """.trimMargin() ) } + + @Test + @Tag(WarningNames.LOCAL_VARIABLE_EARLY_DECLARATION) + fun `should not trigger on triple quoted strings`() { + lintMethod( + """ + |class Example { + | fun some() { + | val code = ${"\"\"\" class Some {\n \t\t fun for() {} \n \t} \"\"\".trimIndent()"} + | bar(code) + | } + |} + """.trimMargin() + ) + } } diff --git a/diktat-rules/src/test/resources/test/funcTest/FunctionalTestFile.kt b/diktat-rules/src/test/resources/test/funcTest/FunctionalTestFile.kt index 85168cfe7d..e087033398 100644 --- a/diktat-rules/src/test/resources/test/funcTest/FunctionalTestFile.kt +++ b/diktat-rules/src/test/resources/test/funcTest/FunctionalTestFile.kt @@ -2,4 +2,14 @@ package test.funcTest class FunctionalTestFile { val AAAA = 5 -} + + fun `method name incorrect, part 4`() { + val code = """ + class TestPackageName { + fun methODTREE(): String { + } + } + """.trimIndent() + lintMethod(code, LintError(2, 7, ruleId, "${FUNCTION_NAME_INCORRECT_CASE.warnText()} methODTREE", true)) + } +} \ No newline at end of file From 54ad467de1b5dd005c177e7d1a5518f9012f3cc6 Mon Sep 17 00:00:00 2001 From: aktsay6 Date: Tue, 17 Nov 2020 11:06:26 +0300 Subject: [PATCH 2/4] bugfix/false-positive-local-variable-early-declaration(#488) ### What's done: * Fixed bugs --- .../test/resources/test/funcTest/FunctionalTestFile.kt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/diktat-rules/src/test/resources/test/funcTest/FunctionalTestFile.kt b/diktat-rules/src/test/resources/test/funcTest/FunctionalTestFile.kt index e087033398..4dc9b73226 100644 --- a/diktat-rules/src/test/resources/test/funcTest/FunctionalTestFile.kt +++ b/diktat-rules/src/test/resources/test/funcTest/FunctionalTestFile.kt @@ -2,14 +2,14 @@ package test.funcTest class FunctionalTestFile { val AAAA = 5 +} - fun `method name incorrect, part 4`() { - val code = """ +fun `method name incorrect, part 4`() { + val code = """ class TestPackageName { fun methODTREE(): String { } } """.trimIndent() - lintMethod(code, LintError(2, 7, ruleId, "${FUNCTION_NAME_INCORRECT_CASE.warnText()} methODTREE", true)) - } -} \ No newline at end of file + lintMethod(code, LintError(2, 7, ruleId, "${FUNCTION_NAME_INCORRECT_CASE.warnText()} methODTREE", true)) +} From d91a48c9bef7202bac456630b6f9a5fe81f4a1f6 Mon Sep 17 00:00:00 2001 From: soWhoAmI Date: Thu, 19 Nov 2020 14:37:30 +0300 Subject: [PATCH 3/4] bugfix/false-positive-local-variable-early-declaration(#488) ### What's done: * Fixed bugs --- .../ruleset/chapter3/LocalVariablesWarnTest.kt | 7 ++++++- .../org/cqfn/diktat/ruleset/smoke/DiktatSmokeTest.kt | 6 ++++++ .../resources/test/funcTest/FunctionalTestFile.kt | 10 ---------- .../test/smoke/src/main/kotlin/Example4Expected.kt | 12 ++++++++++++ .../test/smoke/src/main/kotlin/Example4Test.kt | 12 ++++++++++++ 5 files changed, 36 insertions(+), 11 deletions(-) create mode 100644 diktat-rules/src/test/resources/test/smoke/src/main/kotlin/Example4Expected.kt create mode 100644 diktat-rules/src/test/resources/test/smoke/src/main/kotlin/Example4Test.kt diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/LocalVariablesWarnTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/LocalVariablesWarnTest.kt index d4ab378f5c..0d1409f3db 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 @@ -553,11 +553,16 @@ class LocalVariablesWarnTest : LintTestBase(::LocalVariablesRule) { @Test @Tag(WarningNames.LOCAL_VARIABLE_EARLY_DECLARATION) fun `should not trigger on triple quoted strings`() { + val spacesForClassIndent = " ".repeat(18) + val spacesForFunIndent = " ".repeat(20) + val spacesForEndIndent = " ".repeat(16) lintMethod( """ |class Example { | fun some() { - | val code = ${"\"\"\" class Some {\n \t\t fun for() {} \n \t} \"\"\".trimIndent()"} + | val code = ${"\"\"\" \n${spacesForClassIndent}class Some {" + + "\n${spacesForFunIndent}fun for() : String {\n${spacesForFunIndent}} " + + "\n ${spacesForClassIndent}}${spacesForEndIndent}\"\"\".trimIndent()"} | bar(code) | } |} diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/smoke/DiktatSmokeTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/smoke/DiktatSmokeTest.kt index 55621ea418..c2f8da2a59 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/smoke/DiktatSmokeTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/smoke/DiktatSmokeTest.kt @@ -95,6 +95,12 @@ class DiktatSmokeTest : FixTestBase("test/smoke/src/main/kotlin", fixAndCompare("Example3Expected.kt", "Example3Test.kt") } + @Test + @Tag("DiktatRuleSetProvider") + fun `smoke test #4`() { + fixAndCompare("Example4Expected.kt", "Example4Test.kt") + } + @Test @Tag("DiktatRuleSetProvider") fun `regression - should not fail if package is not set`() { diff --git a/diktat-rules/src/test/resources/test/funcTest/FunctionalTestFile.kt b/diktat-rules/src/test/resources/test/funcTest/FunctionalTestFile.kt index 4dc9b73226..85168cfe7d 100644 --- a/diktat-rules/src/test/resources/test/funcTest/FunctionalTestFile.kt +++ b/diktat-rules/src/test/resources/test/funcTest/FunctionalTestFile.kt @@ -3,13 +3,3 @@ package test.funcTest class FunctionalTestFile { val AAAA = 5 } - -fun `method name incorrect, part 4`() { - val code = """ - class TestPackageName { - fun methODTREE(): String { - } - } - """.trimIndent() - lintMethod(code, LintError(2, 7, ruleId, "${FUNCTION_NAME_INCORRECT_CASE.warnText()} methODTREE", true)) -} diff --git a/diktat-rules/src/test/resources/test/smoke/src/main/kotlin/Example4Expected.kt b/diktat-rules/src/test/resources/test/smoke/src/main/kotlin/Example4Expected.kt new file mode 100644 index 0000000000..64f574f938 --- /dev/null +++ b/diktat-rules/src/test/resources/test/smoke/src/main/kotlin/Example4Expected.kt @@ -0,0 +1,12 @@ +package org.cqfn.diktat + +fun `method name incorrect, part 4`() { + val code = """ + class TestPackageName { + fun methODTREE(): String { + } + } + """.trimIndent() + lintMethod(code, LintError(2, 7, ruleId, "${FUNCTION_NAME_INCORRECT_CASE.warnText()} methODTREE", true)) +} + diff --git a/diktat-rules/src/test/resources/test/smoke/src/main/kotlin/Example4Test.kt b/diktat-rules/src/test/resources/test/smoke/src/main/kotlin/Example4Test.kt new file mode 100644 index 0000000000..64f574f938 --- /dev/null +++ b/diktat-rules/src/test/resources/test/smoke/src/main/kotlin/Example4Test.kt @@ -0,0 +1,12 @@ +package org.cqfn.diktat + +fun `method name incorrect, part 4`() { + val code = """ + class TestPackageName { + fun methODTREE(): String { + } + } + """.trimIndent() + lintMethod(code, LintError(2, 7, ruleId, "${FUNCTION_NAME_INCORRECT_CASE.warnText()} methODTREE", true)) +} + From 18e5550fb0bd81c2dfd0cb4ed12e4d9fc45e49e3 Mon Sep 17 00:00:00 2001 From: soWhoAmI Date: Mon, 23 Nov 2020 16:28:13 +0300 Subject: [PATCH 4/4] bugfix/false-positive-local-variable-early-declaration(#488) ### What's done: * Fixed bugs --- .../ruleset/chapter3/LocalVariablesWarnTest.kt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) 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 0d1409f3db..2b9d8a6136 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 @@ -553,16 +553,16 @@ class LocalVariablesWarnTest : LintTestBase(::LocalVariablesRule) { @Test @Tag(WarningNames.LOCAL_VARIABLE_EARLY_DECLARATION) fun `should not trigger on triple quoted strings`() { - val spacesForClassIndent = " ".repeat(18) - val spacesForFunIndent = " ".repeat(20) - val spacesForEndIndent = " ".repeat(16) lintMethod( """ |class Example { | fun some() { - | val code = ${"\"\"\" \n${spacesForClassIndent}class Some {" + - "\n${spacesForFunIndent}fun for() : String {\n${spacesForFunIndent}} " + - "\n ${spacesForClassIndent}}${spacesForEndIndent}\"\"\".trimIndent()"} + | val code = ${"\"\"\""} + | class Some { + | fun for() : String { + | } + | } + | ${"\"\"\""}.trimIndent() | bar(code) | } |}