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 committed Dec 12, 2017
1 parent 66d3e6b commit 0c1dee5
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 0c1dee5

Please sign in to comment.