mirror of
https://github.com/nodejs/node.git
synced 2026-11-24 21:50:36 -05:00
tools: simplify buffer-constructor rule
PR-URL: https://github.com/nodejs/node/pull/17572 Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
This commit is contained in:
1 parent
5383422672
commit
ad0d878772
1 file changed
+3
-8
@@ -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)
|
||||
};
|
||||
};
|
||||
Reference in new issue
Block a user