Linting rules
E002: unused-variable
Checks for variables and parameters that are declared but never used.
Metadata
Code:E002Rule:unused-variableStatus: Stable sincev0.0.1Quick fix: always available
What it does
Checks for variables and parameters that are declared but never used.
Why is this bad?
Unused variables and parameters clutter the code and can be a sign of a bug.
Example
fun main() {
val x = 1; println("hello");
}Use instead:
fun main() {
println("hello");
}Or prefix with an underscore if the variable is intentionally unused:
fun main() {
val _x = 1;
println("hello");
}Behavior notes
- Locals prefixed with
_are intentionally ignored. - The rule also skips type parameters, implicit asm/builtin parameters, and
self. - Autofix prefixes the declaration identifier with
_.
Last updated on