• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/**
2 * @fileoverview Prohibit use of a single argument only in `assert.fail()`. It
3 * is almost always an error.
4 * @author Rich Trott
5 */
6'use strict';
7
8//------------------------------------------------------------------------------
9// Rule Definition
10//------------------------------------------------------------------------------
11
12const msg = 'assert.fail() message should be third argument';
13
14function isAssert(node) {
15  return node.callee.object && node.callee.object.name === 'assert';
16}
17
18function isFail(node) {
19  return node.callee.property && node.callee.property.name === 'fail';
20}
21
22module.exports = function(context) {
23  return {
24    'CallExpression': function(node) {
25      if (isAssert(node) && isFail(node) && node.arguments.length === 1) {
26        context.report(node, msg);
27      }
28    }
29  };
30};
31