Skip to content

noUselessCatchBinding (JavaScript)

Language JavaScript (and super languages)
biome.json
{
"linter": {
"rules": {
"complexity": {
"noUselessCatchBinding": "error"
}
}
}
}

Disallow unused catch bindings.

This rule disallows unnecessary catch bindings in accordance with ECMAScript 2019. See also: the ECMAScript 2019 “optional catch binding” feature in the language specification.

try {
// Do something
} catch (unused) {}
code-block.js:3:9 lint/complexity/noUselessCatchBinding  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

ℹ This catch binding is unused.

1 │ try {
2 │ // Do something
> 3 │ } catch (unused) {}
│ ^^^^^^^^
4 │

ℹ Since ECMAScript 2019, catch bindings are optional; you can omit the catch binding if you don't need it.

ℹ Unsafe fix: Remove the catch binding.

3 │ }·catch·(unused)·{}
│ ---------
try {
// Do something
} catch ({ unused }) {}
code-block.js:3:9 lint/complexity/noUselessCatchBinding  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

ℹ This catch binding is unused.

1 │ try {
2 │ // Do something
> 3 │ } catch ({ unused }) {}
│ ^^^^^^^^^^^^
4 │

ℹ Since ECMAScript 2019, catch bindings are optional; you can omit the catch binding if you don't need it.

ℹ Unsafe fix: Remove the catch binding.

3 │ }·catch·({·unused·})·{}
│ -------------
try {
// Do something
} catch ({ unused1, unused2 }) {}
code-block.js:3:9 lint/complexity/noUselessCatchBinding  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

ℹ This catch binding is unused.

1 │ try {
2 │ // Do something
> 3 │ } catch ({ unused1, unused2 }) {}
│ ^^^^^^^^^^^^^^^^^^^^^^
4 │

ℹ Since ECMAScript 2019, catch bindings are optional; you can omit the catch binding if you don't need it.

ℹ Unsafe fix: Remove the catch binding.

3 │ }·catch·({·unused1,·unused2·})·{}
│ -----------------------
try {
// Do something
} catch (used) {
console.error(used);
}
try {
// Do something
} catch ({ used }) {
console.error(used);
}
try {
// Do something
} catch ({ used, unused }) {
console.error(used);
}
try {
// Do something
} catch {}