1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- "use strict";
- const astUtils = require("./utils/ast-utils");
- module.exports = {
- meta: {
- type: "suggestion",
- docs: {
- description: "disallow `catch` clause parameters from shadowing variables in the outer scope",
- category: "Variables",
- recommended: false,
- url: "https://eslint.org/docs/rules/no-catch-shadow"
- },
- replacedBy: ["no-shadow"],
- deprecated: true,
- schema: [],
- messages: {
- mutable: "Value of '{{name}}' may be overwritten in IE 8 and earlier."
- }
- },
- create(context) {
-
-
-
-
- function paramIsShadowing(scope, name) {
- return astUtils.getVariableByName(scope, name) !== null;
- }
-
-
-
- return {
- "CatchClause[param!=null]"(node) {
- let scope = context.getScope();
-
- if (scope.block === node) {
- scope = scope.upper;
- }
- if (paramIsShadowing(scope, node.param.name)) {
- context.report({ node, messageId: "mutable", data: { name: node.param.name } });
- }
- }
- };
- }
- };
|