]>
git.proxmox.com Git - pve-eslint.git/blob - eslint/lib/rules/prefer-rest-params.js
371a28964f2739e5d560771ce40a192684e4715e
2 * @fileoverview Rule to
3 * @author Toru Nagashima
8 //------------------------------------------------------------------------------
10 //------------------------------------------------------------------------------
13 * Gets the variable object of `arguments` which is defined implicitly.
14 * @param {eslint-scope.Scope} scope A scope to get.
15 * @returns {eslint-scope.Variable} The found variable object.
17 function getVariableOfArguments(scope
) {
18 const variables
= scope
.variables
;
20 for (let i
= 0; i
< variables
.length
; ++i
) {
21 const variable
= variables
[i
];
23 if (variable
.name
=== "arguments") {
26 * If there was a parameter which is named "arguments", the implicit "arguments" is not defined.
27 * So does fast return with null.
29 return (variable
.identifiers
.length
=== 0) ? variable
: null;
33 /* istanbul ignore next : unreachable */
38 * Checks if the given reference is not normal member access.
40 * - arguments .... true // not member access
41 * - arguments[i] .... true // computed member access
42 * - arguments[0] .... true // computed member access
43 * - arguments.length .... false // normal member access
44 * @param {eslint-scope.Reference} reference The reference to check.
45 * @returns {boolean} `true` if the reference is not normal member access.
47 function isNotNormalMemberAccess(reference
) {
48 const id
= reference
.identifier
;
49 const parent
= id
.parent
;
52 parent
.type
=== "MemberExpression" &&
53 parent
.object
=== id
&&
58 //------------------------------------------------------------------------------
60 //------------------------------------------------------------------------------
62 /** @type {import('../shared/types').Rule} */
68 description
: "require rest parameters instead of `arguments`",
70 url
: "https://eslint.org/docs/rules/prefer-rest-params"
76 preferRestParams
: "Use the rest parameters instead of 'arguments'."
83 * Reports a given reference.
84 * @param {eslint-scope.Reference} reference A reference to report.
87 function report(reference
) {
89 node
: reference
.identifier
,
90 loc
: reference
.identifier
.loc
,
91 messageId
: "preferRestParams"
96 * Reports references of the implicit `arguments` variable if exist.
99 function checkForArguments() {
100 const argumentsVar
= getVariableOfArguments(context
.getScope());
105 .filter(isNotNormalMemberAccess
)
111 "FunctionDeclaration:exit": checkForArguments
,
112 "FunctionExpression:exit": checkForArguments