• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/**
2 * @fileoverview Prefer common.mustNotCall(msg) over common.mustCall(fn, 0)
3 * @author James M Snell <jasnell@gmail.com>
4 */
5'use strict';
6
7//------------------------------------------------------------------------------
8// Rule Definition
9//------------------------------------------------------------------------------
10
11const msg = 'Please use common.mustNotCall(msg) instead of ' +
12            'common.mustCall(fn, 0) or common.mustCall(0).';
13const mustCallSelector = 'CallExpression[callee.object.name="common"]' +
14                         '[callee.property.name="mustCall"]';
15const arg0Selector = `${mustCallSelector}[arguments.0.value=0]`;
16const arg1Selector = `${mustCallSelector}[arguments.1.value=0]`;
17
18module.exports = function(context) {
19  function report(node) {
20    context.report(node, msg);
21  }
22
23  return {
24    // Catch common.mustCall(0)
25    [arg0Selector]: report,
26
27    // Catch common.mustCall(fn, 0)
28    [arg1Selector]: report
29  };
30};
31