2 * @fileoverview Rule to flag duplicate arguments
3 * @author Jamund Ferguson
8 //------------------------------------------------------------------------------
10 //------------------------------------------------------------------------------
17 description: "disallow duplicate arguments in `function` definitions",
18 category: "Possible Errors",
20 url: "https://eslint.org/docs/rules/no-dupe-args"
26 unexpected: "Duplicate param '{{name}}'."
32 //--------------------------------------------------------------------------
34 //--------------------------------------------------------------------------
37 * Checks whether or not a given definition is a parameter's.
38 * @param {eslint-scope.DefEntry} def A definition to check.
39 * @returns {boolean} `true` if the definition is a parameter's.
41 function isParameter(def) {
42 return def.type === "Parameter";
46 * Determines if a given node has duplicate parameters.
47 * @param {ASTNode} node The node to check.
51 function checkParams(node) {
52 const variables = context.getDeclaredVariables(node);
54 for (let i = 0; i < variables.length; ++i) {
55 const variable = variables[i];
57 // Checks and reports duplications.
58 const defs = variable.defs.filter(isParameter);
60 if (defs.length >= 2) {
63 messageId: "unexpected",
64 data: { name: variable.name }
70 //--------------------------------------------------------------------------
72 //--------------------------------------------------------------------------
75 FunctionDeclaration: checkParams,
76 FunctionExpression: checkParams