Permalink
Browse files

tools: simplify buffer-constructor rule

PR-URL: #17572
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
  • Loading branch information...
cjihrig authored and gibfahn committed Dec 9, 2017
1 parent 5383422 commit ad0d878772f8533dbd4ed87b67b25a2ef3be346c
Showing with 3 additions and 8 deletions.
  1. +3 −8 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)
};
};

0 comments on commit ad0d878

Please sign in to comment.