diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/kdoc/KdocFormatting.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/kdoc/KdocFormatting.kt index 1f62607e9b..a857a59ef4 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/kdoc/KdocFormatting.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter2/kdoc/KdocFormatting.kt @@ -219,7 +219,6 @@ class KdocFormatting(configRules: List) : DiktatRule( .first() .node .startOffset, basicTags.first().node) { - val kdocSection = node.getFirstChildWithType(KDOC_SECTION)!! val basicTagChildren = kdocTags .filter { basicTagsOrdered.contains(it.knownTag) } .map { it.node } @@ -229,7 +228,8 @@ class KdocFormatting(configRules: List) : DiktatRule( .map { it.node } basicTagChildren.mapIndexed { index, astNode -> - kdocSection.treeParent.addChild(correctKdocOrder[index].clone() as CompositeElement, astNode.treeNext) + val kdocSection = astNode.treeParent + kdocSection.addChild(correctKdocOrder[index].clone() as CompositeElement, astNode) kdocSection.removeChild(astNode) } } diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter2/KdocFormattingTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter2/KdocFormattingTest.kt index 4d29b705b9..9779a3c7b9 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter2/KdocFormattingTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter2/KdocFormattingTest.kt @@ -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.() -> 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`() { diff --git a/diktat-rules/src/test/resources/test/paragraph2/kdoc/OrderedTagsAssertionTest.kt b/diktat-rules/src/test/resources/test/paragraph2/kdoc/OrderedTagsAssertionTest.kt index 1f03d234d6..d0e8e9ef2d 100644 --- a/diktat-rules/src/test/resources/test/paragraph2/kdoc/OrderedTagsAssertionTest.kt +++ b/diktat-rules/src/test/resources/test/paragraph2/kdoc/OrderedTagsAssertionTest.kt @@ -4,9 +4,10 @@ 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.() -> Unit = {} -) : Reporter \ No newline at end of file +) : Reporter