Skip to content

Commit

Permalink
### What's done:
Browse files Browse the repository at this point in the history
- Fixed false positive `MISSING_KDOC_ON_FUNCTION` on local function (function inside another function)
- Added warning test

Closes #1773
  • Loading branch information
diphtongue committed Dec 7, 2023
1 parent f5b7f89 commit 30c59ae
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,11 @@ class KdocMethods(configRules: List<RulesConfig>) : DiktatRule(
return false
}

@Suppress("UnsafeCallOnNullableType", "AVOID_NULL_CHECKS")
@Suppress(
"UnsafeCallOnNullableType",
"AVOID_NULL_CHECKS",
"CyclomaticComplexMethod"
)
private fun checkSignatureDescription(node: ASTNode) {
val kdoc = node.getFirstChildWithType(KDOC)
val kdocTags = kdoc?.kDocTags()
Expand All @@ -130,12 +134,12 @@ class KdocMethods(configRules: List<RulesConfig>) : DiktatRule(

val anyTagFailed = paramCheckFailed || returnCheckFailed || throwsCheckFailed
// if no tag failed, we have too little information to suggest KDoc - it would just be empty
if (kdoc == null && anyTagFailed) {
if (kdoc == null && hasFunParent(node)) {
return
} else if (kdoc == null && anyTagFailed) {
addKdocTemplate(node, name, missingParameters, explicitlyThrownExceptions, returnCheckFailed)
} else if (kdoc == null && !isReferenceExpressionWithSameName(node)) {
MISSING_KDOC_ON_FUNCTION.warn(configRules, emitWarn, name, node.startOffset, node)
} else if (kdoc != null && hasFunParent(kdoc)) {
return
} else {
if (paramCheckFailed) {
handleParamCheck(node, kdoc, missingParameters, kDocMissingParameters, kdocTags)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,8 @@ class KdocMethodsTest : LintTestBase(::KdocMethods) {
| }
|}
""".trimMargin(),
DiktatError(1, 1, ruleId, "${MISSING_KDOC_ON_FUNCTION.warnText()} printHelloAndBye", false),
)
}

}

0 comments on commit 30c59ae

Please sign in to comment.