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

Remove dependencies on discouraged-comment-location rule #2371

Merged
merged 7 commits into from
Nov 22, 2023
Prev Previous commit
Next Next commit
Add missing tests
  • Loading branch information
paul-dingemans committed Nov 21, 2023
commit e6900276db0ae9406fb551a12fad90b5d55f06e7
Original file line number Diff line number Diff line change
@@ -133,7 +133,7 @@ public class DiscouragedCommentLocationRule : StandardRule("discouraged-comment-
} else {
emit(
node.startOffset,
"A KDoc is not allowed on a '${node.treeParentElementTypeName()}",
"A KDoc is not allowed inside a '${node.treeParentElementTypeName()}'",
false,
)
}
Original file line number Diff line number Diff line change
@@ -606,6 +606,39 @@ class DiscouragedCommentLocationRuleTest {

@Nested
inner class `Given a type parameter list ast node` {
@Test
fun `Given a kdoc inside a type parameter`() {
val code =
"""
class Foo<in /** some comment */ Bar>
""".trimIndent()
discouragedCommentLocationRuleAssertThat(code)
.hasLintViolationWithoutAutoCorrect(1, 14, "A KDoc is not allowed inside a 'type_parameter'")
}

@Test
fun `Given a block comment inside a type parameter`() {
val code =
"""
class Foo<in /* some comment */ Bar>
""".trimIndent()
@Suppress("ktlint:standard:argument-list-wrapping", "ktlint:standard:max-line-length")
discouragedCommentLocationRuleAssertThat(code)
.hasLintViolationWithoutAutoCorrect(1, 14, "A (block or EOL) comment inside or on same line after a 'type_parameter' is not allowed. It may be placed on a separate line above.")
}

@Test
fun `Given an EOL comment inside a type parameter`() {
val code =
"""
class Foo<in // some comment
Bar>
""".trimIndent()
@Suppress("ktlint:standard:argument-list-wrapping", "ktlint:standard:max-line-length")
discouragedCommentLocationRuleAssertThat(code)
.hasLintViolationWithoutAutoCorrect(1, 14, "A (block or EOL) comment inside or on same line after a 'type_parameter' is not allowed. It may be placed on a separate line above.")
}

@Test
fun `Given a kdoc as child of type parameter list`() {
val code =
@@ -683,6 +716,39 @@ class DiscouragedCommentLocationRuleTest {

@Nested
inner class `Given a type argument list ast node` {
@Test
fun `Given a kdoc inside a type projection`() {
val code =
"""
fun Foo<out /** some comment */ Any>.foo() {}
""".trimIndent()
discouragedCommentLocationRuleAssertThat(code)
.hasLintViolationWithoutAutoCorrect(1, 13, "A KDoc is not allowed inside a 'type_projection'")
}

@Test
fun `Given a block comment inside a type projection`() {
val code =
"""
fun Foo<out /* some comment */ Any>.foo() {}
""".trimIndent()
@Suppress("ktlint:standard:argument-list-wrapping", "ktlint:standard:max-line-length")
discouragedCommentLocationRuleAssertThat(code)
.hasLintViolationWithoutAutoCorrect(1, 13, "A (block or EOL) comment inside or on same line after a 'type_projection' is not allowed. It may be placed on a separate line above.")
}

@Test
fun `Given a EOL comment inside type projection`() {
val code =
"""
fun Foo<out // some comment
Any>.foo() {}
""".trimIndent()
@Suppress("ktlint:standard:argument-list-wrapping", "ktlint:standard:max-line-length")
discouragedCommentLocationRuleAssertThat(code)
.hasLintViolationWithoutAutoCorrect(1, 13, "A (block or EOL) comment inside or on same line after a 'type_projection' is not allowed. It may be placed on a separate line above.")
}

@Test
fun `Given a kdoc as child of type argument list`() {
val code =