2024-08-09 12:04:48 +00:00
|
|
|
/**
|
|
|
|
* @fileoverview disallow use of the Buffer() constructor
|
|
|
|
* @author Teddy Katz
|
2024-08-21 06:34:30 +00:00
|
|
|
* @deprecated in ESLint v7.0.0
|
2024-08-09 12:04:48 +00:00
|
|
|
*/
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
// Rule Definition
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2024-08-21 06:34:30 +00:00
|
|
|
/** @type {import('../shared/types').Rule} */
|
2024-08-09 12:04:48 +00:00
|
|
|
module.exports = {
|
|
|
|
meta: {
|
|
|
|
deprecated: true,
|
|
|
|
|
|
|
|
replacedBy: [],
|
|
|
|
|
|
|
|
type: "problem",
|
|
|
|
|
|
|
|
docs: {
|
2024-08-21 06:34:30 +00:00
|
|
|
description: "Disallow use of the `Buffer()` constructor",
|
2024-08-09 12:04:48 +00:00
|
|
|
recommended: false,
|
2024-08-21 06:34:30 +00:00
|
|
|
url: "https://eslint.org/docs/latest/rules/no-buffer-constructor"
|
2024-08-09 12:04:48 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
schema: [],
|
|
|
|
|
|
|
|
messages: {
|
|
|
|
deprecated: "{{expr}} is deprecated. Use Buffer.from(), Buffer.alloc(), or Buffer.allocUnsafe() instead."
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
create(context) {
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Public
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
return {
|
|
|
|
"CallExpression[callee.name='Buffer'], NewExpression[callee.name='Buffer']"(node) {
|
|
|
|
context.report({
|
|
|
|
node,
|
|
|
|
messageId: "deprecated",
|
|
|
|
data: { expr: node.type === "CallExpression" ? "Buffer()" : "new Buffer()" }
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
};
|