From 051a1656dd10a2a56d2462e1630c7512540478ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=B3bert=20Papp=20=28TWiStErRob=29?= Date: Sun, 18 Sep 2022 17:28:14 +0100 Subject: [PATCH 1/3] Reference bugfix like other inner classes --- .../arturbosch/detekt/rules/style/UnusedPrivateMemberSpec.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/detekt-rules-style/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/style/UnusedPrivateMemberSpec.kt b/detekt-rules-style/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/style/UnusedPrivateMemberSpec.kt index fec8431b2d9..62812d70225 100644 --- a/detekt-rules-style/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/style/UnusedPrivateMemberSpec.kt +++ b/detekt-rules-style/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/style/UnusedPrivateMemberSpec.kt @@ -1606,7 +1606,7 @@ class UnusedPrivateMemberSpec(val env: KotlinCoreEnvironment) { } @Nested - inner class `highlights declaration name` { + inner class `highlights declaration name - #4916` { @Test fun function() { val code = """ From be620caa9925b6fc7bf7e10c6fcdad8733fb687c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=B3bert=20Papp=20=28TWiStErRob=29?= Date: Sun, 18 Sep 2022 17:28:40 +0100 Subject: [PATCH 2/3] EndOfSentenceFormatSpec: add invalid expectation (it highlights everything) --- .../documentation/EndOfSentenceFormatSpec.kt | 51 ++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/detekt-rules-documentation/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/documentation/EndOfSentenceFormatSpec.kt b/detekt-rules-documentation/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/documentation/EndOfSentenceFormatSpec.kt index 9bd93405884..2c385ff46d1 100644 --- a/detekt-rules-documentation/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/documentation/EndOfSentenceFormatSpec.kt +++ b/detekt-rules-documentation/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/documentation/EndOfSentenceFormatSpec.kt @@ -1,10 +1,12 @@ package io.gitlab.arturbosch.detekt.rules.documentation +import io.gitlab.arturbosch.detekt.test.assertThat import io.gitlab.arturbosch.detekt.test.compileAndLint -import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Nested import org.junit.jupiter.api.Test class EndOfSentenceFormatSpec { + val subject = EndOfSentenceFormat() @Test @@ -202,4 +204,51 @@ class EndOfSentenceFormatSpec { """.trimIndent() assertThat(subject.compileAndLint(code)).isEmpty() } + + @Nested + inner class `highlights whole element` { + + @Test + fun function() { + val code = """ + /** + * This sentence is correct invalid + * + * This sentence doesn't matter */ + fun test() = 3 + """.trimIndent() + assertThat(subject.compileAndLint(code)).hasSize(1) + .hasStartSourceLocation(1, 1) + .hasEndSourceLocation(5, 15) + } + + @Test + fun property() { + val code = """ + class Test { + /** This sentence is correct invalid + This sentence doesn't matter */ + val test = 3 + } + """.trimIndent() + assertThat(subject.compileAndLint(code)).hasSize(1) + .hasStartSourceLocation(2, 5) + .hasEndSourceLocation(4, 17) + } + + @Test + fun `class`() { + val code = """ + /** + * This sentence is correct invalid + * + * This sentence doesn't matter + */ + class Test + """.trimIndent() + assertThat(subject.compileAndLint(code)).hasSize(1) + .hasStartSourceLocation(1, 1) + .hasEndSourceLocation(6, 11) + } + } } From 423cfd6f7a4033744bbd0cad4de36351c6da9b28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=B3bert=20Papp=20=28TWiStErRob=29?= Date: Sun, 18 Sep 2022 17:39:49 +0100 Subject: [PATCH 3/3] EndOfSentenceFormat: change the expectation to highlight only relevant part, and fix code. --- .../documentation/EndOfSentenceFormat.kt | 2 +- .../documentation/EndOfSentenceFormatSpec.kt | 20 +++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/detekt-rules-documentation/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/documentation/EndOfSentenceFormat.kt b/detekt-rules-documentation/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/documentation/EndOfSentenceFormat.kt index 30b9fdcb271..3604ce9929e 100644 --- a/detekt-rules-documentation/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/documentation/EndOfSentenceFormat.kt +++ b/detekt-rules-documentation/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/documentation/EndOfSentenceFormat.kt @@ -42,7 +42,7 @@ class EndOfSentenceFormat(config: Config = Config.empty) : Rule(config) { report( CodeSmell( issue, - Entity.from(dcl), + Entity.from(it.getDefaultSection()), "The first sentence of this KDoc does not end with the correct punctuation." ) ) diff --git a/detekt-rules-documentation/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/documentation/EndOfSentenceFormatSpec.kt b/detekt-rules-documentation/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/documentation/EndOfSentenceFormatSpec.kt index 2c385ff46d1..93af53cd23e 100644 --- a/detekt-rules-documentation/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/documentation/EndOfSentenceFormatSpec.kt +++ b/detekt-rules-documentation/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/documentation/EndOfSentenceFormatSpec.kt @@ -206,7 +206,7 @@ class EndOfSentenceFormatSpec { } @Nested - inner class `highlights whole element` { + inner class `highlights only the relevant part of the comment - #5310` { @Test fun function() { @@ -214,12 +214,12 @@ class EndOfSentenceFormatSpec { /** * This sentence is correct invalid * - * This sentence doesn't matter */ + * This sentence counts too, because it doesn't know where the other ends */ fun test() = 3 """.trimIndent() assertThat(subject.compileAndLint(code)).hasSize(1) - .hasStartSourceLocation(1, 1) - .hasEndSourceLocation(5, 15) + .hasStartSourceLocation(2, 2) + .hasEndSourceLocation(4, 75) } @Test @@ -227,13 +227,13 @@ class EndOfSentenceFormatSpec { val code = """ class Test { /** This sentence is correct invalid - This sentence doesn't matter */ + This sentence counts too, because it doesn't know where the other ends */ val test = 3 } """.trimIndent() assertThat(subject.compileAndLint(code)).hasSize(1) - .hasStartSourceLocation(2, 5) - .hasEndSourceLocation(4, 17) + .hasStartSourceLocation(2, 8) + .hasEndSourceLocation(3, 80) } @Test @@ -242,13 +242,13 @@ class EndOfSentenceFormatSpec { /** * This sentence is correct invalid * - * This sentence doesn't matter + * This sentence counts too, because it doesn't know where the other ends */ class Test """.trimIndent() assertThat(subject.compileAndLint(code)).hasSize(1) - .hasStartSourceLocation(1, 1) - .hasEndSourceLocation(6, 11) + .hasStartSourceLocation(2, 2) + .hasEndSourceLocation(4, 74) } } }