]>
Commit | Line | Data |
---|---|---|
eb39fafa DC |
1 | /** |
2 | * @fileoverview Rule to flag use of arguments.callee and arguments.caller. | |
3 | * @author Nicholas C. Zakas | |
4 | */ | |
5 | ||
6 | "use strict"; | |
7 | ||
8 | //------------------------------------------------------------------------------ | |
9 | // Rule Definition | |
10 | //------------------------------------------------------------------------------ | |
11 | ||
34eeec05 | 12 | /** @type {import('../shared/types').Rule} */ |
eb39fafa DC |
13 | module.exports = { |
14 | meta: { | |
15 | type: "suggestion", | |
16 | ||
17 | docs: { | |
8f9d1d4d | 18 | description: "Disallow the use of `arguments.caller` or `arguments.callee`", |
eb39fafa DC |
19 | recommended: false, |
20 | url: "https://eslint.org/docs/rules/no-caller" | |
21 | }, | |
22 | ||
23 | schema: [], | |
24 | ||
25 | messages: { | |
26 | unexpected: "Avoid arguments.{{prop}}." | |
27 | } | |
28 | }, | |
29 | ||
30 | create(context) { | |
31 | ||
32 | return { | |
33 | ||
34 | MemberExpression(node) { | |
35 | const objectName = node.object.name, | |
36 | propertyName = node.property.name; | |
37 | ||
38 | if (objectName === "arguments" && !node.computed && propertyName && propertyName.match(/^calle[er]$/u)) { | |
39 | context.report({ node, messageId: "unexpected", data: { prop: propertyName } }); | |
40 | } | |
41 | ||
42 | } | |
43 | }; | |
44 | ||
45 | } | |
46 | }; |