oxc-project/oxc · warning · OxcDiagnostic
Identifier name is too short (< {config_min}).
Error message
Identifier name is too short (< {config_min}). What it means
Reported by the `id-length` rule (ESLint id-length port) when an identifier's name has fewer characters than the configured (or default) minimum. The default configuration in oxc sets `min: 2` and `max: u64::MAX` (crates/oxc_linter/src/rules/eslint/id_length.rs:32-33), so with defaults only single-character names are flagged. It is a style rule aimed at self-documenting names.
Source
Thrown at crates/oxc_linter/src/rules/eslint/id_length.rs:25
use unicode_segmentation::UnicodeSegmentation;
use oxc_ast::AstKind;
use oxc_ast::ast::{
BindingIdentifier, BindingPattern, BindingProperty, IdentifierName, PrivateIdentifier,
};
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::{ContentEq, GetSpan, Span};
use crate::{
AstNode,
context::LintContext,
rule::{DefaultRuleConfig, Rule},
utils::{AlwaysNever, deserialize_regex_vec},
};
fn id_length_is_too_short_diagnostic(span: Span, config_min: u64) -> OxcDiagnostic {
OxcDiagnostic::warn(format!("Identifier name is too short (< {config_min}).")).with_label(span)
}
fn id_length_is_too_long_diagnostic(span: Span, config_max: u64) -> OxcDiagnostic {
OxcDiagnostic::warn(format!("Identifier name is too long (> {config_max}).")).with_label(span)
}
const DEFAULT_MAX_LENGTH: u64 = u64::MAX;
const DEFAULT_MIN_LENGTH: u64 = 2;
#[derive(Debug, Clone, Default, Deserialize)]
pub struct IdLength(Box<IdLengthConfig>);
impl Deref for IdLength {
type Target = IdLengthConfig;
fn deref(&self) -> &Self::Target {
&self.0
}View on GitHub (pinned to 5b3e335484)
Solutions
- Rename short identifiers to descriptive ones (`x` → `offsetX`, `i` → `rowIndex`) — the primary intent of the rule.
- Add conventional short names to the rule's exceptions: `{ "id-length": ["error", { "min": 2, "exceptions": ["x", "y", "_"] }] }` (oxlint supports exceptions/exceptionPatterns like ESLint).
- Lower `min` (e.g. to 1) or disable the rule if the codebase convention accepts single-character names in loops.
Example fix
// before users.forEach((u, i) => rows[i] = renderRow(u)); // after users.forEach((user, rowIndex) => rows[rowIndex] = renderRow(user));
Defensive patterns
Strategy: validation
Validate before calling
// Encode your real convention once:
// .oxlintrc.json -> "id-length": ["error", { "min": 2, "exceptions": ["i", "j", "x", "y", "_"] }]
// oxlint runs in CI and fails before short names land. Prevention
- Add loop counters and coordinate names to `exceptions` immediately when enabling the rule; they are 90% of real hits.
- Raise min gradually (1 → 2 → 3) rather than jumping, so the backlog of renames stays manageable.
- For math/graphics code, prefer exceptionPatterns over renames — single letters x/y/z are the correct vocabulary there.
When it happens
Trigger: Declare or use identifiers of length < min: `let x = 1;`, `for (let i = 0; ...)` with the default min of 2, `const e = new Error()`; or raise the minimum via config `{ "id-length": ["error", { "min": 4 }] }` and keep short names like `err`. The check applies to variable, function, class, and parameter names (with exceptions options available).
Common situations: Enabling id-length in an existing repo where loop counters `i`, `j`, `k` and error variable `e` are everywhere; raising `min` beyond the team's actual habits; catching that `exceptions`/`exceptionPatterns` need entries for conventional short names (`x`/`y` in geometry code, `id`, `db`); refactoring generated or math-heavy code full of short symbols.
Related errors
- Identifier '{name}' is restricted.
- Identifier '#{name}' is restricted.
- A constructor name should not start with a lowercase letter.
- A function with a name starting with an uppercase letter sho
- `VirtualFree` failed during cleanup: {err}
AI-assisted analysis of oxc-project/oxc@5b3e335484 (2026-08-20).
Data as JSON: /api/errors/02abbb848b2f8836.
Report an issue: GitHub.