diff options
Diffstat (limited to 'tools/eslint-rules/buffer-constructor.js')
-rw-r--r-- | tools/eslint-rules/buffer-constructor.js | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/tools/eslint-rules/buffer-constructor.js b/tools/eslint-rules/buffer-constructor.js new file mode 100644 index 0000000000..938598e8db --- /dev/null +++ b/tools/eslint-rules/buffer-constructor.js @@ -0,0 +1,25 @@ +/** + * @fileoverview Require use of new Buffer constructor methods in lib + * @author James M Snell + */ +'use strict'; + +//------------------------------------------------------------------------------ +// Rule Definition +//------------------------------------------------------------------------------ +const msg = 'Use of the Buffer() constructor has been deprecated. ' + + 'Please use either Buffer.alloc(), Buffer.allocUnsafe(), ' + + 'or Buffer.from()'; + +function test(context, node) { + if (node.callee.name === 'Buffer') { + context.report(node, msg); + } +} + +module.exports = function(context) { + return { + 'NewExpression': (node) => test(context, node), + 'CallExpression': (node) => test(context, node) + }; +}; |