Guest User

Untitled

a guest
Oct 20th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. 'use strict';
  2.  
  3. //------------------------------------------------------------------------------
  4. // Rule Definition
  5. //------------------------------------------------------------------------------
  6.  
  7. const msg = 'Please use common.expectsError(fn, err) instead of ' +
  8. 'assert.throws(fn, common.expectsError(err)).';
  9.  
  10. function isAssertThrows(node) {
  11. return node &&
  12. node.callee &&
  13. node.callee.object &&
  14. node.callee.object.name === 'assert' &&
  15. node.callee.property &&
  16. node.callee.property.name === 'throws';
  17. }
  18.  
  19.  
  20. function isFunction(arg) {
  21. return arg && (arg.type === 'ArrowFunctionExpression' ||
  22. arg.type === 'FunctionExpression' ||
  23. arg.type === 'CallExpression');
  24. }
  25.  
  26. function isCommonExpectsError(node) {
  27. return node &&
  28. node.callee &&
  29. node.callee.object &&
  30. node.callee.object.name === 'common' &&
  31. node.callee.property &&
  32. node.callee.property.name === 'expectsError';
  33. }
  34.  
  35. module.exports = function(context) {
  36. return {
  37. CallExpression(node) {
  38. if (isAssertThrows(node) &&
  39. isFunction(node.arguments[0]) &&
  40. isCommonExpectsError(node.arguments[1]) &&
  41. !node.arguments[2]) {
  42. context.report(node, msg);
  43. }
  44. }
  45. };
  46. };
Add Comment
Please, Sign In to add comment