Single-Character Variable Name

ID

go.naming_single_char_var

Severity

info

Remediation Complexity

trivial

Remediation Risk

medium

Remediation Effort

low

Resource

Naming Convention

Language

Go

Tags

naming

Description

Reports single-character variable, parameter and named-result identifiers whose name is not an idiomatic short name. The idiomatic allow-list defaults to i, j, k (loop indices), v (range value), ok (comma-ok results) and err (the error idiom); the blank identifier _ is always allowed.

Rationale

Single-character names carry no semantic meaning and force the reader to track what the value represents. Go culture embraces a small, well-understood set of short names — loop indices, the error idiom, comma-ok results — but anything outside that set increases cognitive load.

// Bad — non-idiomatic single-char names
x := value          // FLAW
var s int           // FLAW

// Good — idiomatic short names and descriptive names
for i := 0; i < n; i++ {}    // OK — loop index
value, err := load()         // OK — error idiom
total := value               // OK — descriptive

Exceptions

  • names on the configurable allow-list (i, j, k, v, ok, err by default);

  • the blank identifier _;

  • method receivers — short receiver names are the recommended Go convention;

  • for loop index and range variables.

Parameters

allowedNames

List of single-character names accepted as idiomatic. Defaults to [i, j, k, v, ok, err].

Remediation

Replace the single-character name with a descriptive name that conveys the value’s purpose.