summaryrefslogtreecommitdiff
path: root/deps/node/deps/node-inspect/tools/eslint-rules/new-with-error.js
blob: 655f34bf080956a71a4fe0b0414cd782607ebfc8 (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
26
27
28
29
30
31
/**
 * @fileoverview Require `throw new Error()` rather than `throw Error()`
 * @author Rich Trott
 */
'use strict';

//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------

module.exports = function(context) {

  var errorList = context.options.length !== 0 ? context.options : ['Error'];

  return {
    'ThrowStatement': function(node) {
      if (node.argument.type === 'CallExpression' &&
          errorList.indexOf(node.argument.callee.name) !== -1) {
        context.report(node, 'Use new keyword when throwing.');
      }
    }
  };
};

module.exports.schema = {
  'type': 'array',
  'additionalItems': {
    'type': 'string'
  },
  'uniqueItems': true
};