UNPKG

1.16 kBJavaScriptView Raw
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
12module.exports = {
13 meta: {
14 docs: {
15 description: "disallow the use of `arguments.caller` or `arguments.callee`",
16 category: "Best Practices",
17 recommended: false,
18 url: "https://eslint.org/docs/rules/no-caller"
19 },
20
21 schema: [],
22
23 messages: {
24 unexpected: "Avoid arguments.{{prop}}."
25 }
26 },
27
28 create(context) {
29
30 return {
31
32 MemberExpression(node) {
33 const objectName = node.object.name,
34 propertyName = node.property.name;
35
36 if (objectName === "arguments" && !node.computed && propertyName && propertyName.match(/^calle[er]$/)) {
37 context.report({ node, messageId: "unexpected", data: { prop: propertyName } });
38 }
39
40 }
41 };
42
43 }
44};