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