]>
git.proxmox.com Git - pve-eslint.git/blob - eslint/lib/rules/no-dupe-args.js
2 * @fileoverview Rule to flag duplicate arguments
3 * @author Jamund Ferguson
8 //------------------------------------------------------------------------------
10 //------------------------------------------------------------------------------
17 description
: "disallow duplicate arguments in `function` definitions",
19 url
: "https://eslint.org/docs/rules/no-dupe-args"
25 unexpected
: "Duplicate param '{{name}}'."
31 //--------------------------------------------------------------------------
33 //--------------------------------------------------------------------------
36 * Checks whether or not a given definition is a parameter's.
37 * @param {eslint-scope.DefEntry} def A definition to check.
38 * @returns {boolean} `true` if the definition is a parameter's.
40 function isParameter(def
) {
41 return def
.type
=== "Parameter";
45 * Determines if a given node has duplicate parameters.
46 * @param {ASTNode} node The node to check.
50 function checkParams(node
) {
51 const variables
= context
.getDeclaredVariables(node
);
53 for (let i
= 0; i
< variables
.length
; ++i
) {
54 const variable
= variables
[i
];
56 // Checks and reports duplications.
57 const defs
= variable
.defs
.filter(isParameter
);
59 if (defs
.length
>= 2) {
62 messageId
: "unexpected",
63 data
: { name
: variable
.name
}
69 //--------------------------------------------------------------------------
71 //--------------------------------------------------------------------------
74 FunctionDeclaration
: checkParams
,
75 FunctionExpression
: checkParams