noCatchAssign
Summary
Section titled “Summary”- Rule available since:
v1.0.0
- Diagnostic Category:
lint/suspicious/noCatchAssign
- This rule is recommended, which means is enabled by default.
- This rule doesn’t have a fix.
- The default severity of this rule is warning.
- Sources:
- Same as
no-ex-assign
- Same as
Description
Section titled “Description”Disallow reassigning exceptions in catch clauses.
Assignment to a catch
parameter can be misleading and confusing.
It is often unintended and indicative of a programmer error.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”try {
} catch (e) { e; e = 10;}
code-block.js:5:3 lint/suspicious/noCatchAssign ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ Reassigning a catch parameter is confusing.
3 │ } catch (e) {
4 │ e;
> 5 │ e = 10;
│ ^
6 │ }
7 │
ℹ The catch parameter is declared here:
1 │ try {
2 │
> 3 │ } catch (e) {
│ ^
4 │ e;
5 │ e = 10;
ℹ Use a local variable instead.
try {
} catch (e) { let e = 10; e = 100;}
How to configure
Section titled “How to configure”{ "linter": { "rules": { "suspicious": { "noCatchAssign": "error" } } }}