2016-03-16 18:37:35 +01:00
|
|
|
/**
|
|
|
|
* @fileoverview Require use of new Buffer constructor methods in lib
|
|
|
|
* @author James M Snell
|
|
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
// Rule Definition
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
const msg = 'Use of the Buffer() constructor has been deprecated. ' +
|
|
|
|
'Please use either Buffer.alloc(), Buffer.allocUnsafe(), ' +
|
|
|
|
'or Buffer.from()';
|
2017-12-09 16:06:57 +01:00
|
|
|
const astSelector = 'NewExpression[callee.name="Buffer"],' +
|
|
|
|
'CallExpression[callee.name="Buffer"]';
|
2016-03-16 18:37:35 +01:00
|
|
|
|
|
|
|
module.exports = function(context) {
|
|
|
|
return {
|
2017-12-09 16:06:57 +01:00
|
|
|
[astSelector]: (node) => context.report(node, msg)
|
2016-03-16 18:37:35 +01:00
|
|
|
};
|
|
|
|
};
|