Skip to content

Commit

Permalink
Bugfix. KdocMethod should not raise warning on override fun (#594)
Browse files Browse the repository at this point in the history
* bugfix/overriden-kdoc-not-mandatory(#551)

### What's done:
  * Fixed bugs
  • Loading branch information
aktsay6 authored Nov 30, 2020
1 parent 2349037 commit 6d4a8ef
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import com.pinterest.ktlint.core.ast.ElementType.WHEN_CONDITION_WITH_EXPRESSION
import org.cqfn.diktat.ruleset.utils.findChildAfter
import org.cqfn.diktat.ruleset.utils.findChildBefore
import org.cqfn.diktat.ruleset.utils.getAllChildrenWithType
import org.cqfn.diktat.ruleset.utils.isOverridden
import org.jetbrains.kotlin.com.intellij.lang.ASTNode
import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.LeafPsiElement
import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.PsiWhiteSpaceImpl
Expand Down Expand Up @@ -83,7 +84,7 @@ class KdocMethods(private val configRules: List<RulesConfig>) : Rule("kdoc-metho
isFixMode = autoCorrect
emitWarn = emit

if (node.elementType == FUN && node.getFirstChildWithType(MODIFIER_LIST).isAccessibleOutside()) {
if (node.elementType == FUN && node.getFirstChildWithType(MODIFIER_LIST).isAccessibleOutside() && !node.isOverridden()) {
val config = configRules.getCommonConfiguration().value
val fileName = node.getRootNode().getFileName()
val isTestMethod = node.hasTestAnnotation() || isLocatedInTest(fileName.splitPathToDirs(), config.testAnchors)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,4 +339,19 @@ class KdocMethodsTest : LintTestBase(::KdocMethods) {
LintError(2, 3, ruleId, "${KDOC_TRIVIAL_KDOC_ON_FUNCTION.warnText()} Returns X", false)
)
}


@Test
@Tag(WarningNames.MISSING_KDOC_ON_FUNCTION)
fun `should not trigger on override funcs`() {
lintMethod(
"""
|class Some : A {
| override fun foo() {}
|
| override fun bar(t: T): U { return U() }
|}
""".trimMargin()
)
}
}

0 comments on commit 6d4a8ef

Please sign in to comment.