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

Fix assertion failed in rule [kdoc-formatting] #1489 #1522

Merged
merged 4 commits into from
Sep 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)!!
icemachined marked this conversation as resolved.
Show resolved Hide resolved
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
*
icemachined marked this conversation as resolved.
Show resolved Hide resolved
* @param builder additional configuration lambda for serializers module
*/
class JsonReporter(
override val out: BufferedSink,
builder: PolymorphicModuleBuilder<Plugin.TestFiles>.() -> Unit = {}
) : Reporter