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 9bd93405884..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 @@ -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 only the relevant part of the comment - #5310` { + + @Test + fun function() { + val code = """ + /** + * This sentence is correct invalid + * + * This sentence counts too, because it doesn't know where the other ends */ + fun test() = 3 + """.trimIndent() + assertThat(subject.compileAndLint(code)).hasSize(1) + .hasStartSourceLocation(2, 2) + .hasEndSourceLocation(4, 75) + } + + @Test + fun property() { + val code = """ + class Test { + /** This sentence is correct invalid + 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, 8) + .hasEndSourceLocation(3, 80) + } + + @Test + fun `class`() { + val code = """ + /** + * This sentence is correct invalid + * + * This sentence counts too, because it doesn't know where the other ends + */ + class Test + """.trimIndent() + assertThat(subject.compileAndLint(code)).hasSize(1) + .hasStartSourceLocation(2, 2) + .hasEndSourceLocation(4, 74) + } + } } 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 = """