Skip to content

Commit

Permalink
tools: simplify buffer-constructor rule
Browse files Browse the repository at this point in the history
PR-URL: #17572
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
  • Loading branch information
cjihrig authored and gibfahn committed Dec 20, 2017
1 parent 7f979a7 commit 4a10cf5
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions tools/eslint-rules/buffer-constructor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 4a10cf5

Please sign in to comment.