Acton
Linting rules

E002: unused-variable

Checks for variables and parameters that are declared but never used.

Metadata

  • Code: E002
  • Rule: unused-variable
  • Status: Stable since v0.0.1
  • Quick 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;
E002: variable is unused
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 _.
Source code

Last updated on

On this page