Skip to content

Commit

Permalink
Fix assertion failed in rule [kdoc-formatting] #1489 (#1522)
Browse files Browse the repository at this point in the history
Assertion failed: anchorBefore == null || anchorBefore.getTreeParent() == parent in rule [kdoc-formatting] #1489

What's done:
- fix for KDOC_WRONG_TAGS_ORDER rule
- warning test "tags should be ordered assertion issue"
- fix test "extra new line with tags ordering should not cause assert"
  • Loading branch information
icemachined authored Sep 14, 2022
1 parent 95efc18 commit 52b4096
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ class KdocFormatting(configRules: List<RulesConfig>) : DiktatRule(
.first()
.node
.startOffset, basicTags.first().node) {
val kdocSection = node.getFirstChildWithType(KDOC_SECTION)!!
val basicTagChildren = kdocTags
.filter { basicTagsOrdered.contains(it.knownTag) }
.map { it.node }
Expand All @@ -229,6 +228,7 @@ class KdocFormatting(configRules: List<RulesConfig>) : DiktatRule(
.map { it.node }

basicTagChildren.mapIndexed { index, astNode ->
val kdocSection = astNode.treeParent
kdocSection.addChild(correctKdocOrder[index].clone() as CompositeElement, astNode)
kdocSection.removeChild(astNode)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ class KdocFormattingFixTest : FixTestBase("test/paragraph2/kdoc/", ::KdocFormatt
fixAndCompare("OrderedTagsExpected.kt", "OrderedTagsTest.kt")
}

@Test
@Tag(WarningNames.KDOC_WRONG_TAGS_ORDER)
fun `extra new line with tags ordering should not cause assert`() {
fixAndCompare("OrderedTagsAssertionExpected.kt", "OrderedTagsAssertionTest.kt")
}

@Test
@Tag(WarningNames.KDOC_NO_NEWLINES_BETWEEN_BASIC_TAGS)
fun `basic tags should not have empty lines between`() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,31 @@ class KdocFormattingTest : LintTestBase(::KdocFormatting) {
"${KDOC_WRONG_TAGS_ORDER.warnText()} @return, @throws, @param", true))
}

@Test
@Tag(WarningNames.KDOC_WRONG_TAGS_ORDER)
fun `tags should be ordered assertion issue`() {
val invalidCode = """
/**
* Reporter that produces a JSON report as a [Report]
*
* @property out a sink for output
*
* @param builder additional configuration lambda for serializers module
*/
class JsonReporter(
override val out: BufferedSink,
builder: PolymorphicModuleBuilder<Plugin.TestFiles>.() -> Unit = {}
) : Reporter
""".trimIndent()

lintMethod(invalidCode,
LintError(4, 4, ruleId,
"${KDOC_NO_NEWLINES_BETWEEN_BASIC_TAGS.warnText()} @property", true),
LintError(4, 4, ruleId,
"${KDOC_WRONG_TAGS_ORDER.warnText()} @property, @param", true)
)
}

@Test
@Tag(WarningNames.KDOC_NO_NEWLINES_BETWEEN_BASIC_TAGS)
fun `newlines are not allowed between basic tags`() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.saveourtool.save.reporter.json

/**
* Reporter that produces a JSON report as a [Report]
*
* @param builder additional configuration lambda for serializers module
* @property out a sink for output
*/
class JsonReporter(
override val out: BufferedSink,
builder: PolymorphicModuleBuilder<Plugin.TestFiles>.() -> Unit = {}
) : Reporter
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.saveourtool.save.reporter.json

/**
* Reporter that produces a JSON report as a [Report]
*
* @property out a sink for output
*
* @param builder additional configuration lambda for serializers module
*/
class JsonReporter(
override val out: BufferedSink,
builder: PolymorphicModuleBuilder<Plugin.TestFiles>.() -> Unit = {}
) : Reporter

0 comments on commit 52b4096

Please sign in to comment.