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 <[email protected]>
  • Loading branch information
cjihrig authored and MylesBorins committed Dec 12, 2017
1 parent 01e7b44 commit e157e1c
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 e157e1c

Please sign in to comment.