Naming Single Char Var

ID

kotlin.naming_single_char_var

Severity

info

Remediation Complexity

trivial

Remediation Risk

medium

Remediation Effort

low

Resource

Naming Convention

Language

Kotlin

Tags

naming, readability

Description

Reports function-local val/var declarations whose name is a single non-underscore character. Names like a, n, x communicate nothing about the value they hold. The common loop indices i, j, k and the conventional catch variable e are allow-listed; the wildcard _ is also allowed.

Rationale

Variable names are the primary documentation of intent inside a function body. A single-character name forces every reader to scan back to the declaration and infer the meaning from the initialiser. The cost is small per occurrence and large at file scale.

// Bad
fun compute(): Int {
    val a = 5            // FLAW
    return a
}

// Good — descriptive name
fun compute(): Int {
    val initial = 5
    return initial
}

// OK — conventional indices and catch variables
fun loop() {
    for (i in 0..10) {}
    try { ... } catch (e: Exception) {}
}

Remediation

Rename the variable to a word or short phrase that describes what the value represents. If the variable is a conventional loop index or catch parameter, add it to the rule’s allowedNames list in the configuration.

References