Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

no-prototype-builtins.js 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /**
  2. * @fileoverview Rule to disallow use of Object.prototype builtins on objects
  3. * @author Andrew Levine
  4. */
  5. "use strict";
  6. //------------------------------------------------------------------------------
  7. // Requirements
  8. //------------------------------------------------------------------------------
  9. const astUtils = require("./utils/ast-utils");
  10. //------------------------------------------------------------------------------
  11. // Rule Definition
  12. //------------------------------------------------------------------------------
  13. module.exports = {
  14. meta: {
  15. type: "problem",
  16. docs: {
  17. description: "disallow calling some `Object.prototype` methods directly on objects",
  18. category: "Possible Errors",
  19. recommended: true,
  20. url: "https://eslint.org/docs/rules/no-prototype-builtins"
  21. },
  22. schema: [],
  23. messages: {
  24. prototypeBuildIn: "Do not access Object.prototype method '{{prop}}' from target object."
  25. }
  26. },
  27. create(context) {
  28. const DISALLOWED_PROPS = [
  29. "hasOwnProperty",
  30. "isPrototypeOf",
  31. "propertyIsEnumerable"
  32. ];
  33. /**
  34. * Reports if a disallowed property is used in a CallExpression
  35. * @param {ASTNode} node The CallExpression node.
  36. * @returns {void}
  37. */
  38. function disallowBuiltIns(node) {
  39. const callee = astUtils.skipChainExpression(node.callee);
  40. if (callee.type !== "MemberExpression") {
  41. return;
  42. }
  43. const propName = astUtils.getStaticPropertyName(callee);
  44. if (propName !== null && DISALLOWED_PROPS.indexOf(propName) > -1) {
  45. context.report({
  46. messageId: "prototypeBuildIn",
  47. loc: callee.property.loc,
  48. data: { prop: propName },
  49. node
  50. });
  51. }
  52. }
  53. return {
  54. CallExpression: disallowBuiltIns
  55. };
  56. }
  57. };