]>
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 //------------------------------------------------------------------------------
12 /** @type {import('../shared/types').Rule} */
18 description
: "Disallow duplicate arguments in `function` definitions",
20 url
: "https://eslint.org/docs/latest/rules/no-dupe-args"
26 unexpected
: "Duplicate param '{{name}}'."
32 const sourceCode
= context
.sourceCode
;
34 //--------------------------------------------------------------------------
36 //--------------------------------------------------------------------------
39 * Checks whether or not a given definition is a parameter's.
40 * @param {eslint-scope.DefEntry} def A definition to check.
41 * @returns {boolean} `true` if the definition is a parameter's.
43 function isParameter(def
) {
44 return def
.type
=== "Parameter";
48 * Determines if a given node has duplicate parameters.
49 * @param {ASTNode} node The node to check.
53 function checkParams(node
) {
54 const variables
= sourceCode
.getDeclaredVariables(node
);
56 for (let i
= 0; i
< variables
.length
; ++i
) {
57 const variable
= variables
[i
];
59 // Checks and reports duplications.
60 const defs
= variable
.defs
.filter(isParameter
);
62 if (defs
.length
>= 2) {
65 messageId
: "unexpected",
66 data
: { name
: variable
.name
}
72 //--------------------------------------------------------------------------
74 //--------------------------------------------------------------------------
77 FunctionDeclaration
: checkParams
,
78 FunctionExpression
: checkParams