Skip to main content

no-ex-assign

NOTE: this rule is part of the recommended rule set.
Enable full set in deno.json:
{
  "lint": {
    "tags": ["recommended"]
  }
}
Enable full set using the Deno CLI:
deno lint --tags=recommended

Disallows the reassignment of exception parameters.

There is generally no good reason to reassign an exception parameter. Once reassigned the code from that point on has no reference to the error anymore.

Invalid:

try {
  someFunc();
} catch (e) {
  e = true;
  // can no longer access the thrown error
}

Valid:

try {
  someFunc();
} catch (e) {
  const anotherVar = true;
}

Did you find what you needed?

Privacy policy