0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-30 07:27:22 +01:00
nodejs/tools/eslint-rules/prefer-common-expectserror.js
Anatoli Papirovski e51fb90a6d
tools: prefer common.expectsError in tests
Add lint rule to validate that common.expectsError(fn, err) is being
used instead of assert.throws(fn, common.expectsError(err));

PR-URL: https://github.com/nodejs/node/pull/17557
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2017-12-11 18:23:11 -05:00

22 lines
732 B
JavaScript

'use strict';
//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
const msg = 'Please use common.expectsError(fn, err) instead of ' +
'assert.throws(fn, common.expectsError(err)).';
const astSelector =
'CallExpression[arguments.length=2]' +
'[callee.object.name="assert"]' +
'[callee.property.name="throws"]' +
'[arguments.1.callee.object.name="common"]' +
'[arguments.1.callee.property.name="expectsError"]';
module.exports = function(context) {
return {
[astSelector]: (node) => context.report(node, msg)
};
};