Rules which enforce generally accepted best practices.
Table of Contents

FunctionNameTooShort

Since: PMD 7.0.0

Priority: Medium (3)

Function names should be easy to understand and describe the intention. Makes developers happy.

This rule is defined by the following XPath expression:

//FunctionDeclaration/SimpleIdentifier/T-Identifier[string-length(@Text) < 3]

Example(s):

fun cl() {} // violation, no unavailable attribute added to the function declaration

fun calculateLayout() // no violation

Use this rule by referencing it:

<rule ref="category/kotlin/bestpractices.xml/FunctionNameTooShort" />

LocalVariableShadowsParameter

Since: PMD 7.26.0

Priority: Medium (3)

A local variable declaration uses the same name as a parameter of the enclosing function. This shadows the parameter and may lead to confusion about which value is used.

This rule is defined by the following Java class: net.sourceforge.pmd.lang.kotlin.rule.bestpractices.LocalVariableShadowsParameterRule

Example(s):

fun compute(result: Int): Int {
    val result = 42  // violation - shadows parameter 'result'
    return result
}

fun compute2(input: Int): Int {
    val result = input + 1  // no violation - different name
    return result
}

Use this rule by referencing it:

<rule ref="category/kotlin/bestpractices.xml/LocalVariableShadowsParameter" />