2 * @fileoverview Rule to flag when the same variable is declared more then once.
8 //------------------------------------------------------------------------------
10 //------------------------------------------------------------------------------
12 module.exports = function(context) {
15 * Find variables in a given scope and flag redeclared ones.
16 * @param {Scope} scope An escope scope object.
20 function findVariablesInScope(scope) {
21 scope.variables.forEach(function(variable) {
23 if (variable.identifiers && variable.identifiers.length > 1) {
24 variable.identifiers.sort(function(a, b) {
25 return a.range[1] - b.range[1];
28 for (var i = 1, l = variable.identifiers.length; i < l; i++) {
29 context.report(variable.identifiers[i], "{{a}} is already defined", {a: variable.name});
37 * Find variables in a given node's associated scope.
38 * @param {ASTNode} node The node to check.
42 function findVariables(node) {
43 var scope = context.getScope();
45 findVariablesInScope(scope);
47 // globalReturn means one extra scope to check
48 if (node.type === "Program" && context.ecmaFeatures.globalReturn) {
49 findVariablesInScope(scope.childScopes[0]);
54 "Program": findVariables,
55 "FunctionExpression": findVariables,
56 "FunctionDeclaration": findVariables