noUselessCatchBinding
Summary
Section titled “Summary”- Rule available since:
v2.2.3
- Diagnostic Category:
lint/nursery/noUselessCatchBinding
- This rule has an unsafe fix.
- The default severity of this rule is information.
How to configure
Section titled “How to configure”{ "linter": { "rules": { "nursery": { "noUselessCatchBinding": "error" } } }}
Description
Section titled “Description”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.
Examples
Section titled “Examples”Invalid
Section titled “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·})·{}
│ -----------------------
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
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.