# id-length

Rule `eslint/id-length`. Enforce minimum and maximum identifier lengths

- Source: eslint
- Technologies: JavaScript
- Kind: style
- Needs type information: no
- Autofix: no
- Reach: 0 weekly downloads of presets that enable it
- Trend: 0% last quarter
- Rank: #1698 by reach

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `id-length` | no | no | package `eslint` | [docs](https://eslint.org/docs/latest/rules/id-length) |
| Oxlint | `id-length` | no | no | plugin `eslint`, category style | [docs](https://oxc.rs/docs/guide/usage/linter/rules/eslint/id-length.html) |

## Code examples

### Incorrect: the rule reports this

```js
/*eslint id-length: "error"*/     // default is minimum 2-chars ({ "min": 2 })

const x = 5;
obj.e = document.body;
const foo = function (e) { };
try {
    dangerousStuff();
} catch (e) {
    // ignore as many do
}
const myObj = { a: 1 };
(a) => { a * a };
class y { }
class Foo { x() {} }
class Bar { #x() {} }
class Baz { x = 1 }
class Qux { #x = 1 }
function bar(...x) { }
function baz([x]) { }
const [z] = arr;
const { prop: [i]} = {};
function qux({x}) { }
const { j } = {};
const { prop: a} = {};
({ prop: obj.x } = {});
```

```js
const val = 5;
obj.e = document.body;
function foo (e) { };
try {
    dangerousStuff();
} catch (e) {
    // ignore as many do
}
const myObj = { a: 1 };
(val) => { val * val };
class y { }
class Foo { x() {} }
function bar(...x) { }
const { x } = {};
const { prop: a} = {};
const [i] = arr;
const { prop: [num]} = {};
({ prop: obj.x } = {});
```

```js
const reallyLongVarName = 5;
function reallyLongFuncName() { return 42; }
obj.reallyLongPropName = document.body;
const foo = function (reallyLongArgName) { /* do stuff */ };
try {
    dangerousStuff();
} catch (reallyLongErrorName) {
    // ignore as many do
}
(reallyLongArgName) => { return !reallyLongArgName; };
const [reallyLongFirstElementName] = arr;
```

### Correct: the rule accepts this

```js
/*eslint id-length: "error"*/     // default is minimum 2-chars ({ "min": 2 })

const num = 5;
function _f() { return 42; }
function _func() { return 42; }
obj.el = document.body;
const foo = function (evt) { /* do stuff */ };
try {
    dangerousStuff();
} catch (error) {
    // ignore as many do
}
const myObj = { apple: 1 };
(num) => { num * num };
function bar(num = 0) { }
class MyClass { }
class Foo { method() {} }
class Bar { #method() {} }
class Baz { field = 1 }
class Qux { #field = 1 }
function baz(...args) { }
function qux([longName]) { }
const { prop } = {};
const { prop: [name] } = {};
const [longName] = arr;
function foobar({ prop }) { }
function foobaz({ a: prop }) { }
const { a: property } = {};
({ prop: obj.longName } = {});
const data = { "x": 1 };  // excused because of quotes
data["y"] = 3;  // excused because of calculated property access
```

```js
const value = 5;
function func() { return 42; }
object.element = document.body;
const foobar = function (event) { /* do stuff */ };
try {
    dangerousStuff();
} catch (error) {
    // ignore as many do
}
const myObj = { apple: 1 };
(value) => { value * value };
function foobaz(value = 0) { }
class MyClass { }
class Foobar { method() {} }
function barbaz(...args) { }
const { prop } = {};
const [longName] = foo;
const { a: [name] } = {};
const { a: record } = {};
({ prop: object.name } = {});
const data = { "x": 1 };  // excused because of quotes
data["y"] = 3;  // excused because of calculated property access
```

```js
const varName = 5;
function funcName() { return 42; }
obj.propName = document.body;
const foo = function (arg) { /* do stuff */ };
try {
    dangerousStuff();
} catch (error) {
    // ignore as many do
}
(arg) => { return !arg; };
const [first] = arr;
```

Examples from the ESLint documentation.

## Enable it

### ESLint: `eslint.config.js`

```js
export default [
  {
    rules: {
      "id-length": "error",
    },
  },
];
```

### Oxlint: `.oxlintrc.json`

```json
{
  "rules": {
    "id-length": "error"
  }
}
```

## Related rules

- [eslint/no-undefined](https://lintradar.dev/rules/eslint/no-undefined.md): Disallow the use of `undefined` as an identifier
- [eslint/sort-imports](https://lintradar.dev/rules/eslint/sort-imports.md): Enforce sorted `import` declarations within modules
- [eslint/sort-keys](https://lintradar.dev/rules/eslint/sort-keys.md): Require object keys to be sorted
- [eslint/no-ternary](https://lintradar.dev/rules/eslint/no-ternary.md): Disallow ternary operators
- [eslint/no-magic-numbers](https://lintradar.dev/rules/eslint/no-magic-numbers.md): Disallow magic numbers
- [eslint/max-statements](https://lintradar.dev/rules/eslint/max-statements.md): Enforce a maximum number of statements allowed in function blocks

---

Web page: https://lintradar.dev/rules/eslint/id-length. Data from npm and the linters' documentation, collected Dec 4, 2026. Site guide for agents: https://lintradar.dev/llms.txt
