Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strict';
- //------------------------------------------------------------------------------
- // Rule Definition
- //------------------------------------------------------------------------------
- const msg = 'Please use common.expectsError(fn, err) instead of ' +
- 'assert.throws(fn, common.expectsError(err)).';
- function isAssertThrows(node) {
- return node &&
- node.callee &&
- node.callee.object &&
- node.callee.object.name === 'assert' &&
- node.callee.property &&
- node.callee.property.name === 'throws';
- }
- function isFunction(arg) {
- return arg && (arg.type === 'ArrowFunctionExpression' ||
- arg.type === 'FunctionExpression' ||
- arg.type === 'CallExpression');
- }
- function isCommonExpectsError(node) {
- return node &&
- node.callee &&
- node.callee.object &&
- node.callee.object.name === 'common' &&
- node.callee.property &&
- node.callee.property.name === 'expectsError';
- }
- module.exports = function(context) {
- return {
- CallExpression(node) {
- if (isAssertThrows(node) &&
- isFunction(node.arguments[0]) &&
- isCommonExpectsError(node.arguments[1]) &&
- !node.arguments[2]) {
- context.report(node, msg);
- }
- }
- };
- };
Add Comment
Please, Sign In to add comment