Skip to main content

noCatchAssign (since v0.7.0)

This rule is recommended by Rome.

Disallow reassigning exceptions in catch clauses

Examples

Invalid

try {

} catch (e) {
e;
e = 10;
}
error[js/noCatchAssign]:  Do not reassign catch parameters.
  ┌─ js/noCatchAssign.js:5:3
  │
3 │ } catch (e) {
  │          - The catch parameter is declared here
4 │   e;
5 │   e = 10;
  │   ^

=  note: Use a local variable instead.

Valid

try {

} catch (e) {
let e = 10;
e = 100;
}