Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix EndOfSentenceFormat highlight #5311

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -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."
)
)
Expand Down
@@ -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
Expand Down Expand Up @@ -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)
}
}
}
Expand Up @@ -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 = """
Expand Down