Unused Private Class

ID

kotlin.unused_private_class

Severity

low

Remediation Complexity

medium

Remediation Risk

low

Remediation Effort

medium

Resource

Code Smell

Language

Kotlin

Tags

dead_code, readability

Description

Reports a private class declaration whose name is never referenced anywhere else in the same source file. A private class is only visible inside its compilation unit (top-level) or inside its enclosing type (nested). If no other declaration uses it, the class is unreachable and should be removed.

Rationale

Dead code increases the maintenance burden, confuses readers, and may hide bugs since it is never exercised. Removing unused declarations keeps the file lean and signals to readers that every remaining declaration plays a role.

// Bad — Helper is never used in this file
private class Helper {
    fun work() = Unit
}

// Good — Used has at least one reference
private class Used {
    fun work() = Unit
}

fun build() = Used()

Remediation

Delete the class. If you intended it to be visible outside the file, change the visibility modifier; if it is only needed in tests, move it to the test source set.