1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | "use strict";
|
7 |
|
8 | const astUtils = require("./utils/ast-utils");
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | module.exports = {
|
15 | meta: {
|
16 | type: "problem",
|
17 |
|
18 | docs: {
|
19 | description: "disallow reassigning exceptions in `catch` clauses",
|
20 | category: "Possible Errors",
|
21 | recommended: true,
|
22 | url: "https://eslint.org/docs/rules/no-ex-assign"
|
23 | },
|
24 |
|
25 | schema: [],
|
26 |
|
27 | messages: {
|
28 | unexpected: "Do not assign to the exception parameter."
|
29 | }
|
30 | },
|
31 |
|
32 | create(context) {
|
33 |
|
34 | |
35 |
|
36 |
|
37 |
|
38 |
|
39 | function checkVariable(variable) {
|
40 | astUtils.getModifyingReferences(variable.references).forEach(reference => {
|
41 | context.report({ node: reference.identifier, messageId: "unexpected" });
|
42 | });
|
43 | }
|
44 |
|
45 | return {
|
46 | CatchClause(node) {
|
47 | context.getDeclaredVariables(node).forEach(checkVariable);
|
48 | }
|
49 | };
|
50 |
|
51 | }
|
52 | };
|