From e157e1c9222f351ecb09aae4e6453e2bba4e0578 Mon Sep 17 00:00:00 2001 From: cjihrig Date: Sat, 9 Dec 2017 10:06:57 -0500 Subject: [PATCH] tools: simplify buffer-constructor rule PR-URL: https://github.com/nodejs/node/pull/17572 Reviewed-By: Anatoli Papirovski --- tools/eslint-rules/buffer-constructor.js | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/tools/eslint-rules/buffer-constructor.js b/tools/eslint-rules/buffer-constructor.js index 938598e8dbf618..412fdaa934664b 100644 --- a/tools/eslint-rules/buffer-constructor.js +++ b/tools/eslint-rules/buffer-constructor.js @@ -10,16 +10,11 @@ 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); - } -} +const astSelector = 'NewExpression[callee.name="Buffer"],' + + 'CallExpression[callee.name="Buffer"]'; module.exports = function(context) { return { - 'NewExpression': (node) => test(context, node), - 'CallExpression': (node) => test(context, node) + [astSelector]: (node) => context.report(node, msg) }; };