Skip to content

Commit

Permalink
OutdatedDocumentation - Detect param which private property documente…
Browse files Browse the repository at this point in the history
…d as property (#6372)

* Detect param which private property documented as property

* Use not of private instead of public
  • Loading branch information
atulgpt authored and cortinico committed Oct 29, 2023
1 parent c921492 commit 0b25543
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ class OutdatedDocumentation(config: Config = Config.empty) : Rule(config) {
private fun getDeclarationsForValueParameters(valueParameters: List<KtParameter>): List<Declaration> {
return valueParameters.mapNotNull {
it.name?.let { name ->
val type = if (it.isPropertyParameter()) {
val type = if (it.isPropertyParameter() && it.isPrivate().not()) {
if (allowParamOnConstructorProperties) {
DeclarationType.ANY
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,50 @@ class OutdatedDocumentationSpec {
""".trimIndent()
assertThat(subject.compileAndLint(incorrectDeclarationsOrder)).hasSize(1)
}

@Test
fun `should report when param which is private property is documented as property`() {
val code = """
/**
* Doc
* @property a desc
*/
class A(
private val a: String,
)
""".trimIndent()
assertThat(subject.compileAndLint(code)).hasSize(1)
}

@Test
fun `should not report internal or protected property is documented`() {
val code = """
/**
* Doc
* @property a desc
* @property b desc
*/
open class A(
internal val a: String,
protected val b: String,
)
""".trimIndent()
assertThat(subject.compileAndLint(code)).isEmpty()
}

@Test
fun `should not report when param which is private property is documented as param`() {
val code = """
/**
* Doc
* @param a desc
*/
class A(
private val a: String,
)
""".trimIndent()
assertThat(subject.compileAndLint(code)).isEmpty()
}
}

@Nested
Expand Down Expand Up @@ -450,7 +494,8 @@ class OutdatedDocumentationSpec {

@Nested
inner class `configuration matchTypeParameters` {
private val configuredSubject = OutdatedDocumentation(TestConfig("matchTypeParameters" to "false"))
private val configuredSubject =
OutdatedDocumentation(TestConfig("matchTypeParameters" to "false"))

@Test
fun `should not report when class type parameters mismatch and configuration is off`() {
Expand All @@ -477,7 +522,8 @@ class OutdatedDocumentationSpec {

@Nested
inner class `configuration matchDeclarationsOrder` {
private val configuredSubject = OutdatedDocumentation(TestConfig("matchDeclarationsOrder" to "false"))
private val configuredSubject =
OutdatedDocumentation(TestConfig("matchDeclarationsOrder" to "false"))

@Test
fun `should not report when declarations order mismatch and configuration is off`() {
Expand Down Expand Up @@ -524,6 +570,18 @@ class OutdatedDocumentationSpec {
assertThat(configuredSubject.compileAndLint(propertyAsParam)).isEmpty()
}

@Test
fun `should not report when internal or protected property is documented as param`() {
val propertyAsParam = """
/**
* @param a Description of param
* @param b Description of property
*/
open class MyClass(internal val a: String, protected val b: String)
""".trimIndent()
assertThat(configuredSubject.compileAndLint(propertyAsParam)).isEmpty()
}

@Test
fun `should not report when property is documented as property`() {
val propertyAsParam = """
Expand Down Expand Up @@ -569,5 +627,19 @@ class OutdatedDocumentationSpec {
""".trimIndent()
assertThat(configuredSubject.compileAndLint(propertyAsParam)).isEmpty()
}

@Test
fun `should report when param which is private property is documented as property`() {
val code = """
/**
* Doc
* @property a desc
*/
class A(
private val a: String,
)
""".trimIndent()
assertThat(subject.compileAndLint(code)).hasSize(1)
}
}
}

0 comments on commit 0b25543

Please sign in to comment.