summaryrefslogtreecommitdiff
path: root/tools/eslint-rules/prefer-common-mustnotcall.js
blob: 0008145ccb93a3b5ab7173c4e1dd6be0da8c73c4 (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
32
/**
 * @fileoverview Prefer common.mustNotCall(msg) over common.mustCall(fn, 0)
 * @author James M Snell <jasnell@gmail.com>
 */
'use strict';

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

const msg = 'Please use common.mustNotCall(msg) instead of ' +
            'common.mustCall(fn, 0) or common.mustCall(0).';
const mustCallSelector = 'CallExpression[callee.object.name="common"]' +
                         '[callee.property.name="mustCall"]';
const arg0Selector = `${mustCallSelector}[arguments.0.value=0]`;
const arg1Selector = `${mustCallSelector}[arguments.1.value=0]`;

module.exports = {
  create(context) {
    function report(node) {
      context.report(node, msg);
    }

    return {
    // Catch common.mustCall(0)
      [arg0Selector]: report,

      // Catch common.mustCall(fn, 0)
      [arg1Selector]: report,
    };
  },
};