You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[kotlin] New Rule: LocalVariableShadowsParameter #6732
Description:
Detects local variable declarations and lambda explicit parameters that shadow a parameter of any enclosing named function. Shadowing a parameter with a local variable of the same name may lead to confusion about which value is actually used.
This rule also serves as a demonstration of the new Kotlin AST features: custom AttributeView classes for typed attribute access, and KotlinAstUtil helpers for navigating the Kotlin AST.
Code Sample:
// violation - local variable 'result' shadows function parameter 'result'funcompute(result:Int): Int {
val result =42return result
}
// no violation - different namefuncompute2(input:Int): Int {
val result = input +1return result
}
// violation - lambda explicit parameter shadows outer function parameterfunprocess(result:Int): Int {
val transform = { result:Int-> result +1 }
return transform(result)
}
Possible Properties:
No properties planned — the rule has no configurable threshold or pattern.
Not in scope / possible follow-up:
Local variable hiding a class field — this is a related but distinct case that requires type/classpath resolution and is better handled by a separate rule.
Activity
[doc] Update release notes (#6732)
[kotlin] Fix pmd#6732: Add LocalVariableShadowsParameter rule (pmd#6733)