From 9ca40d4a2b3e166c81cad7ff9c4fa4486b5e2d04 Mon Sep 17 00:00:00 2001 From: Dmitry Morozovsky <27895587+icemachined@users.noreply.github.com> Date: Tue, 13 Sep 2022 18:29:08 +0300 Subject: [PATCH 1/2] fix for #1489 --- .../ruleset/rules/chapter2/kdoc/KdocFormatting.kt | 2 +- .../diktat/ruleset/chapter2/KdocFormattingFixTest.kt | 6 ++++++ .../paragraph2/kdoc/OrderedTagsAssertionExpected.kt | 12 ++++++++++++ .../test/paragraph2/kdoc/OrderedTagsAssertionTest.kt | 12 ++++++++++++ 4 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 diktat-rules/src/test/resources/test/paragraph2/kdoc/OrderedTagsAssertionExpected.kt create mode 100644 diktat-rules/src/test/resources/test/paragraph2/kdoc/OrderedTagsAssertionTest.kt 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 9ac53e2c6e..1f62607e9b 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 @@ -229,7 +229,7 @@ class KdocFormatting(configRules: List) : DiktatRule( .map { it.node } basicTagChildren.mapIndexed { index, astNode -> - kdocSection.addChild(correctKdocOrder[index].clone() as CompositeElement, astNode) + kdocSection.treeParent.addChild(correctKdocOrder[index].clone() as CompositeElement, astNode.treeNext) kdocSection.removeChild(astNode) } } diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter2/KdocFormattingFixTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter2/KdocFormattingFixTest.kt index 9c7e6a15f0..8dc34df986 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter2/KdocFormattingFixTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter2/KdocFormattingFixTest.kt @@ -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`() { diff --git a/diktat-rules/src/test/resources/test/paragraph2/kdoc/OrderedTagsAssertionExpected.kt b/diktat-rules/src/test/resources/test/paragraph2/kdoc/OrderedTagsAssertionExpected.kt new file mode 100644 index 0000000000..fe4d7db474 --- /dev/null +++ b/diktat-rules/src/test/resources/test/paragraph2/kdoc/OrderedTagsAssertionExpected.kt @@ -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.() -> Unit = {} +) : Reporter \ No newline at end of file diff --git a/diktat-rules/src/test/resources/test/paragraph2/kdoc/OrderedTagsAssertionTest.kt b/diktat-rules/src/test/resources/test/paragraph2/kdoc/OrderedTagsAssertionTest.kt new file mode 100644 index 0000000000..1f03d234d6 --- /dev/null +++ b/diktat-rules/src/test/resources/test/paragraph2/kdoc/OrderedTagsAssertionTest.kt @@ -0,0 +1,12 @@ +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 From 391e26c10c9ef211f1dffd7220a77a7ee3fd3eea Mon Sep 17 00:00:00 2001 From: Dmitry Morozovsky <27895587+icemachined@users.noreply.github.com> Date: Wed, 14 Sep 2022 15:04:27 +0300 Subject: [PATCH 2/2] fix for #1489 --- .../rules/chapter2/kdoc/KdocFormatting.kt | 4 +-- .../ruleset/chapter2/KdocFormattingTest.kt | 25 +++++++++++++++++++ .../kdoc/OrderedTagsAssertionTest.kt | 3 ++- 3 files changed, 29 insertions(+), 3 deletions(-) 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