prefer-called-with.js 740 Bytes
Newer Older
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
'use strict';

const { getDocsUrl, expectCase, expectNotCase, method } = require('./util');

module.exports = {
  meta: {
    docs: {
      url: getDocsUrl(__filename),
    },
  },
  create(context) {
    return {
      CallExpression(node) {
        // Could check resolves/rejects here but not a likely idiom.
        if (expectCase(node) && !expectNotCase(node)) {
          const methodNode = method(node);
          const { name } = methodNode;
          if (name === 'toBeCalled' || name === 'toHaveBeenCalled') {
            context.report({
              data: { name },
              message: 'Prefer {{name}}With(/* expected args */)',
              node: methodNode,
            });
          }
        }
      },
    };
  },
};