Redundant Visibility Modifier
ID |
kotlin.redundant_visibility |
Severity |
info |
Remediation Complexity |
medium |
Remediation Risk |
low |
Remediation Effort |
medium |
Resource |
Code Smell |
Language |
Kotlin |
Tags |
readability, style |
Description
Reports class, function, and property declarations that carry an explicit public visibility modifier.
public is the default visibility in Kotlin for top-level and class-member declarations.
Writing it explicitly provides no additional information and introduces visual noise that
can distract readers from the actual intent of the code.
Rationale
// Bad — public is the default, no need to spell it out
public class Foo { // FLAW
public fun bar(): Int = 0 // FLAW
public val x: Int = 1 // FLAW
}
// Good — rely on the Kotlin default
class Foo {
fun bar(): Int = 0
val x: Int = 1
}
// OK — other visibility modifiers convey real information
private class Hidden
internal fun helper()
protected open fun hook()
Remediation
Remove the redundant public modifier from the declaration.
The visibility remains unchanged since public is the implicit default.