UNPKG

942 BJavaScriptView Raw
1/**
2 * @fileoverview Rule to flag assignment of the exception parameter
3 * @author Stephen Murray <spmurrayzzz>
4 */
5
6//------------------------------------------------------------------------------
7// Rule Definition
8//------------------------------------------------------------------------------
9
10module.exports = function(context) {
11
12 "use strict";
13
14 var inCatch = false,
15 exceptionName = null;
16
17 return {
18
19 "CatchClause": function(node) {
20 inCatch = true;
21 exceptionName = node.param.name;
22 },
23
24 "CatchClause:exit": function() {
25 inCatch = false;
26 exceptionName = null;
27 },
28
29 "AssignmentExpression": function(node) {
30
31 if (inCatch) {
32
33 if (node.left.name === exceptionName) {
34 context.report(node, "Do not assign to the exception parameter.");
35 }
36 }
37 }
38
39 };
40
41};