UNPKG

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