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

OutdatedDocumentation - Detect param which private property documented as property #6372

Merged
merged 2 commits into from
Aug 13, 2023
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
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)
}
}
}