Skip to content

Commit

Permalink
Fix EndOfSentenceFormat highlight (#5311)
Browse files Browse the repository at this point in the history
* Reference bugfix like other inner classes

* EndOfSentenceFormatSpec: add invalid expectation (it highlights everything)

* EndOfSentenceFormat: change the expectation to highlight only relevant part, and fix code.
  • Loading branch information
TWiStErRob committed Sep 18, 2022
1 parent 51ed85a commit 783a623
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 3 deletions.
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

0 comments on commit 783a623

Please sign in to comment.