]> git.proxmox.com Git - pve-eslint.git/blob - eslint/lib/rules/no-ex-assign.js
import 8.3.0 source
[pve-eslint.git] / eslint / lib / rules / no-ex-assign.js
1 /**
2 * @fileoverview Rule to flag assignment of the exception parameter
3 * @author Stephen Murray <spmurrayzzz>
4 */
5
6 "use strict";
7
8 const astUtils = require("./utils/ast-utils");
9
10 //------------------------------------------------------------------------------
11 // Rule Definition
12 //------------------------------------------------------------------------------
13
14 module.exports = {
15 meta: {
16 type: "problem",
17
18 docs: {
19 description: "disallow reassigning exceptions in `catch` clauses",
20 recommended: true,
21 url: "https://eslint.org/docs/rules/no-ex-assign"
22 },
23
24 schema: [],
25
26 messages: {
27 unexpected: "Do not assign to the exception parameter."
28 }
29 },
30
31 create(context) {
32
33 /**
34 * Finds and reports references that are non initializer and writable.
35 * @param {Variable} variable A variable to check.
36 * @returns {void}
37 */
38 function checkVariable(variable) {
39 astUtils.getModifyingReferences(variable.references).forEach(reference => {
40 context.report({ node: reference.identifier, messageId: "unexpected" });
41 });
42 }
43
44 return {
45 CatchClause(node) {
46 context.getDeclaredVariables(node).forEach(checkVariable);
47 }
48 };
49
50 }
51 };