Skip to content

Commit e157e1c

Browse files
cjihrigMylesBorins
authored andcommittedDec 12, 2017
tools: simplify buffer-constructor rule
PR-URL: #17572 Reviewed-By: Anatoli Papirovski <[email protected]>
1 parent 01e7b44 commit e157e1c

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed
 

‎tools/eslint-rules/buffer-constructor.js

+3-8
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,11 @@
1010
const msg = 'Use of the Buffer() constructor has been deprecated. ' +
1111
'Please use either Buffer.alloc(), Buffer.allocUnsafe(), ' +
1212
'or Buffer.from()';
13-
14-
function test(context, node) {
15-
if (node.callee.name === 'Buffer') {
16-
context.report(node, msg);
17-
}
18-
}
13+
const astSelector = 'NewExpression[callee.name="Buffer"],' +
14+
'CallExpression[callee.name="Buffer"]';
1915

2016
module.exports = function(context) {
2117
return {
22-
'NewExpression': (node) => test(context, node),
23-
'CallExpression': (node) => test(context, node)
18+
[astSelector]: (node) => context.report(node, msg)
2419
};
2520
};

0 commit comments

Comments
 (0)
Please sign in to comment.