summaryrefslogtreecommitdiff
path: root/deps/node-inspect/tools/eslint-rules/assert-fail-single-argument.js
blob: 4ce790238181ccda30f8df9888de106a80fff9c1 (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
/**
 * @fileoverview Prohibit use of a single argument only in `assert.fail()`. It
 * is almost always an error.
 * @author Rich Trott
 */
'use strict';

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

const msg = 'assert.fail() message should be third argument';

function isAssert(node) {
  return node.callee.object && node.callee.object.name === 'assert';
}

function isFail(node) {
  return node.callee.property && node.callee.property.name === 'fail';
}

module.exports = function(context) {
  return {
    'CallExpression': function(node) {
      if (isAssert(node) && isFail(node) && node.arguments.length === 1) {
        context.report(node, msg);
      }
    }
  };
};