summaryrefslogtreecommitdiff
path: root/tools/eslint-rules/buffer-constructor.js
blob: 938598e8dbf618c22632db613cebb8c69813abb8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/**
 * @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()';

function test(context, node) {
  if (node.callee.name === 'Buffer') {
    context.report(node, msg);
  }
}

module.exports = function(context) {
  return {
    'NewExpression': (node) => test(context, node),
    'CallExpression': (node) => test(context, node)
  };
};