diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/kdoc/KdocFormatting.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/kdoc/KdocFormatting.kt index 1cbf3bd793..77e036eb4d 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/kdoc/KdocFormatting.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/kdoc/KdocFormatting.kt @@ -76,8 +76,6 @@ class KdocFormatting(private val configRules: List) : Rule("kdoc-fo emitWarn = emit fileName = node.getRootNode().getFileName() - val declarationTypes = setOf(CLASS, FUN, PROPERTY) - if (node.elementType == KDOC && isKdocNotEmpty(node)) { checkNoDeprecatedTag(node) checkEmptyTags(node.kDocTags()) @@ -278,7 +276,7 @@ class KdocFormatting(private val configRules: List) : Rule("kdoc-fo } } - @Suppress("UnsafeCallOnNullableType", "TOO_LONG_FUNCTION") + @Suppress("UnsafeCallOnNullableType", "TOO_LONG_FUNCTION", "ComplexMethod") private fun checkNewLineAfterSpecialTags(node: ASTNode) { val presentSpecialTagNodes = node .getFirstChildWithType(KDOC_SECTION) @@ -304,13 +302,13 @@ class KdocFormatting(private val configRules: List) : Rule("kdoc-fo node.removeChild(node.lastChildNode) // KDOC_LEADING_ASTERISK node.removeChild(node.lastChildNode) // WHITE_SPACE } - if (node.lastChildNode.elementType != KDOC_LEADING_ASTERISK) { + if (node.treeParent.lastChildNode != node && node.lastChildNode.elementType != KDOC_LEADING_ASTERISK) { val indent = node .prevSibling { it.elementType == WHITE_SPACE } ?.text ?.substringAfter('\n') ?.count { it == ' ' } ?: 0 - node.addChild(LeafPsiElement(WHITE_SPACE, "\n${" ".repeat(indent)}"), null) + node.addChild(PsiWhiteSpaceImpl("\n${" ".repeat(indent)}"), null) node.addChild(LeafPsiElement(KDOC_LEADING_ASTERISK, "*"), null) } } diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/smoke/DiktatSmokeTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/smoke/DiktatSmokeTest.kt index 2dceac75a0..3f85f87cb3 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/smoke/DiktatSmokeTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/smoke/DiktatSmokeTest.kt @@ -96,6 +96,12 @@ class DiktatSmokeTest : FixTestBase("test/smoke/src/main/kotlin", fixAndCompare("Example3Expected.kt", "Example3Test.kt") } + @Test + @Tag("DiktatRuleSetProvider") + fun `smoke test #4`() { + fixAndCompare("Example4Expected.kt", "Example4Test.kt") + } + @Test @Tag("DiktatRuleSetProvider") fun `regression - should not fail if package is not set`() { diff --git a/diktat-rules/src/test/resources/test/paragraph2/kdoc/KdocFormattingFullExpected.kt b/diktat-rules/src/test/resources/test/paragraph2/kdoc/KdocFormattingFullExpected.kt index 54b5583235..aa36ac1821 100644 --- a/diktat-rules/src/test/resources/test/paragraph2/kdoc/KdocFormattingFullExpected.kt +++ b/diktat-rules/src/test/resources/test/paragraph2/kdoc/KdocFormattingFullExpected.kt @@ -17,3 +17,10 @@ class Example { @Deprecated(message = "Use testNew") fun test(a: Int): Int = 2 * a } + +class Foo { + /** + * @implNote lorem ipsum + */ + private fun foo() {} +} diff --git a/diktat-rules/src/test/resources/test/paragraph2/kdoc/KdocFormattingFullTest.kt b/diktat-rules/src/test/resources/test/paragraph2/kdoc/KdocFormattingFullTest.kt index 78ffb4bdcc..daaa408802 100644 --- a/diktat-rules/src/test/resources/test/paragraph2/kdoc/KdocFormattingFullTest.kt +++ b/diktat-rules/src/test/resources/test/paragraph2/kdoc/KdocFormattingFullTest.kt @@ -17,3 +17,10 @@ class Example { */ fun test(a: Int): Int = 2 * a } + +class Foo { + /** + * @implNote lorem ipsum + */ + private fun foo() {} +} diff --git a/diktat-rules/src/test/resources/test/paragraph2/kdoc/SpecialTagsInKdocExpected.kt b/diktat-rules/src/test/resources/test/paragraph2/kdoc/SpecialTagsInKdocExpected.kt index 8410afedcd..c50aaf35a8 100644 --- a/diktat-rules/src/test/resources/test/paragraph2/kdoc/SpecialTagsInKdocExpected.kt +++ b/diktat-rules/src/test/resources/test/paragraph2/kdoc/SpecialTagsInKdocExpected.kt @@ -9,7 +9,6 @@ class SpecialTagsInKdoc { * @implSpec bar * * @implNote baz - * */ fun test() = Unit } diff --git a/diktat-rules/src/test/resources/test/smoke/src/main/kotlin/Example3Expected.kt b/diktat-rules/src/test/resources/test/smoke/src/main/kotlin/Example3Expected.kt index 231a5813b9..32d8804eda 100644 --- a/diktat-rules/src/test/resources/test/smoke/src/main/kotlin/Example3Expected.kt +++ b/diktat-rules/src/test/resources/test/smoke/src/main/kotlin/Example3Expected.kt @@ -45,3 +45,10 @@ class Example { } } +class Foo { + /** + * @implNote lorem ipsum + */ + private fun foo() {} +} + diff --git a/diktat-rules/src/test/resources/test/smoke/src/main/kotlin/Example3Test.kt b/diktat-rules/src/test/resources/test/smoke/src/main/kotlin/Example3Test.kt index cefa503487..ddd801edf8 100644 --- a/diktat-rules/src/test/resources/test/smoke/src/main/kotlin/Example3Test.kt +++ b/diktat-rules/src/test/resources/test/smoke/src/main/kotlin/Example3Test.kt @@ -40,3 +40,12 @@ class Example { foo() } } + + +class Foo { + /** + * @implNote lorem ipsum + */ + private fun foo() {} +} + diff --git a/diktat-rules/src/test/resources/test/smoke/src/main/kotlin/Example4Expected.kt b/diktat-rules/src/test/resources/test/smoke/src/main/kotlin/Example4Expected.kt new file mode 100644 index 0000000000..79589c1926 --- /dev/null +++ b/diktat-rules/src/test/resources/test/smoke/src/main/kotlin/Example4Expected.kt @@ -0,0 +1,16 @@ +package org.cqfn.diktat + +class SpecialTagsInKdoc { + /** + * Empty function to test KDocs + * @apiNote foo + * + * @implSpec bar + * + * @implNote baz + * + * @return + */ + fun test() = Unit +} + diff --git a/diktat-rules/src/test/resources/test/smoke/src/main/kotlin/Example4Test.kt b/diktat-rules/src/test/resources/test/smoke/src/main/kotlin/Example4Test.kt new file mode 100644 index 0000000000..df836479f9 --- /dev/null +++ b/diktat-rules/src/test/resources/test/smoke/src/main/kotlin/Example4Test.kt @@ -0,0 +1,15 @@ +package org.cqfn.diktat + +class SpecialTagsInKdoc { + + /** + * Empty function to test KDocs + * @apiNote foo + * @implSpec bar + * + * + * @implNote baz + */ + fun test() = Unit +} +