UNPKG

1.01 kBJavaScriptView Raw
1/**
2 * @fileoverview Rule to flag assignment of the exception parameter
3 * @author Stephen Murray <spmurrayzzz>
4 */
5
6"use strict";
7
8var astUtils = require("../ast-utils");
9
10//------------------------------------------------------------------------------
11// Rule Definition
12//------------------------------------------------------------------------------
13
14module.exports = function(context) {
15
16 /**
17 * Finds and reports references that are non initializer and writable.
18 * @param {Variable} variable - A variable to check.
19 * @returns {void}
20 */
21 function checkVariable(variable) {
22 astUtils.getModifyingReferences(variable.references).forEach(function(reference) {
23 context.report(
24 reference.identifier,
25 "Do not assign to the exception parameter.");
26 });
27 }
28
29 return {
30 "CatchClause": function(node) {
31 context.getDeclaredVariables(node).forEach(checkVariable);
32 }
33 };
34
35};
36
37module.exports.schema = [];