mirror of
https://github.com/nodejs/node.git
synced 2024-11-30 07:27:22 +01:00
e51fb90a6d
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>
22 lines
732 B
JavaScript
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)
|
|
};
|
|
};
|