Ohm-Management - Projektarbeit B-ME
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-buffer-constructor.js 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /**
  2. * @fileoverview disallow use of the Buffer() constructor
  3. * @author Teddy Katz
  4. */
  5. "use strict";
  6. //------------------------------------------------------------------------------
  7. // Rule Definition
  8. //------------------------------------------------------------------------------
  9. module.exports = {
  10. meta: {
  11. type: "problem",
  12. docs: {
  13. description: "disallow use of the `Buffer()` constructor",
  14. category: "Node.js and CommonJS",
  15. recommended: false,
  16. url: "https://eslint.org/docs/rules/no-buffer-constructor"
  17. },
  18. schema: [],
  19. messages: {
  20. deprecated: "{{expr}} is deprecated. Use Buffer.from(), Buffer.alloc(), or Buffer.allocUnsafe() instead."
  21. }
  22. },
  23. create(context) {
  24. //----------------------------------------------------------------------
  25. // Public
  26. //----------------------------------------------------------------------
  27. return {
  28. "CallExpression[callee.name='Buffer'], NewExpression[callee.name='Buffer']"(node) {
  29. context.report({
  30. node,
  31. messageId: "deprecated",
  32. data: { expr: node.type === "CallExpression" ? "Buffer()" : "new Buffer()" }
  33. });
  34. }
  35. };
  36. }
  37. };