Skip to content

noUselessCatchBinding

¥Summary

¥How to configure

biome.json
{
"linter": {
"rules": {
"nursery": {
"noUselessCatchBinding": "error"
}
}
}
}

¥Description

禁止使用未使用的 catch 绑定。

¥Disallow unused catch bindings.

此规则禁止根据 ECMAScript 2019 使用不必要的 catch 绑定。另请参阅:ECMAScript 2019 语言规范中的“可选 catch 绑定”特性。

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

¥Examples

¥Invalid

try {
// Do something
} catch (unused) {}
code-block.js:3:9 lint/nursery/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/nursery/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/nursery/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·})·{}
-----------------------

¥Valid

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 {}

¥Related links