mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00: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:
committed by
Gibson Fahnestock
parent
20044a239d
commit
dd1105ddba
@@ -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