no-caller.js 1.1 KB

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