tools: simplify buffer-constructor rule

PR-URL: https://github.com/nodejs/node/pull/17572
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
This commit is contained in:
cjihrig authored and Gibson Fahnestock committed 2017-12-20 01:24:07 +00:00
1 parent 5383422672
commit ad0d878772
1 file changed
+3 -8
+3 -8
View File
@@ -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)
};
};