]>
git.proxmox.com Git - pve-eslint.git/blob - eslint/lib/rules/no-catch-shadow.js
2 * @fileoverview Rule to flag variable leak in CatchClauses in IE 8 and earlier
3 * @author Ian Christian Myers
4 * @deprecated in ESLint v5.1.0
9 //------------------------------------------------------------------------------
11 //------------------------------------------------------------------------------
13 const astUtils
= require("./utils/ast-utils");
15 //------------------------------------------------------------------------------
17 //------------------------------------------------------------------------------
19 /** @type {import('../shared/types').Rule} */
25 description
: "Disallow `catch` clause parameters from shadowing variables in the outer scope",
27 url
: "https://eslint.org/docs/latest/rules/no-catch-shadow"
30 replacedBy
: ["no-shadow"],
36 mutable
: "Value of '{{name}}' may be overwritten in IE 8 and earlier."
42 const sourceCode
= context
.sourceCode
;
44 //--------------------------------------------------------------------------
46 //--------------------------------------------------------------------------
49 * Check if the parameters are been shadowed
50 * @param {Object} scope current scope
51 * @param {string} name parameter name
52 * @returns {boolean} True is its been shadowed
54 function paramIsShadowing(scope
, name
) {
55 return astUtils
.getVariableByName(scope
, name
) !== null;
58 //--------------------------------------------------------------------------
60 //--------------------------------------------------------------------------
64 "CatchClause[param!=null]"(node
) {
65 let scope
= sourceCode
.getScope(node
);
68 * When ecmaVersion >= 6, CatchClause creates its own scope
69 * so start from one upper scope to exclude the current node
71 if (scope
.block
=== node
) {
75 if (paramIsShadowing(scope
, node
.param
.name
)) {
76 context
.report({ node
, messageId
: "mutable", data
: { name
: node
.param
.name
} });